Created
December 7, 2018 12:28
-
-
Save rmuhamedgaliev/59f638dfe3c44ffcdf7cd625bd867ac4 to your computer and use it in GitHub Desktop.
prom_client_send
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const express = require('express'); | |
const server = express(); | |
const client = require('prom-client'); | |
const Counter = client.Counter; | |
const register = client.register; | |
//Non push Alarm metrics | |
const c = new Counter({ | |
name: 'test1_counter', | |
help: 'Example of a counter', | |
labelNames: ['code'] | |
}); | |
setInterval(() => { | |
c.inc({ code: 200 }); | |
}, 5000); | |
server.get('/metric', (req, res) => { | |
res.set('Content-Type', register.contentType); | |
res.end(register.metrics()); | |
}); | |
// Setting up the push gateway: | |
const registry = new client.Registry(); | |
const pushAlarmMetricOne = new Counter({ | |
name: 'push_alarm_counter_metric_one', | |
help: 'Example of a counter', | |
labelNames: ['service','pod'], | |
registers: [registry] | |
}); | |
const pushAlarmMetricTwo = new Counter({ | |
name: 'push_alarm_counter_metric_two', | |
help: 'Example of a counter', | |
labelNames: ['service', 'pod'], | |
registers: [registry] | |
}); | |
let gateway = new client.Pushgateway('http://127.0.0.1:9091', {}, registry); | |
//Exposes the pushgateway registry at '/push/metric' | |
server.get('/push/metric', (req, res) => { | |
res.set('Content-Type', register.contentType); | |
res.end(registry.metrics()); | |
}); | |
server.get('/pushadd/:labelOne', (req, res) => { | |
gateway.pushAdd({ | |
jobName: 'push_alarms'}, function (err, resp, body) { | |
pushAlarmMetricOne.labels('svcName', req.params.labelOne).inc() | |
}); | |
res.end("Success!!"); | |
}); | |
server.get('/push/:labelOne', (req, res) => { | |
gateway.push({ jobName: 'push_alarms' }, function (err, resp, body) { | |
pushAlarmMetricOne.labels('svcName', req.params.labelOne).inc() | |
}); | |
res.end("Success!!"); | |
}); | |
console.log('Server listening to 3002, metrics exposed on /metrics endpoint'); | |
server.listen(3002); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment