mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Track deployments in Prometheus
This commit is contained in:
parent
f8fcb9ac77
commit
26eb6c259b
3 changed files with 23 additions and 1 deletions
|
|
@ -1,9 +1,14 @@
|
|||
import { register } from 'prom-client';
|
||||
|
||||
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';
|
||||
|
||||
if (githash) {
|
||||
deploymentsCounter.inc({ git_hash: githash });
|
||||
}
|
||||
|
||||
/** Prometheus/OpenMetrics controller. */
|
||||
export const metricsController: AppController = async (c) => {
|
||||
const db = await Storages.database();
|
||||
|
|
|
|||
11
src/git.ts
Normal file
11
src/git.ts
Normal 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 };
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
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({
|
||||
name: 'ditto_http_requests_total',
|
||||
help: 'Total number of HTTP requests',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue