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

Statements: 29.41% (5 / 17)      Branches: 0% (0 / 6)      Functions: 0% (0 / 7)      Lines: 29.41% (5 / 17)      Ignored: none     

All files » node/src/apm/prometheus/ » 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 52 53 54 55 56 57 58 59 60 61 621 1 1     1                                                                                 1                              
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);
  }
 
}