1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-19 01:17:18 +02:00
unleash.unleash/src/lib/util/metrics/createHistogram.ts
David Leek adb6f61015
chore: proxy repository load features metrics (#6314)
## About the changes

- Adds createHistogram
- Adds histogram metrics for proxy-repositorys loading features
2024-02-22 14:29:21 +01:00

28 lines
697 B
TypeScript

import {
Histogram as PromHistogram,
HistogramConfiguration,
} from 'prom-client';
export type Histogram<T extends string = string> = {
histogram: PromHistogram<T>;
labels: (labels: Record<T, string | number>) => PromHistogram.Internal<T>;
observe: (value: number) => void;
};
export const createHistogram = <T extends string>(
options: HistogramConfiguration<T>,
): Histogram<T> => {
const histogram = new PromHistogram(options);
const labels = (labels: Record<T, string | number>) =>
histogram.labels(labels);
const observe = (value: number) => histogram.observe(value);
return {
histogram,
labels,
observe,
};
};