mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-22 19:12:28 -05:00
Add collectors to monitoring (#6777)
* Add collectors to monitoring * Pass request and response objects to collectors
This commit is contained in:
parent
5ee9aa2410
commit
3f77cfa93a
@ -42,6 +42,7 @@ module.exports.CreateMonitoring = function (parent, args) {
|
|||||||
RelaySessions: { description: "Relay Sessions" }, // parent.webserver.relaySessionCount
|
RelaySessions: { description: "Relay Sessions" }, // parent.webserver.relaySessionCount
|
||||||
RelayCount: { description: "Relay Count" } // Object.keys(parent.webserver.wsrelays).length30bb4fb74dfb758d36be52a7
|
RelayCount: { description: "Relay Count" } // Object.keys(parent.webserver.wsrelays).length30bb4fb74dfb758d36be52a7
|
||||||
}
|
}
|
||||||
|
obj.collectors = [];
|
||||||
if (parent.config.settings.prometheus != null) { // Create Prometheus Monitoring Endpoint
|
if (parent.config.settings.prometheus != null) { // Create Prometheus Monitoring Endpoint
|
||||||
if ((typeof parent.config.settings.prometheus == 'number') && ((parent.config.settings.prometheus < 1) || (parent.config.settings.prometheus > 65535))) {
|
if ((typeof parent.config.settings.prometheus == 'number') && ((parent.config.settings.prometheus < 1) || (parent.config.settings.prometheus > 65535))) {
|
||||||
console.log('Promethus port number is invalid, Prometheus metrics endpoint has be disabled');
|
console.log('Promethus port number is invalid, Prometheus metrics endpoint has be disabled');
|
||||||
@ -103,6 +104,7 @@ module.exports.CreateMonitoring = function (parent, args) {
|
|||||||
};
|
};
|
||||||
for (const key in counters) { obj.counterMetrics[key].prometheus.reset(); obj.counterMetrics[key].prometheus.inc(counters[key]); }
|
for (const key in counters) { obj.counterMetrics[key].prometheus.reset(); obj.counterMetrics[key].prometheus.inc(counters[key]); }
|
||||||
res.set('Content-Type', obj.prometheus.register.contentType);
|
res.set('Content-Type', obj.prometheus.register.contentType);
|
||||||
|
await Promise.all(obj.collectors.map((collector) => (collector(req, res))));
|
||||||
res.end(await obj.prometheus.register.metrics());
|
res.end(await obj.prometheus.register.metrics());
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.log(ex);
|
console.log(ex);
|
||||||
@ -111,4 +113,5 @@ module.exports.CreateMonitoring = function (parent, args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return obj;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user