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

feat: add prometheus #299

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
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