make metric buckets configurable

This commit is contained in:
Erik 2023-11-11 23:01:39 +02:00
parent 69a7016e97
commit 69021a5c8e
2 changed files with 6 additions and 4 deletions

View File

@ -26,7 +26,8 @@ export type MariaOptions = {
credentials: Credentials, credentials: Credentials,
loggerOptions?: LoggerClientOptions, loggerOptions?: LoggerClientOptions,
donorQuery?: boolean, donorQuery?: boolean,
recordMetrics?: boolean recordMetrics?: boolean,
metricsBuckets?: number[],
} }
type MariaError = { type MariaError = {
@ -247,7 +248,7 @@ class MariaDB
MariaDB.#queryHistogram = new Prometheus.Histogram({ MariaDB.#queryHistogram = new Prometheus.Histogram({
name: 'sql_queries', name: 'sql_queries',
help: 'Tracks query duration in seconds and frequency', help: 'Tracks query duration in seconds and frequency',
buckets: Prometheus?.exponentialBuckets(0.005, 2, 10), buckets: this.#config.metricsBuckets ?? Prometheus?.exponentialBuckets(0.005, 2, 10),
labelNames: [ 'type' ] as const labelNames: [ 'type' ] as const
}); });
this.#server.registerMetric(MariaDB.#queryHistogram!); this.#server.registerMetric(MariaDB.#queryHistogram!);

View File

@ -22,7 +22,8 @@ export type MongoOptions = {
loggerOptions?: LoggerClientOptions, loggerOptions?: LoggerClientOptions,
client?: MongoClientOptions, client?: MongoClientOptions,
load?: boolean, load?: boolean,
recordMetrics?: boolean recordMetrics?: boolean,
metricsBuckets?: number[],
} }
type StringIndexable = {[key: string]: boolean | string | number | Document | object} type StringIndexable = {[key: string]: boolean | string | number | Document | object}
@ -151,7 +152,7 @@ class MongoDB
MongoDB.#queryHistogram = new Prometheus.Histogram({ MongoDB.#queryHistogram = new Prometheus.Histogram({
name: 'mongo_queries', name: 'mongo_queries',
help: 'Tracks query duration in seconds and frequency', help: 'Tracks query duration in seconds and frequency',
buckets: Prometheus?.exponentialBuckets(0.005, 2, 10), buckets: this.#config.metricsBuckets ?? Prometheus?.exponentialBuckets(0.005, 2, 10),
labelNames: [ 'type' ] as const labelNames: [ 'type' ] as const
}); });
this.#server.registerMetric(MongoDB.#queryHistogram!); this.#server.registerMetric(MongoDB.#queryHistogram!);