prometheus-metrics-reporter
v1.3.0
Published
Generates prometheus metrics using tasks from config file
Downloads
3
Readme
prometheus-metrics
Utility to generate prometheus metrics based on tasks from config
How to use
Install
npm install @akasybe/prometheus-metrics --save-dev
Create config file
Create file metrics.config.js
in root directory:
module.exports = {
output: "build/metrics.txt",
tasks: [
{
type: "size",
path: "build/*.js",
labels: {
compression: "gzip",
type: "javascript",
project: "app",
},
// optional, 'bundle_size_bytes_total` is default value
// metricName: "bundle_size_bytes_total"
},
{
type: "custom",
// client is default export from 'prom-client' library
resolve: function(client) {
// you can create any valid metric, please refer to 'prom-client' docs
const metric = new client.Counter({
name: "metric_name",
help: "metric_help",
});
// calculate metric value
metric.inc(1);
// and do not forget to return metric
return metric;
},
},
],
};
Supported 2 task types: size
and custom
.
- Task with type
size
should havepath
as glob pattern andlabels
(these are prometheus labels) - Task with type
custom
should haveresolve
method that returns singleprom-client
metric
Add script
Add script in package.json
:
"scripts": {
"metrics": "prometheus-metrics"
}
Run
npm run metrics
Now go to output
directory and look at metrics.txt
file