UNPKG

openhim-core

Version:

The OpenHIM core application that provides logging and routing of http requests

73 lines (60 loc) 2.21 kB
var Channel, Q, Transaction, authorisation, logger, metrics, moment, mongoose; Transaction = require('../model/transactions').Transaction; Channel = require('../model/channels').Channel; moment = require('moment'); logger = require('winston'); mongoose = require('mongoose'); authorisation = require('./authorisation'); Q = require('q'); metrics = require("../metrics"); exports.getGlobalLoadTimeMetrics = function*() { var filtersObject, i, j, len, result, results, userRequesting; filtersObject = this.request.query; userRequesting = this.authenticated; results = (yield metrics.fetchGlobalLoadTimeMetrics(userRequesting, filtersObject)); this.body = []; for (i = j = 0, len = results.length; j < len; i = ++j) { result = results[i]; this.body.push({ load: result.load, avgResp: results[i].avgResp, timestamp: moment.utc([result._id.year, result._id.month - 1, result._id.day, result._id.hour]).format() }); } }; exports.getGlobalStatusMetrics = function*() { var filtersObject, results, userRequesting; filtersObject = this.request.query; userRequesting = this.authenticated; results = (yield metrics.fetchGlobalStatusMetrics(userRequesting, filtersObject)); this.body = results; }; exports.getChannelMetrics = function*(time, channelId) { var filtersObject, i, j, len, result, results, userRequesting; filtersObject = this.request.query; userRequesting = this.authenticated; results = (yield metrics.fetchChannelMetrics(time, channelId, userRequesting, filtersObject)); if (time === 'status') { this.body = results; } else { this.body = []; for (i = j = 0, len = results.length; j < len; i = ++j) { result = results[i]; if (!result._id.minute) { result._id.minute = '00'; } if (!result._id.hour) { result._id.hour = '00'; } if (!result._id.day) { result._id.day = '1'; } this.body.push({ load: result.load, avgResp: result.avgResp, timestamp: moment.utc([result._id.year, result._id.month - 1, result._id.day, result._id.hour, result._id.minute]).format() }); } } }; //# sourceMappingURL=metrics.js.map