Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prometheus metric exporter to web package #1124

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/web/package-lock.json

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

6 changes: 4 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@sabia/web",
"scripts": {
"dev": "cross-env NODE_ICU_DATA=node_modules/full-icu APP_ENV=development next dev -p 8000",
"dev": "cross-env NODE_ICU_DATA=node_modules/full-icu APP_ENV=development node server.js",
"build": "cross-env NODE_ICU_DATA=node_modules/full-icu next build",
"start:ci": "cross-env APP_ENV=testing NODE_ENV=production npm run build && APP_ENV=testing npm run start",
"start": "cross-env NODE_ICU_DATA=node_modules/full-icu NODE_ENV=production next start -p 8000",
"start": "cross-env NODE_ICU_DATA=node_modules/full-icu NODE_ENV=production node server.js",
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook",
"jest": "cross-env APP_ENV=testing NODE_ICU_DATA=node_modules/full-icu jest --coverage --maxWorkers=50%",
Expand All @@ -23,6 +23,7 @@
"algoliasearch": "^4.1.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-prom-bundle": "^6.3.6",
"google-maps-react": "^2.0.6",
"html-react-parser": "^0.13.0",
"isomorphic-dompurify": "^0.3.0",
Expand All @@ -34,6 +35,7 @@
"next-translate": "^1.0.6",
"npm": "^6.14.8",
"nprogress": "^0.2.0",
"prom-client": "^13.1.0",
"prop-types": "^15.7.2",
"query-string": "^6.12.1",
"react": "^17.0.1",
Expand Down
33 changes: 33 additions & 0 deletions packages/web/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const express = require('express');
const next = require('next');
const promBundle = require('express-prom-bundle');
const { collectDefaultMetrics } = require('prom-client');

const port = parseInt(process.env.PORT, 10) || 8000;
const dev = process.env.NODE_ENV !== 'production';
const server = next({ dev });
const handle = server.getRequestHandler();
const metricsMiddleware = promBundle({
promClient: {
collectDefaultMetrics,
},
});

server.prepare().then(() => {
const app = express();

app.use(metricsMiddleware);

app.all('*', (req, res) => {
return handle(req, res);
});

app.listen(port, (err) => {
if (err) {
throw err;
}

// eslint-disable-next-line no-console
console.log(`> Ready on http://localhost:${port}`);
});
});