Skip to content

Commit

Permalink
Prometheus用のエンドポイントを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Jan 27, 2024
1 parent 2b9be3a commit 40c20f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
"dev": "bun run --hot src/main.ts"
},
"dependencies": {
"@hono/prometheus": "^1.0.0",
"@hono/zod-openapi": "^0.9.5",
"@read-stack/database": "workspace:*",
"@read-stack/lib": "workspace:*",
"@read-stack/openapi": "workspace:*",
"@read-stack/tsconfig": "workspace:*",
"@supabase/ssr": "^0.0.10",
"hono": "^3.11.11",
"prom-client": "^15.1.0",
"rss-parser": "^3.13.0",
"zod": "^3.22.4"
},
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import { loggerMiddleware } from '@/middleware/logger';
import type { WithSupabaseClient } from '@/middleware/supabase';
import { supabaseMiddleware } from '@/middleware/supabase';
import { corsMiddleware } from '@/middleware/cors';
import {
prometheusHandler,
prometheusMiddleware,
} from '@/middleware/prometheus';

export const app = new OpenAPIHono().basePath('/api');

app.use('*', loggerMiddleware);
app.use('*', corsMiddleware);
app.use('*', prometheusMiddleware);

const v1 = app.basePath('/v1');

Expand All @@ -26,5 +31,6 @@ registerUsersHandlers(
registerArticlesHandlers(v1);
registerDocsHandler(v1);
registerAuthHandlers(v1 as unknown as WithSupabaseClient);
v1.get('/metrics', prometheusHandler);

export const handler = handle(app);
6 changes: 6 additions & 0 deletions apps/server/src/middleware/prometheus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { prometheus } from '@hono/prometheus';

export const {
printMetrics: prometheusHandler,
registerMetrics: prometheusMiddleware,
} = prometheus();
39 changes: 39 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 40c20f9

Please sign in to comment.