1.3.0 • Published 5 years ago
prometheus-metrics-reporter v1.3.0
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
sizeshould havepathas glob pattern andlabels(these are prometheus labels) - Task with type
customshould haveresolvemethod that returns singleprom-clientmetric
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
1.3.0
5 years ago