diff --git a/README.md b/README.md index 425045e..8e1b833 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ Supported metric types: * Counter * Gauge +* Histogram +* Summary -Labels are supported for both metric types. +Labels are supported for all metric types. ## How to install @@ -38,6 +40,7 @@ The node expects a `message.payload` as input with the following structure: ```json { + "reset": false, "op": "inc", "val": 5, "labels": { @@ -46,6 +49,8 @@ The node expects a `message.payload` as input with the following structure: } ``` +Set `reset` if you want to reset the metric before the operation is executed. Defaults to `false`. + Choose the `op` property from one of the following values: * For metrics of type __Counter__: @@ -54,6 +59,9 @@ Choose the `op` property from one of the following values: * `set` - Sets the gauge to `val` (which is mandatory for this operation) * `inc` - Increases the gauge by `val` (without specifying `val`, defaults to `1`) * `dec` - Decreases the gauge by `val` (without specifying `val`, defaults to `1`) +* For metrics of type __Histogram__ and __Summary__: + * `observe` - Observe `val` (which is mandatory for this operation) +* Additionally, all metrics support the `nop` 'no-operation' mode, which does nothing. Useful for resets As described above, the `val` property is mandatory or optional depending on the selected `op` and the metric type. @@ -74,6 +82,35 @@ example_counter 10 # TYPE example_gauge gauge example_gauge{tag_1="computer_123"} 5 example_gauge 5 + +# HELP example_histogram This is an example Histogram +# TYPE example_histogram histogram +example_histogram_bucket{le="0.005"} 0 +example_histogram_bucket{le="0.01"} 0 +example_histogram_bucket{le="0.025"} 0 +example_histogram_bucket{le="0.05"} 0 +example_histogram_bucket{le="0.1"} 0 +example_histogram_bucket{le="0.25"} 0 +example_histogram_bucket{le="0.5"} 0 +example_histogram_bucket{le="1"} 1 +example_histogram_bucket{le="2.5"} 1 +example_histogram_bucket{le="5"} 1 +example_histogram_bucket{le="10"} 1 +example_histogram_bucket{le="+Inf"} 1 +example_histogram_sum 1 +example_histogram_count 1 + +# HELP example_summary This is an example Summary +# TYPE example_summary summary +example_summary{quantile="0.01"} 0.1 +example_summary{quantile="0.05"} 0.1 +example_summary{quantile="0.5"} 0.1 +example_summary{quantile="0.9"} 0.1 +example_summary{quantile="0.95"} 0.1 +example_summary{quantile="0.99"} 0.1 +example_summary{quantile="0.999"} 0.1 +example_summary_sum 0.1 +example_summary_count 1 ``` ### Changing the path diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9212e31 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "node-red-contrib-prometheus-exporter", + "version": "1.0.5", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "bintrees": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.1.tgz", + "integrity": "sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ=" + }, + "prom-client": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-14.0.1.tgz", + "integrity": "sha512-HxTArb6fkOntQHoRGvv4qd/BkorjliiuO2uSWC2KC17MUTKYttWdDoXX/vxOhQdkoECEM9BBH0pj2l8G8kev6w==", + "requires": { + "tdigest": "^0.1.1" + } + }, + "tdigest": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.1.tgz", + "integrity": "sha1-Ljyyw56kSeVdHmzZEReszKRYgCE=", + "requires": { + "bintrees": "1.0.1" + } + } + } +} diff --git a/package.json b/package.json index e065b86..29e5334 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,9 @@ "url": "git+https://github.com/Docoyo/node-red-contrib-prometheus-exporter.git" }, "author": "docoyo", - "contributors": [ - { - "name": "Masanori Fujita" - } - ], + "contributors": [{ + "name": "Masanori Fujita" + }], "license": "Apache-2.0", "bugs": { "url": "https://github.com/Docoyo/node-red-contrib-prometheus-exporter/issues" @@ -30,6 +28,6 @@ } }, "dependencies": { - "prom-client": "^13.1.0" + "prom-client": "^14.1.0" } -} +} \ No newline at end of file diff --git a/prometheus-exporter/prometheus-adapter.js b/prometheus-exporter/prometheus-adapter.js index ab2a96a..6f6527d 100644 --- a/prometheus-exporter/prometheus-adapter.js +++ b/prometheus-exporter/prometheus-adapter.js @@ -39,7 +39,6 @@ module.exports = { if (customRegistry._metrics[metricConfig.name]) { const metric = customRegistry._metrics[metricConfig.name]; red.log.info('Reusing Prometheus Counter ' + metricConfig.name); - metric.reset(); return metric; } else { const metric = new client.Counter(metricConfig); @@ -60,6 +59,32 @@ module.exports = { return metric; } }, + addHistogram: function (metricConfig) { + metricConfig.registers = [customRegistry]; + if (customRegistry._metrics[metricConfig.name]) { + const metric = customRegistry._metrics[metricConfig.name]; + red.log.info('Reusing Prometheus Histogram ' + metricConfig.name); + metric.reset(); + return metric; + } else { + const metric = new client.Histogram(metricConfig); + red.log.info('Added Prometheus Histogram ' + metricConfig.name); + return metric; + } + }, + addSummary: function (metricConfig) { + metricConfig.registers = [customRegistry]; + if (customRegistry._metrics[metricConfig.name]) { + const metric = customRegistry._metrics[metricConfig.name]; + red.log.info('Reusing Prometheus Summary ' + metricConfig.name); + metric.reset(); + return metric; + } else { + const metric = new client.Summary(metricConfig); + red.log.info('Added Prometheus Summary ' + metricConfig.name); + return metric; + } + }, removeMetric: function (metricName) { customRegistry.removeSingleMetric(metricName); red.log.info('Removed Prometheus metric ' + metricName); diff --git a/prometheus-exporter/prometheus-exporter.html b/prometheus-exporter/prometheus-exporter.html index b3401ab..d044ae7 100644 --- a/prometheus-exporter/prometheus-exporter.html +++ b/prometheus-exporter/prometheus-exporter.html @@ -24,6 +24,7 @@
{ + "reset": false, "op": "inc", "val": 5, "labels": { @@ -31,6 +32,7 @@+Using the metric in a flow
} }
Set reset
if you want to reset the metric before the operation is executed. Defaults to false
.
Choose the op
property from one of the following values:
1
)observe
- Observe val
(which is mandatory for this operation)nop
'no-operation' mode, which does nothing. Useful for resets.