Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove op #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ Choose the `op` property from one of the following values:

* For metrics of type __Counter__:
* `inc` - Increases the counter by `val` (without specifying `val`, defaults to `1`)
* `remove` - Remove the stored value
* For metrics of type __Gauge__:
* `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`)
* `remove` - Remove the stored value

As described above, the `val` property is mandatory or optional depending on the selected `op` and the metric type.

Expand Down
4 changes: 3 additions & 1 deletion prometheus-exporter/prometheus-exporter.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h2>Using the metric in a flow</h2>
<ul>
<li><code>inc</code> - Increases the counter by <code>val</code> (without specifying <code>val</code>,
defaults to <code>1</code>)</li>
<li><code>remove</code> - Remove the stored value</li>
</ul>
</li>
<li>For metrics of type <strong>Gauge</strong>:
Expand All @@ -46,6 +47,7 @@ <h2>Using the metric in a flow</h2>
to <code>1</code>)</li>
<li><code>dec</code> - Decreases the gauge by <code>val</code> (without specifying <code>val</code>, defaults
to <code>1</code>)</li>
<li><code>remove</code> - Remove the stored value</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -101,4 +103,4 @@ <h2>Check the metrics output</h2>
label: label,
paletteLabel: 'prometheus out'
});
</script>
</script>
8 changes: 4 additions & 4 deletions prometheus-exporter/prometheus-exporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const VALID_OPS = {
counter: ['inc'],
gauge: ['inc', 'dec', 'set']
counter: ['inc', 'remove'],
gauge: ['inc', 'dec', 'set', 'remove']
};

const DEFAULT_OPS = {
Expand Down Expand Up @@ -37,8 +37,8 @@ module.exports = function (RED) {
}
// apply specific value
if (msg.payload.val === undefined || msg.payload.val === null) {
// no value is only allowed for counter
if (this.metricConfig.mtype !== 'counter') {
// no value is only allowed for counter or remove op
if (this.metricConfig.mtype !== 'counter' && metricOp !== 'remove') {
done('Missing val for metric type ' + this.metricConfig.mtype);
}
} else {
Expand Down