Skip to content

Commit

Permalink
feat: add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassimoen committed Jan 27, 2024
1 parent 9c78683 commit d8c7412
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import dotenv from "dotenv";
import { deserializeUser } from "../src/utils/DeserializeUser";
import fastifyStatic from "@fastify/static";
import path from "path";
import _default from "fastify-metrics";
import { prisma } from "../src/db/client";
dotenv.config();

export const server = fastify({
Expand All @@ -30,6 +32,8 @@ server.register(cookies, {
hook: "onRequest",
});

server.register(_default);

server.register(fastifyStatic, {
root: path.join(__dirname, "../static"),
prefix: "/api/static/",
Expand All @@ -43,6 +47,9 @@ server.register(AdminRouter, { prefix: "/api" });
server.get("/ping", (req: any, res: any) => {
res.status(200).send();
});
server.get("/metrics/prisma", async (req: any, res: any) => {
res.send(await prisma.$metrics.prometheus());
})

server.setErrorHandler((err, req, rep) => {
if (err instanceof HttpError) {
Expand All @@ -60,7 +67,7 @@ server.listen({ host: "0.0.0.0", port: +(process.env.PORT || 8080) }, (err, addr
console.error(err);
process.exit(1);
}
console.log(`Server listening at ${address}`);
console.log(`Server listening at ${address}, environment: ${process.env.ENV}`);
});

export default async (req: any, res: any) => {
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions docker-compose.metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.7"
services:

prometheus:
image: prom/prometheus:latest
volumes:
- prometheus_data:/prometheus
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'

grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
# - ./grafana/provisioning:/etc/grafana/provisioning
# - ./grafana/config.ini:/etc/grafana/config.ini
# - ./grafana/dashboards:/var/lib/grafana/dashboards
environment:
- GF_SECURITY_ADMIN_PASSWORD=ohno
depends_on:
- prometheus
ports:
- '1234:3000'

volumes:
prometheus_data: {}
grafana_data: {}
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

generator client {
provider = "prisma-client-js"
previewFeatures = ["metrics"]
}

datasource db {
Expand Down

0 comments on commit d8c7412

Please sign in to comment.