mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
prometheus track playercounts
This commit is contained in:
1 parent
cf7af19370
commit
b7b0dd9d85
1 file changed
+11
@@ -95,6 +95,11 @@ const prometheusProductionGauge = new Prometheus.Gauge({
|
|||||||
help: 'Items produced by instance',
|
help: 'Items produced by instance',
|
||||||
labelNames: ["instanceID", "itemName"],
|
labelNames: ["instanceID", "itemName"],
|
||||||
});
|
});
|
||||||
|
const prometheusPlayerCountGauge = new Prometheus.Gauge({
|
||||||
|
name: prometheusPrefix+'player_count_gauge',
|
||||||
|
help: 'Amount of players connected to this cluster',
|
||||||
|
labelNames: ["instanceID", "instanceName"],
|
||||||
|
})
|
||||||
setInterval(()=>{
|
setInterval(()=>{
|
||||||
let numberOfActiveSlaves = 0;
|
let numberOfActiveSlaves = 0;
|
||||||
for(let instance in slaves){
|
for(let instance in slaves){
|
||||||
@@ -112,6 +117,12 @@ app.get('/metrics', (req, res) => {
|
|||||||
endpointHitCounter.labels(req.route.path).inc();
|
endpointHitCounter.labels(req.route.path).inc();
|
||||||
let reqStartTime = Date.now();
|
let reqStartTime = Date.now();
|
||||||
res.set('Content-Type', Prometheus.register.contentType);
|
res.set('Content-Type', Prometheus.register.contentType);
|
||||||
|
|
||||||
|
// gather some static metrics
|
||||||
|
for(let instanceID in slaves){try{
|
||||||
|
prometheusPlayerCountGauge.labels(instanceID, slaves[instanceID].instanceName).set(slaves[instanceID].playerCount);
|
||||||
|
}catch(e){}}
|
||||||
|
|
||||||
res.end(Prometheus.register.metrics());
|
res.end(Prometheus.register.metrics());
|
||||||
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
|
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user