Skip to content

Commit

Permalink
Prometheus2 (#247)
Browse files Browse the repository at this point in the history
* Update .travis.yml

* Update .travis.yml

* Get Connections & Prometheus changes

* removed prometheus server

Co-authored-by: Michael McKay <mckaymic@us.ibm.com>
  • Loading branch information
Harish Kotha and mckaymic authored Apr 7, 2020
1 parent bc2b7f5 commit db88212
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
21 changes: 20 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ const port = 3333;

const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');

const apollo = require('./apollo');

const promClient = require('prom-client');
const collectDefaultMetrics = promClient.collectDefaultMetrics;
collectDefaultMetrics({ timeout: 5000 }); //Collect all default metrics
const connections = new promClient.Gauge({ name: 'razee_server_connections_count', help: 'Razee server request count' });

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

router.use(ebl(getBunyanConfig('razeedash-api')));
Expand Down Expand Up @@ -61,11 +66,17 @@ app.use(function errorHandler(err, req, res, next) {
next();
});

app.get('/metrics', function (request, response) {
response.writeHead(200, {'Content-Type': promClient.register.contentType});
response.end(promClient.register.metrics());
});

const server = http.createServer(app);

server.on('ready', onReady);
server.on('error', onError);
server.on('listening', onListening);
server.on('connection', onConnection);

require('./subs/index')(server);

Expand Down Expand Up @@ -111,3 +122,11 @@ function onError(error) {
}

}

// emitted when new client connects
function onConnection(){
server.getConnections(function(error,count){
//console.log('Number of concurrent connections to the server : ' + count);
connections.set(count);
});
}
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"swagger-ui-express": "^4.1.4",
"uuid": "^7.0.3",
"validator": "^12.2.0",
"ws": "^7.2.3"
"ws": "^7.2.3",
"prom-client": "^12.0.0"
},
"devDependencies": {
"axios": "^0.19.2",
Expand Down

0 comments on commit db88212

Please sign in to comment.