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

Statements: 36.36% (4 / 11)      Branches: 0% (0 / 13)      Functions: 0% (0 / 1)      Lines: 36.36% (4 / 11)      Ignored: none     

All files » node/src/apm/statsd/ » metric.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 441 1 1                     1                                                            
import {StatsD} from 'hot-shots';
import {Tags, Providers} from '@btilford/ts-base-core';
import * as os from 'os';
 
export type StatsDOptions = {
  statsd?: StatsD;
  sampleRate?: number;
  tags?: Tags;
  prefix?: string;
  suffix?: string;
}
 
 
export class StatsDMetric {
  readonly tags: Tags;
  protected readonly options: StatsDOptions;
  protected readonly statsd: StatsD;
 
  constructor(
    readonly name: string,
    options: StatsDOptions,
    tags: Tags = {}
  ) {
    this.options = { ...options };
    this.tags = {
      pid: `${process.pid}`,
      NODE_ENV: process.env.NODE_ENV || 'not set',
      host: os.hostname(),
      os: os.type(),
      platform: os.platform(),
 
      ...options.tags,
      ...tags
    };
    const statsd = options.statsd || Providers.provide(StatsD);
    if (this.options.prefix || this.options.suffix) {
      this.statsd = statsd?.childClient(this.options);
    } else {
      this.statsd = statsd;
    }
 
  }
}