A hapi plugin for sending request response time metrics to AWS CloudWatch.
npm install hapi-cloudwatch
To install this plugin on your Hapi server, do something similar to this:
varHapi=require('hapi');varserver=newHapi.Server();varoptions={};server.register({plugin: require('hapi-cloudwatch'), options },function(err){if(err){console.log('error','Failed loading plugin: hapi-cloudwatch');}});AWS region to send the metrics to.
Defaults to eu-west-1
The primary dimension added to the CloudWatch metric
Defaults to process.env.NODE_ENV
Turns on/off the sending of metrics to CloudWatch
Defaults to true
A function to call when metrics have been sent to CloudWatch.
Defaults to no-op.
A Hapi route configured like this:
server.route({method: 'GET',path: '/products/{id}',handler: function(request,h){'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 | hapi.js |
|---|---|
2.x | >=17 hapi |
1.x | <17 hapi |

