Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
examples
grafana-dashboards
src
test/unit
.gitignore
CHANGELOG.md
LICENSE add prometheus files Mar 26, 2018
README.md
index.js
package-lock.json update locks Dec 9, 2018
package.json

README.md

Moleculer logo

moleculer-prometheus NPM version

Moleculer metrics module for Prometheus.

Grafana screenshot

Features

  • collect default Node.js metrics.
  • measure service calls.
  • support custom metrics.
  • Grafana dashboard example.

Install

$ npm install moleculer-prometheus

Usage

// services/metrics.prometheus.service.js

const PromService = require("moleculer-prometheus");

module.exports = {
    mixins: [PromService],
    settings: {
        port: 3030,
        collectDefaultMetrics: true,
        timeout: 5 * 1000, 
    }
};

// moleculer.config.js
module.exports = {
    // ...
    metrics: true,
    // ...
}

Add custom metric

// services/metrics.prometheus.js
const PromService = require("moleculer-prometheus");

module.exports = {
    mixins: [PromService],
    settings: {
        metrics: {
           "custom_value": { type: "Gauge", help: "Moleculer Prometheus custom metric" } 
        } 
    }
});

Broadcast a metrics.update event to set the metric value

broker.broadcast("metrics.update", {
    name: "custom_value",
    method: "set",
    value: Math.round(Math.random() * 100)
});

Settings

Property Type Default Description
port Number 3030 Exposed HTTP port.
collectDefaultMetrics Boolean true Enable to collect default metrics.
timeout Number 10000 Timeout option for 'collectDefaultMetrics' in milliseconds.
metrics Object {} Metric definitions.

Default Moleculer metrics

Name Type Labels Description
moleculer_nodes_total Gauge - Moleculer nodes count
moleculer_services_total Gauge - Moleculer services count
moleculer_actions_total Gauge - Moleculer actions count
moleculer_events_total Gauge - Moleculer event subscription count
moleculer_nodes Gauge nodeID, type, version, langVersion Moleculer node list
moleculer_action_endpoints_total Gauge action Moleculer action endpoints
moleculer_service_endpoints_total Gauge service, version Moleculer service endpoints
moleculer_event_endpoints_total Gauge event, group Moleculer event endpoints
moleculer_req_total Counter action, service, nodeID Moleculer request count
moleculer_req_errors_total Counter action, service, nodeID, errorCode, errorName, errorType Moleculer request error count
moleculer_req_duration_ms Histogram action, service, nodeID Moleculer request durations

Methods

update

Update a metric value.

Parameters

Property Type Default Description
name String required
method String required
labels Object -
value any required
timestamp any required

Test

$ npm test

In development with watching

$ npm run ci

License

The project is available under the MIT license.

Contact

Copyright (c) 2016-2018 MoleculerJS

@moleculerjs @MoleculerJS

You can’t perform that action at this time.