mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'db-query-time-prom-metric' into 'main'
basic (and incredibly stupid but potentially genius) db_query_time histogram See merge request soapbox-pub/ditto!400
This commit is contained in:
commit
eba0605e32
2 changed files with 9 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { Stickynotes } from '@soapbox/stickynotes';
|
import { Stickynotes } from '@soapbox/stickynotes';
|
||||||
import { Logger } from 'kysely';
|
import { Logger } from 'kysely';
|
||||||
|
import { dbQueryTimeHistogram } from '@/metrics.ts';
|
||||||
|
|
||||||
/** Log the SQL for queries. */
|
/** Log the SQL for queries. */
|
||||||
export const KyselyLogger: Logger = (event) => {
|
export const KyselyLogger: Logger = (event) => {
|
||||||
|
|
@ -9,6 +10,8 @@ export const KyselyLogger: Logger = (event) => {
|
||||||
const { query, queryDurationMillis } = event;
|
const { query, queryDurationMillis } = event;
|
||||||
const { sql, parameters } = query;
|
const { sql, parameters } = query;
|
||||||
|
|
||||||
|
dbQueryTimeHistogram.observe(queryDurationMillis);
|
||||||
|
|
||||||
console.debug(
|
console.debug(
|
||||||
sql,
|
sql,
|
||||||
JSON.stringify(parameters),
|
JSON.stringify(parameters),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Counter, Gauge } from 'prom-client';
|
import { Counter, Gauge, Histogram } from 'prom-client';
|
||||||
|
|
||||||
export const httpRequestCounter = new Counter({
|
export const httpRequestCounter = new Counter({
|
||||||
name: 'http_requests_total',
|
name: 'http_requests_total',
|
||||||
|
|
@ -67,3 +67,8 @@ export const dbAvailableConnectionsGauge = new Gauge({
|
||||||
name: 'db_available_connections',
|
name: 'db_available_connections',
|
||||||
help: 'Number of available connections in the database pool',
|
help: 'Number of available connections in the database pool',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const dbQueryTimeHistogram = new Histogram({
|
||||||
|
name: 'db_query_duration_seconds',
|
||||||
|
help: 'Duration of database queries',
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue