import {Gauge, GaugeFactory, Providers, Tags} from '@btilford/ts-base-core';
import {PromMetric, PromOptions} from './metric';
import {Gauge as Delegate, Registry} from 'prom-client';
export class PromGauge extends PromMetric implements Gauge<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(val: number, tags: Tags = {}): void {
const _tags = this.filterTags({ ...this.tags, ...tags });
this.impl.set(_tags, val);
}
decrement(val: number, tags: Tags = {}): void {
const _tags = this.filterTags({ ...this.tags, ...tags });
this.impl.dec(_tags, val);
}
increment(val: number, tags: Tags = {}): void {
const _tags = this.filterTags({ ...this.tags, ...tags });
this.impl.inc(_tags, val);
}
reset(): void {
this.impl.reset();
}
}
export class PromGaugeFactory extends GaugeFactory<number> {
protected readonly options: PromOptions;
constructor(options: PromOptions) {
super();
this.options = { ...options };
}
gauge(name: string, tags = {}): PromGauge {
return new PromGauge(name, tags, this.options);
}
}
|