Browse Source

used prom-client lib to expose custom metrics

master
Yutsuo 7 years ago
parent
commit
9b4d9373d8
  1. 2
      Dockerfile
  2. 11
      app.js

2
Dockerfile

@ -3,7 +3,7 @@ FROM node
WORKDIR /app
# Copying npm config file setting npm repository location.
COPY .npmrc .npmrc
# COPY .npmrc .npmrc
# If you add the package.json first and run npm install later,
# Docker won’t have to install the dependencies again if you

11
app.js

@ -12,17 +12,16 @@ const libCounter = new Prometheus.Counter({
help: 'A simple counter for app access during runtime created with unofficial prometheus nodejs library'
});
const libUptime = new Prometheus.Histogram({
const libUptime = new Prometheus.Counter({
name: 'lib_upTime',
help: 'uptime A counter of the application\'s uptime in millisenconds.'
help: 'uptime A counter of the application\'s uptime in seconds.'
})
libUptime.startTimer();
const collectDefaultMetrics = Prometheus.collectDefaultMetrics;
// const collectDefaultMetrics = Prometheus.collectDefaultMetrics;
// Probe every 5th second.
collectDefaultMetrics({ timeout: 5000 });
// collectDefaultMetrics({ timeout: 5000 });
// new schema model object based on the structure of what I want to put on MongoDB collection
var testSchema = new Schema({
@ -48,9 +47,11 @@ app.get('/metrics', function(req, res){
// res.write('# HELP invocation_count A simple counter for app access during runtime' + '\n');
// res.write('# TYPE invocation_count counter'+ '\n');
// res.write('invocation_count ' + counter + '\n');
libUptime.inc(Math.floor(process.uptime()));
res.set('Content-Type', Prometheus.register.contentType)
res.end(Prometheus.register.metrics())
res.end();
libUptime.reset();
});

Loading…
Cancel
Save