Code coverage report for node/src/apm/statsd/gauge.ts

Statements: 33.33% (4 / 12)      Branches: 0% (0 / 5)      Functions: 0% (0 / 6)      Lines: 33.33% (4 / 12)      Ignored: none     

All files » node/src/apm/statsd/ » gauge.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 42 43 44 45 46 47 48 49 50 51 521 1     1                                                             1                                
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);
  }
 
 
}