Options
All
  • Public
  • Public/Protected
  • All
Menu

Counter Metric

  • For Prometheus, counters go up, and reset when the process restarts.
  • For Statsd, counters go up, and reset when stasd daemon is restarted.
import { Counter } from '@mists/nestjs-metrics';

const counter = new Counter('metric_counter');

// force prometheus settings
const counter = new Counter('metric_counter', {
  prometheus: {
    help: 'This is a counter metric'
  }
})

// force statsd settings; if no settings are provided here,
// default settings will be used
const counter = new Counter('metric_counter', {
  statsd: {
    host: 'localhost',
    socketTimeout: 2000,
  }
})

Hierarchy

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • Parameters

    • name: string

      Name used for the metric

    • Optional options: CounterOptions

      Options for the metric
      Depending on the metric technology used. Even though the MetricOptions support almost all options for each supported technology, be careful how you use and setup your options since they may generated strange behaviors that were not intended with this API.

    Returns Counter

Properties

Protected name

name: string

Name used for the metric

Protected options

options: MetricOptions

Options for the metric
Depending on the metric technology used. Even though the MetricOptions support almost all options for each supported technology, be careful how you use and setup your options since they may generated strange behaviors that were not intended with this API.

Protected prometheusMetric

prometheusMetric: any

Protected statsdClient

statsdClient: any

Accessors

Protected statsdName

  • get statsdName(): string

Methods

inc

  • inc(value?: number, tags?: Tags): void
  • Increment method.

    import { Counter } from '@mists/nestjs-metrics';
    
    const counter = new Counter('metric_counter');
    
    // will increment by 1 (the default value)
    counter.inc();
    
    // will increment by 10 (custom value)
    counter.inc(10);
    
    // will increment by 1, attaching also a `server_id` label
    counter.inc(1, {server_id: 'instance_1'})

    Parameters

    • Default value value: number = 1

      Value to increment with; default 1

    • Optional tags: Tags

      Tags to attach to the increment; optional

    Returns void

Legend

  • Property
  • Method
  • Constructor
  • Method
  • Inherited method
  • Protected property
  • Static method

Generated using TypeDoc