Class: PrometheusMetrics

PrometheusMetrics()

new PrometheusMetrics()

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.
Source:
Examples

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);
      },
  });

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);
  });

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();
  }

Methods

addAppServicePath(bridge)

Registers the /metrics page generating function with the containing Express app.
Parameters:
Name Type Description
bridge Bridge The containing Bridge instance.
Source:

addCollector(func)

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:
Name Type Description
func function 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.
Source:

addCounter(opts) → {Counter}

Adds a new counter metric
Parameters:
Name Type Description
opts Object Options
Properties
Name Type Attributes Description
namespace string An optional toplevel namespace name for the new metric. Default: "bridge".
name string The variable name for the new metric.
help string Descriptive help text for the new metric. Once created, the value of this metric can be incremented with the incCounter method.
labels Array.<string> <optional>
An optional list of string label names
Source:
Returns:
A counter metric.
Type
Counter

addGauge(opts) → {Gauge}

Adds a new gauge metric.
Parameters:
Name Type Description
opts Object Options
Properties
Name Type Attributes Description
namespace string <optional>
An optional toplevel namespace name for the new metric. Default: "bridge".
name string The variable name for the new metric.
help string Descriptive help text for the new metric.
labels Array.<string> <optional>
An optional list of string label names
refresh function <optional>
An optional function to invoke to generate a new value for the gauge. If a refresh function is provided, it is invoked with the gauge as its only parameter. The function should call the set() method on this gauge in order to provide a new value for it.
Source:
Returns:
A gauge metric.
Type
Gauge

addTimer(opts) → {Histogram}

Adds a new timer metric, represented by a prometheus Histogram.
Parameters:
Name Type Description
opts Object Options
Properties
Name Type Attributes Description
namespace string An optional toplevel namespace name for the new metric. Default: "bridge".
name string The variable name for the new metric.
help string Descriptive help text for the new metric.
labels Array.<string> <optional>
An optional list of string label names
Source:
Returns:
A histogram metric. Once created, the value of this metric can be incremented with the startTimer method.
Type
Histogram

incCounter()

Increments the value of a counter metric
Source:

registerBridgeGauges(counterFunc)

Registers some exported metrics that expose counts of various kinds of objects within the bridge.
Parameters:
Name Type Description
counterFunc BridgeGaugesCallback A function that when invoked returns the current counts of various items in the bridge.
Source:

registerMatrixSdkMetrics()

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.
Source:

startTimer() → {function}

Begins a new timer observation for a timer metric.
Source:
Returns:
A function to be called to end the timer and report the observation.
Type
function