import {StatsDMetric, StatsDOptions} from './metric';
import {Gauge, GaugeFactory, Tags} from '@btilford/ts-base-core';
export class StatsDGauge extends StatsDMetric implements Gauge<number> {
protected last = 0;
set(val: number, tags: Tags = {}): void {
this.statsd.gauge(
this.name,
val,
this.options.sampleRate,
{
...this.tags,
...tags,
},
);
this.last = val;
}
decrement(val: number, tags: Tags = {}): void {
this.set(this.last - val, tags);
}
increment(val: number, tags: Tags = {}): void {
this.set(this.last + val, tags);
}
}
export class StatsDGaugeFactory extends GaugeFactory<number> {
protected readonly options: StatsDOptions;
constructor(options: StatsDOptions = {}) {
super();
this.options = { ...options };
}
gauge(name: string, tags: Tags = {}): Gauge<number> {
return new StatsDGauge(name, this.options, tags);
}
}
|