Moleculer metrics module for Prometheus.
- collect default Node.js metrics.
- measure service calls.
- support custom metrics.
- Grafana dashboard example.
$ npm install moleculer-prometheus
// 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,
// ...
}
// 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)
});
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. |
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 |
Update a metric value.
Property | Type | Default | Description |
---|---|---|---|
name |
String |
required | |
method |
String |
required | |
labels |
Object |
- | |
value |
any |
required | |
timestamp |
any |
required |
$ npm test
In development with watching
$ npm run ci
The project is available under the MIT license.
Copyright (c) 2016-2018 MoleculerJS