Move app graphs graphite query to backend
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getGraphs
|
||||
getGraphs,
|
||||
getAppGraphs
|
||||
};
|
||||
|
||||
const middleware = require('../middleware/index.js'),
|
||||
const assert = require('assert'),
|
||||
graphs = require('../graphs.js'),
|
||||
safe = require('safetydance'),
|
||||
middleware = require('../middleware/index.js'),
|
||||
url = require('url'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
url = require('url');
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess;
|
||||
|
||||
// for testing locally: curl 'http://127.0.0.1:8417/graphite-web/render?format=json&from=-1min&target=absolute(collectd.localhost.du-docker.capacity-usage)'
|
||||
// the datapoint is (value, timestamp) https://buildmedia.readthedocs.org/media/pdf/graphite/0.9.16/graphite.pdf
|
||||
@@ -36,3 +41,15 @@ function getGraphs(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
async function getAppGraphs(req, res, next) {
|
||||
assert.strictEqual(typeof req.app, 'object');
|
||||
|
||||
if (!req.query.fromMinutes || !parseInt(req.query.fromMinutes)) return next(new HttpError(400, 'fromMinutes must be a number'));
|
||||
|
||||
const fromMinutes = parseInt(req.query.fromMinutes) || 60;
|
||||
const noNullPoints = !!req.query.noNullPoints;
|
||||
const [error, result] = await safe(graphs.getByAppId(req.app.id, fromMinutes, noNullPoints));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
next(new HttpSuccess(200, result));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user