Skip to content

prometheus-node-exporter-lua: omit zero #22946

@NoctivagusObitus

Description

@NoctivagusObitus

Maintainer: @champtar
Environment: OpenWrt 22.03.2, r19803-9a599fee93

Description:

I am using the Prometheus node exporter on OpenWrt for a while now. What I have noticed is, depending on the config, there may be multiple time series always zero (e.g. node_network_transmit_carrier_total{device="lan1"} 0). To me these don't provide any value but increase cpu load measurably. For the time being I have implemented a filter on my devices locally like shown here: master...NoctivagusObitus:packages:feature_omit_zero_export

diff --git a/utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua b/utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua
index 36f064c5b..a70a7606a 100755
--- a/utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua
+++ b/utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua
@@ -45,7 +45,9 @@ end
 function metric(name, mtype, labels, value)
   output("# TYPE " .. name .. " " .. mtype)
   local outputter = function(labels, value)
-    print_metric(name, labels, value)
+    if tonumber(value) ~= 0 then
+      print_metric(name, labels, value)
+    end
   end
   if value then
     outputter(labels, value)
lines 1-21/21 (END)

On this Grafana dashboard I disabled my filter. The exported time series where about doubled.
image

This works fine for me since more then a year now.

I would be happy to contribute a configurable version of this, exporting all series by default. Therefor I would kindly ask for a little push in the right direction for using dynamic arguments in the referenced lua script. From what I understand the node exporter gets called by utthpd in this line

procd_set_param command /usr/sbin/uhttpd -f -c /dev/null -l / -L /usr/bin/prometheus-node-exporter-lua
But the -L switch seams to only take one argument which is a file and no additional parameters. There may be a better approach?

Looking forward to get feedback on this one.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions