Skip to content

Commit 4a6333a

Browse files
committed
feat: add prometheus
Signed-off-by: OMPRAKASH MISHRA <omprakashmishra3978@gmail.com>
1 parent bc67d45 commit 4a6333a

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

api/package-lock.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"mongoose": "^7.5.0",
1919
"morgan": "^1.10.0",
2020
"nocache": "^4.0.0",
21+
"prom-client": "^15.1.0",
2122
"winston": "^3.8.2"
2223
},
2324
"devDependencies": {

api/src/app.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ const app = express();
88
const apiRouter = express.Router();
99
const pubcodeRouter = require("./routes/pubcode-router");
1010
const log = require("./logger");
11+
const prom = require('prom-client');
12+
const register = new prom.Registry();
13+
prom.collectDefaultMetrics({ register });
14+
1115
const rateLimit = require('express-rate-limit');
1216
const limiter = rateLimit({
13-
windowMs: 1 * 60 * 1000, // 1 minute
17+
windowMs: 60 * 1000, // 1 minute
1418
max: 100, // Limit each IP to 100 requests per `window` (here, per 1 minutes)
1519
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
1620
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
@@ -25,7 +29,10 @@ app.use(limiter);
2529
app.use(cors());
2630
app.use(helmet());
2731
app.use(nocache());
28-
32+
app.get('/metrics', async (_req, res) => {
33+
const appMetrics = await register.metrics();
34+
res.end(appMetrics);
35+
});
2936
//tells the app to use json as means of transporting data
3037
app.use(bodyParser.json({ limit: "50mb", extended: true }));
3138
app.use(bodyParser.urlencoded({

charts/pubcode/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ api:
8989
enabled: true
9090
host: "{{ .Release.Name }}-api.{{ .Values.global.domain }}"
9191
targetPort: http # look at line#164 refer to the name.
92+
podAnnotations:
93+
prometheus.io/scrape: "true"
94+
prometheus.io/port: "3000"
95+
prometheus.io/path: "/metrics"
9296

9397
frontend:
9498
enabled: true
@@ -160,6 +164,10 @@ frontend:
160164
enabled: true
161165
host: "{{ .Release.Name }}.{{ .Values.global.domain }}"
162166
targetPort: http # look at line#164 refer to the name.
167+
podAnnotations:
168+
prometheus.io/scrape: "true"
169+
prometheus.io/port: "3002"
170+
prometheus.io/path: "/metrics"
163171

164172
database:
165173
enabled: true

frontend/Caddyfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
auto_https off
3-
admin off
3+
admin 0.0.0.0:3002
4+
servers {
5+
metrics
6+
}
47
}
58
:3000 {
69
log {

0 commit comments

Comments
 (0)