import {PromMetric, PromOptions} from './metric';
import {Histogram, HistogramFactory, Providers, Tags} from '@btilford/ts-base-core';
import {Histogram as Delegate, Registry} from 'prom-client';
export class PromHistogram extends PromMetric implements Histogram<number> {
protected readonly impl: Delegate<any>;
constructor(name: string, tags: Tags, options: PromOptions) {
super(name, tags, options);
this.impl = new Delegate({
name: this.name,
help: options.help,
registers: options.registry || [Providers.provide(Registry)],
aggregator: options.aggregator,
labelNames: [...this.supportedLabels],
});
}
set(value: number, tags: Tags = {}): void {
const _tags = this.filterTags({ ...this.tags, ...tags });
this.impl.observe(_tags, value);
}
}
export class PromHistogramFactory extends HistogramFactory<number> {
protected readonly options: PromOptions;
constructor(options: PromOptions) {
super();
this.options = { ...options };
}
histogram(name: string, tags): Histogram<number> {
return new PromHistogram(name, tags, this.options);
}
}
|