-
-
Notifications
You must be signed in to change notification settings - Fork 282
/
registryMetricCreator.ts
41 lines (36 loc) · 1.56 KB
/
registryMetricCreator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {Gauge, Registry, Counter, Histogram} from "prom-client";
import {
AvgMinMaxConfig,
CounterConfig,
GaugeConfig,
HistogramConfig,
AvgMinMax as IAvgMinMax,
Counter as ICounter,
GaugeExtra as IGaugeExtra,
Histogram as IHistogram,
LabelKeys,
LabelsGeneric,
MetricsRegisterCustom,
NoLabels,
StaticConfig,
} from "@lodestar/utils";
import {AvgMinMax} from "./avgMinMax.js";
import {GaugeExtra} from "./gauge.js";
export class RegistryMetricCreator extends Registry implements MetricsRegisterCustom {
gauge<Labels extends LabelsGeneric = NoLabels>(configuration: GaugeConfig<Labels>): IGaugeExtra<Labels> {
return new GaugeExtra<Labels>({...configuration, registers: [this]});
}
histogram<Labels extends LabelsGeneric = NoLabels>(configuration: HistogramConfig<Labels>): IHistogram<Labels> {
return new Histogram<LabelKeys<Labels>>({...configuration, registers: [this]});
}
avgMinMax<Labels extends LabelsGeneric = NoLabels>(configuration: AvgMinMaxConfig<Labels>): IAvgMinMax<Labels> {
return new AvgMinMax<Labels>({...configuration, registers: [this]});
}
/** Static metric to send string-based data such as versions, config params, etc */
static<Labels extends LabelsGeneric = NoLabels>({name, help, value}: StaticConfig<Labels>): void {
new Gauge({name, help, labelNames: Object.keys(value), registers: [this]}).set(value, 1);
}
counter<Labels extends LabelsGeneric = NoLabels>(configuration: CounterConfig<Labels>): ICounter<Labels> {
return new Counter<LabelKeys<Labels>>({...configuration, registers: [this]});
}
}