import {Counter, CounterFactory, Tags} from '@btilford/ts-base-core';
import {StatsDMetric, StatsDOptions} from './metric';
class StatsDCounter extends StatsDMetric implements Counter<number> {
decrement(val: number, tags: Tags = {}): void {
this.statsd.decrement(
this.name,
val || 1,
this.options.sampleRate,
{
...this.tags,
...tags,
},
);
}
increment(val: number, tags: Tags = {}): void {
this.statsd.increment(
this.name,
val || 1,
this.options.sampleRate,
{
...this.tags,
...tags,
},
);
}
}
export class StatsDCounterFactory extends CounterFactory<number> {
protected readonly options: StatsDOptions;
constructor(options: StatsDOptions = {}) {
super();
this.options = { ...options };
}
counter(name: string, tags: Tags = {}): Counter<number> {
return new StatsDCounter(name, this.options, tags);
}
}
|