Skip to content

Commit

Permalink
added metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
denniszielke committed Apr 26, 2023
1 parent ea7c728 commit 4985b8a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion logging/crashing-app/app/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = {}

config.port = process.env.PORT || 80;
config.port = process.env.PORT || 8080;

module.exports = config;
5 changes: 3 additions & 2 deletions logging/crashing-app/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"name": "dzielke"
},
"dependencies": {
"express": "^4.18.1",
"dotenv-extended": "^2.9.0",
"express": "^4.18.2",
"morgan": "^1.10.0",
"dotenv-extended": "^2.9.0"
"prom-client": "^14.2.0"
}
}
17 changes: 15 additions & 2 deletions logging/crashing-app/app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ const config = require('./config');
const express = require('express');
const app = express();
const morgan = require('morgan');

const client = require('prom-client');
const OS = require('os');

const register = new client.Registry();
client.collectDefaultMetrics({
app: 'node-application-monitoring-app',
prefix: 'node_',
timeout: 10000,
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5],
register
});

// add logging middleware
app.use(morgan('dev'));

// Routes
app.get('/metrics', async (req, res) => {
res.setHeader('Content-Type', register.contentType);
res.send(await register.metrics());
});

app.get('/', function(req, res) {
console.log('base received request');
Expand Down Expand Up @@ -50,7 +63,7 @@ app.get('/leak', function(req, res) {
console.log(config);
console.log(OS.hostname());
app.listen(config.port);
console.log('Listening on localhost:'+ config.port);
console.log('Listening on localhost:'+ config.port + ', metrics are exposed on http://localhost:' + config.port + '/metrics');

if (process.env.LEAK){
console.log('Leaking automatically');
Expand Down

0 comments on commit 4985b8a

Please sign in to comment.