https://github.com/clarkie/hapi-cloudwatch
Hapi plugin to send response metrics to AWS CloudWatch
https://github.com/clarkie/hapi-cloudwatch
aws cloudwatch hapi-plugin hapijs metrics
Last synced: 8 months ago
JSON representation
Hapi plugin to send response metrics to AWS CloudWatch
- Host: GitHub
- URL: https://github.com/clarkie/hapi-cloudwatch
- Owner: clarkie
- License: mit
- Created: 2017-02-22T16:55:22.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-09-17T09:42:53.000Z (over 6 years ago)
- Last Synced: 2025-01-01T09:05:40.387Z (about 1 year ago)
- Topics: aws, cloudwatch, hapi-plugin, hapijs, metrics
- Language: JavaScript
- Homepage:
- Size: 115 KB
- Stars: 7
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-cloudwatch
A hapi plugin for sending request response time metrics to AWS CloudWatch.
[](https://travis-ci.org/clarkie/hapi-cloudwatch)
[](https://coveralls.io/github/clarkie/hapi-cloudwatch)
[](http://badge.fury.io/js/hapi-cloudwatch)
[](https://david-dm.org/clarkie/hapi-cloudwatch)
[](https://david-dm.org/clarkie/hapi-cloudwatch#info=devDependencies)
[](https://snyk.io/test/npm/hapi-cloudwatch)
## Installation
npm install hapi-cloudwatch
## Usage
To install this plugin on your Hapi server, do something similar to this:
```js
var Hapi = require('hapi');
var server = new Hapi.Server();
var options = {};
server.register({ register: require('hapi-cloudwatch'), options }, function(err) {
if (err) {
console.log('error', 'Failed loading plugin: hapi-cloudwatch');
}
});
```
## Plugin Options
### `region`
AWS region to send the metrics to.
Defaults to `eu-west-1`
### `environment`
The primary dimension added to the CloudWatch metric
Defaults to `process.env.NODE_ENV`
### `enabled`
Turns on/off the sending of metrics to CloudWatch
Defaults to `true`
### `metricsSentCallback`
A function to call when metrics have been sent to CloudWatch.
Defaults to no-op.
## Example
A Hapi route configured like this:
```js
server.route({
method: 'GET',
path: '/products/{id}',
handler: function(request, reply) {
reply('Success!');
}
});
```
and run with `NODE_ENV=production npm start` will send a metric to AWS CloudWatch with the following dimensions:
- metric name: `responseTime`
- environment: `production`
- method: `GET`
- statusCode: `200`
- path: `/products/{id}`
Here's an example of what can be graphed in CloudWatch with this metric:

## Version Compatibility
### Currently in use by me with with: Hapi 16.1.0 (Node v6)
_I'll add tests for other hapi and node versions shortly_