Skip to content

Commit

Permalink
feat: add prometheus (#299)
Browse files Browse the repository at this point in the history
Signed-off-by: OMPRAKASH MISHRA <[email protected]>
  • Loading branch information
mishraomp authored Jan 11, 2024
1 parent bc67d45 commit 6dcbd21
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
34 changes: 34 additions & 0 deletions api/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 api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"mongoose": "^7.5.0",
"morgan": "^1.10.0",
"nocache": "^4.0.0",
"prom-client": "^15.1.0",
"winston": "^3.8.2"
},
"devDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions api/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ const app = express();
const apiRouter = express.Router();
const pubcodeRouter = require("./routes/pubcode-router");
const log = require("./logger");
const prom = require('prom-client');
const register = new prom.Registry();
prom.collectDefaultMetrics({ register });

const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
windowMs: 60 * 1000, // 1 minute
max: 100, // Limit each IP to 100 requests per `window` (here, per 1 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
Expand All @@ -25,7 +29,10 @@ app.use(limiter);
app.use(cors());
app.use(helmet());
app.use(nocache());

app.get('/metrics', async (_req, res) => {
const appMetrics = await register.metrics();
res.end(appMetrics);
});
//tells the app to use json as means of transporting data
app.use(bodyParser.json({ limit: "50mb", extended: true }));
app.use(bodyParser.urlencoded({
Expand Down
8 changes: 8 additions & 0 deletions charts/pubcode/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ api:
enabled: true
host: "{{ .Release.Name }}-api.{{ .Values.global.domain }}"
targetPort: http # look at line#164 refer to the name.
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "3000"
prometheus.io/path: "/metrics"

frontend:
enabled: true
Expand Down Expand Up @@ -160,6 +164,10 @@ frontend:
enabled: true
host: "{{ .Release.Name }}.{{ .Values.global.domain }}"
targetPort: http # look at line#164 refer to the name.
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "3002"
prometheus.io/path: "/metrics"

database:
enabled: true
Expand Down
5 changes: 4 additions & 1 deletion frontend/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
auto_https off
admin off
admin 0.0.0.0:3002
servers {
metrics
}
}
:3000 {
log {
Expand Down

0 comments on commit 6dcbd21

Please sign in to comment.