prometheus-plugin-memory-stats
v2.0.0
Published
Node.js prometheus client plugin for exporting memory statistics.
Downloads
2
Maintainers
Readme
prometheus-plugin-memory-stats
Node.js prometheus client plugin for collecting general memory stats like rss, external, heap used and total.
Installation
npm i -S prometheus-plugin-memory-stats
Requirements
>=prom-client-4.0.0
npm module (installed as peer dependency). If your project depends on previous version of client this plugin might not work.>=node-4.0.0
because this module uses ES6 syntax
Metric list
Process heap size in bytes
- type: 'Gauge'
- name: 'nodejs_heap_size_bytes'
- labels: ['type'] - 'used' | 'total'
Process resident set size in bytes
- type: 'Gauge'
- name: 'nodejs_rss_size_bytes'
- labels: []
Process external size in bytes
- type: 'Gauge'
- name: 'nodejs_external_size_bytes'
- labels: []
Usage
Simple
const client = require('prom-client');
const memoryPlugin = require('prometheus-plugin-memory-stats');
// start metrics collection
memoryPlugin.init().start();
// log metrics to console
console.log(client.register.metrics());
// stop metrics collection
memoryPlugin.stop();
// stop and clear metrics register
memoryPlugin.reset();
Override metric defaults
const client = require('prom-client');
const memoryPlugin = require('prometheus-plugin-memory-stats');
const override = {
'metric_name': { // provide default metric name to override it's params
type: 'Counter', // could be changed, but it's not recommended
name: 'my_metric_name', // name could be changed
description: 'My custom description', // description could be changed
labelValues: { // additional labels
customLabel: 'hello', // custom labels could be added
customFnLabel: () => { return new Date() } // if it's a function, it will be called to get label value in runtime
}
}
};
// start metrics collection
memoryPlugin.init(override).start(); // pass override object to init function
// log metrics to console
console.log(client.register.metrics());
// stop metrics collection
memoryPlugin.stop();
// stop and clear metrics register
memoryPlugin.reset();