rest-analytics
A simple node.js module that provides analytics for REST services.
This is still a work in progress and lots of info are still missing from the analytics.
Usage
Add it to your connect/express application by using it's middleware.
npm install rest-analytics
// Initialize analytics;var RestAnalytics = ;var analytics = ;
// Use it in your express appvar express = ;var app = ;app;
// Get a collection of analyticsanalytics; // Get a collection of analytics for a specific method/urlanalytics;
Analytics
Currently, analytics per method/path pair contain the following information:
- count: Number of calls for a specific method/pair
- time.min: Minimum ellapsed time processing a request (in nanoseconds).
- time.max: Minimum ellapsed time processing a request (in nanoseconds).
- time.avg: Average ellapsed time processing a request (in nanoseconds).
You can get analytics on method/path pairs by calling the analytics method:
// read analytics for a specific method/pathvar data = analytics;console; // {// 'count': ...// 'time': {// 'min': ...// 'max': ...// 'avg': ...// }// }
// read analytics for all calls to a pathvar data = analytics;console; // {// 'get': ...// 'post': ...// }
// read all analyticsvar data = analytics;console; // {// '/user': {// 'get': ...// 'post': ...// },// '/company': {// 'get': ...// }// }
Events
call
Α 'call'
event will be emitted when a request is completed (after the response is sent). It can be used to integrate collected data with other analytics systems like Elasticsearch or StatsD.
The payload of the event will contain information about this specific request:
var express = ;var RestAnalytics = ; var app = ;var analytics = ;dataanalytics; app;
A payload example json is:
"request": "path": "/user" "ip": "127.0.0.1" "method": "GET" "headers": "key": "header" "value": "header value" "query": {} "parameters": "response": "status": 200 "headers": "key": "header" "value": "header value" "timestamp": 1418557961891 // timestamp of call (in ms) "duration": 040668 // duration of the call (in ms)