graphs: send service graphs

This commit is contained in:
Girish Ramakrishnan
2022-10-13 20:32:36 +02:00
parent 6d8c3febac
commit 4015afc69c
8 changed files with 67 additions and 54 deletions

View File

@@ -2,7 +2,7 @@
exports = module.exports = {
getSystem,
getApp
getContainerStats
};
const apps = require('./apps.js'),
@@ -10,6 +10,7 @@ const apps = require('./apps.js'),
BoxError = require('./boxerror.js'),
docker = require('./docker.js'),
safe = require('safetydance'),
services = require('./services.js'),
superagent = require('superagent');
// for testing locally: curl 'http://${graphite-ip}:8000/graphite-web/render?format=json&from=-1min&target=absolute(collectd.localhost.du-docker.capacity-usage)'
@@ -25,8 +26,8 @@ async function getGraphiteUrl() {
return `http://${ip}:8000/graphite-web/render`;
}
async function getApp(app, fromMinutes, noNullPoints) {
assert.strictEqual(typeof app, 'object');
async function getContainerStats(name, fromMinutes, noNullPoints) {
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof fromMinutes, 'number');
assert.strictEqual(typeof noNullPoints, 'boolean');
@@ -34,13 +35,13 @@ async function getApp(app, fromMinutes, noNullPoints) {
const graphiteUrl = await getGraphiteUrl();
const targets = [
`summarize(collectd.localhost.docker-stats-${app.id}.gauge-cpu-perc, "${timeBucketSize}min", "avg")`,
`summarize(collectd.localhost.docker-stats-${app.id}.gauge-mem-used, "${timeBucketSize}min", "avg")`,
// `summarize(collectd.localhost.docker-stats-${app.id}.gauge-mem-max, "${timeBucketSize}min", "avg")`,
`summarize(collectd.localhost.docker-stats-${app.id}.counter-blockio-read, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${app.id}.counter-blockio-write, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${app.id}.counter-network-read, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${app.id}.counter-network-write, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${name}.gauge-cpu-perc, "${timeBucketSize}min", "avg")`,
`summarize(collectd.localhost.docker-stats-${name}.gauge-mem-used, "${timeBucketSize}min", "avg")`,
// `summarize(collectd.localhost.docker-stats-${name}.gauge-mem-max, "${timeBucketSize}min", "avg")`,
`summarize(collectd.localhost.docker-stats-${name}.counter-blockio-read, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${name}.counter-blockio-write, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${name}.counter-network-read, "${timeBucketSize}min", "sum")`,
`summarize(collectd.localhost.docker-stats-${name}.counter-network-write, "${timeBucketSize}min", "sum")`,
];
const results = [];
@@ -94,8 +95,13 @@ async function getSystem(fromMinutes, noNullPoints) {
const appResponses = {};
for (const app of await apps.list()) {
appResponses[app.id] = await getApp(app, fromMinutes, noNullPoints);
appResponses[app.id] = await getContainerStats(app.id, fromMinutes, noNullPoints);
}
return { cpu: memCpuResponse.body[0], memory: memCpuResponse.body[1], apps: appResponses };
const serviceResponses = {};
for (const serviceId of await services.listServices()) {
serviceResponses[serviceId] = await getContainerStats(serviceId, fromMinutes, noNullPoints);
}
return { cpu: memCpuResponse.body[0], memory: memCpuResponse.body[1], apps: appResponses, services: serviceResponses };
}