Skip to content
Prometheus metrics for opossum circuit breakers
JavaScript
Branch: master
Clone or download
greenkeeper chore(package): Update opossum to the latest version 🚀 (#13)
* chore(package): update opossum to version 5.0.0

* chore(package): update lockfile package-lock.json
Latest commit 50c6d7e Feb 20, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
test
.eslintrc
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
LICENSE
README.md
index.js
package-lock.json
package.json

README.md

Prometheus Metrics for Opossum Circuit Breaker

CircleCI Codacy Badge Codacy Badge dependencies Status Known Vulnerabilities Greenkeeper badge

This module provides Prometheus metrics for opossum circuit breakers. To use it with your circuit breakers, just pass them in to the PrometheusMetrics constructor.

For each circuit breaker, the metrics are:

  • a prometheus counter for each event name
  • a prometheus summary for the events success, failed execution time.

Example:

  const CircuitBreaker = require('opossum');
  const PrometheusMetrics = require('opossum-prometheus');

  // create a couple of circuit breakers
  const c1 = new CircuitBreaker(someFunction);
  const c2 = new CircuitBreaker(someOtherfunction);

  // Provide them to the constructor
  const prometheus = new PrometheusMetrics([c1, c2]);

  //...
  // Provide other circuit breaker later
  const c3 = new CircuitBreaker(someOtherfunction3);
  prometheus.add([C3]);
  
  // Write metrics to the console
  console.log(prometheus.metrics);

This module would typically be used in an application that can provide an endpoint for the Prometheus server to monitor.

The prometheusRegistry constructor parameter allows you to provide an existing prom-client registry. The metrics about the circuit will be added to the provided registry instead of the global registry. The default metrics will not be added to the provided registry.

const CircuitBreaker = require('opossum');
const PrometheusMetrics = require('opossum-prometheus');
const { Registry } = require('prom-client');

// Create a registry
const registry = new Registry();

// create a circuit
const circuit = new CircuitBreaker(functionThatMightFail);
const metrics = new PrometheusMetrics(circuit, registry)
You can’t perform that action at this time.