Track deployments in Prometheus

This commit is contained in:
Alex Gleason 2024-09-23 20:32:24 -05:00
parent f8fcb9ac77
commit 26eb6c259b
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 23 additions and 1 deletions

View file

@ -1,9 +1,14 @@
import { register } from 'prom-client'; import { register } from 'prom-client';
import { AppController } from '@/app.ts'; import { AppController } from '@/app.ts';
import { dbAvailableConnectionsGauge, dbPoolSizeGauge } from '@/metrics.ts'; import { githash } from '@/git.ts';
import { dbAvailableConnectionsGauge, dbPoolSizeGauge, deploymentsCounter } from '@/metrics.ts';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
if (githash) {
deploymentsCounter.inc({ git_hash: githash });
}
/** Prometheus/OpenMetrics controller. */ /** Prometheus/OpenMetrics controller. */
export const metricsController: AppController = async (c) => { export const metricsController: AppController = async (c) => {
const db = await Storages.database(); const db = await Storages.database();

11
src/git.ts Normal file
View file

@ -0,0 +1,11 @@
let githash: string | undefined;
try {
const cmd = new Deno.Command('git', { args: ['rev-parse', 'HEAD'] });
const out = await cmd.output();
githash = new TextDecoder().decode(out.stdout).trim();
} catch {
//
}
export { githash };

View file

@ -1,5 +1,11 @@
import { Counter, Gauge, Histogram } from 'prom-client'; import { Counter, Gauge, Histogram } from 'prom-client';
export const deploymentsCounter = new Counter({
name: 'ditto_deployments_total',
help: 'Updated on each deployment',
labelNames: ['git_hash'],
});
export const httpRequestsCounter = new Counter({ export const httpRequestsCounter = new Counter({
name: 'ditto_http_requests_total', name: 'ditto_http_requests_total',
help: 'Total number of HTTP requests', help: 'Total number of HTTP requests',