rhq-metrics-middleware

rhq-metrics-middleware

Middleware for express and connect apps to inject system and site data into
rhq-metrics as timeseries data. See also:

https://github.com/rhq-project/rhq-metrics
https://github.com/lance/rhq-metrics-js

Usage example

rhq

function
rhq()

Option name Type Description
opts Object RHQ server connection options

Obtain the middleware functions for connect/express. See usage above.
options.host - the server hostname. Defaults to 'localhost'
options.port - the server port. Defaults to 8080
options.path - the REST API path. Defaults to '/rhq-metrics/metrics'

function rhq(opts) {

  var _RHQ = new RHQ(opts);

  function loadAverage(req, res, next) {
    var load = os.loadavg();
    var time = Date.now();
    _RHQ.post([
        {id:'load-1', value:load[0], timestamp:time},
        {id:'load-5', value:load[1], timestamp:time},
        {id:'load-15', value:load[2], timestamp:time}]);
    next();
  }

  function freeMemory(req, res, next) {
    _RHQ.post({id:'free-memory', value:os.freemem(), timestamp:Date.now()});
    next();
  }

  function responseTime(req, res, next) {
    var start = Date.now();
    res.on('finish', function() {
      var end = Date.now();
      _RHQ.post({id:'response-time', value:end-start, timestamp:end});
    });
    next();
  }

  return [loadAverage, freeMemory, responseTime];
}