Options
All
  • Public
  • Public/Protected
  • All
Menu

Prometheus-style /metrics gathering and exporting. This class provides a central location to register gauge and counter metrics used to generate the /metrics page.

This class depends on having prom-client installed. It will attempt to load this module when the constructor is invoked.

example
A simple metric that counts the keys in an object: var metrics = new PrometheusMetrics();

var orange = {}; metrics.addGauge({ name: "oranges", help: "current number of oranges", refresh: (gauge) => { gauge.set({}, Object.keys(oranges).length); }, });

example
Generating values for multiple gauges in a single collector function. var metrics = new PrometheusMetrics();

var oranges_gauge = metrics.addGauge({ name: "oranges", help: "current number of oranges", }); var apples_gauge = metrics.addGauge({ name: "apples", help: "current number of apples", });

metrics.addCollector(() => { var counts = this._countFruit(); oranges_gauge.set({}, counts.oranges); apples_gauge.set({}, counts.apples); });

example
Using counters var metrics = new PrometheusMetrics();

metrics.addCollector({ name: "things_made", help: "count of things that we have made", });

function makeThing() { metrics.incCounter("things_made"); return new Thing(); }

Hierarchy

  • PrometheusMetrics

Index

Constructors

constructor

Properties

Static AgeCounters

AgeCounters: AgeCounters = AgeCounters

Methods

addAppServicePath

  • addAppServicePath(bridge: Bridge): void

addCollector

  • addCollector(func: CollectorFunction): void
  • Adds a new collector function. These collector functions are run whenever the /metrics page is about to be generated, allowing code to update values of gauges.

    Parameters

    • func: CollectorFunction

      A new collector function. This function is passed no arguments and is not expected to return anything. It runs purely to have a side-effect on previously registered gauges.

    Returns void

addCounter

  • addCounter(opts: CounterOpts): Counter<string>

addGauge

  • addGauge(opts: GagueOpts): Gauge<string>

addTimer

  • addTimer(opts: CounterOpts): Histogram<string>
  • Adds a new timer metric, represented by a prometheus Histogram.

    Parameters

    • opts: CounterOpts

      Options

    Returns Histogram<string>

    A histogram metric. Once created, the value of this metric can be incremented with the startTimer method.

incCounter

  • incCounter(name: string, labels: {}): void
  • Increments the value of a counter metric

    param{string}

    name The name the metric was previously registered as.

    param{object}

    labels Optional object containing additional label values.

    Parameters

    • name: string
    • labels: {}
      • [label: string]: string

    Returns void

refresh

  • refresh(): void

registerBridgeGauges

registerMatrixSdkMetrics

  • registerMatrixSdkMetrics(): void
  • Registers some exported metrics that relate to operations of the embedded matrix-js-sdk. In particular, a metric is added that counts the number of calls to client API endpoints made by the client library.

    Returns void

startTimer

  • startTimer(name: string, labels: {}): (labels?: LabelValues<T>) => void
  • Begins a new timer observation for a timer metric.

    param{string}

    name The name the metric was previously registered as.

    param{object}

    labels Optional object containing additional label values.

    Parameters

    • name: string
    • labels: {}
      • [label: string]: string

    Returns (labels?: LabelValues<T>) => void

    A function to be called to end the timer and report the observation.

      • (labels?: LabelValues<T>): void
      • Parameters

        • Optional labels: LabelValues<T>

        Returns void

Generated using TypeDoc