Skip to content

Commit

Permalink
Merge pull request #15 from navikt/dev/metrics
Browse files Browse the repository at this point in the history
f legger til prometheus metrics
  • Loading branch information
jstnhlj authored Nov 22, 2022
2 parents d4b8d5c + cac8c46 commit 7b3d5e3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nais/dev-gcp/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ spec:
path: /aia-backend/internal/isReady
initialDelay: 10
prometheus:
enabled: false
enabled: true
path: /aia-backend/internal/prometheus
replicas:
min: 1
max: 1
Expand Down
46 changes: 46 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"openid-client": "5.3.0",
"pino": "8.7.0",
"pino-http": "8.2.1",
"prom-client": "14.1.0",
"swagger-jsdoc": "6.2.5",
"swagger-ui-express": "4.6.0",
"ulid": "2.3.0",
Expand Down
6 changes: 6 additions & 0 deletions src/api/health.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Router } from 'express';
import { createMetrics } from './metrics';

function healthRoutes() {
const router = Router();
const register = createMetrics();

router.get('/internal/isAlive', (_, res) => {
res.send('ALIVE');
});
router.get('/internal/isReady', (_, res) => {
res.send('READY');
});
router.get('/internal/prometheus', async (_, res) => {
res.setHeader('Content-type', register.contentType);
res.send(await register.metrics());
});

return router;
}
Expand Down
7 changes: 7 additions & 0 deletions src/api/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { collectDefaultMetrics, Registry } from 'prom-client';

export function createMetrics(): Registry {
const register = new Registry();
collectDefaultMetrics({ register });
return register;
}

0 comments on commit 7b3d5e3

Please sign in to comment.