Skip to content

Commit 9237ffb

Browse files
author
Markus Hube
committed
prometheus-node-exporter-lua: remove zero values
depending on the configuration there may be multiple interfaces creating multiple time series always reporting 0 value. omiting them from the export saves resources. most notably cpu. this is limited to counter types Signed-off-by: Markus Hube <[email protected]~>
1 parent 6d210ad commit 9237ffb

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

utils/prometheus-node-exporter-lua/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
include $(TOPDIR)/rules.mk
55

66
PKG_NAME:=prometheus-node-exporter-lua
7-
PKG_VERSION:=2024.06.16
7+
PKG_VERSION:=2025.04.13
88
PKG_RELEASE:=2
99

1010
PKG_MAINTAINER:=Etienne CHAMPETIER <[email protected]>

utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ _log() {
1111
start_service() {
1212
. /lib/functions/network.sh
1313

14-
local interface port bind4 bind6
14+
local interface port bind4 bind6 omit_zero_values
1515

1616
config_load prometheus-node-exporter-lua.main
1717
config_get keepalive "main" http_keepalive 70
1818
config_get interface "main" listen_interface "loopback"
1919
config_get port "main" listen_port 9100
20+
config_get omit_zero_values "main" omit_zero_values 0
2021

2122
[ "$interface" = "*" ] || {
2223
network_get_ipaddr bind4 "$interface"
@@ -29,6 +30,8 @@ start_service() {
2930

3031
procd_open_instance
3132

33+
[ "$omit_zero_values" -eq 1 ] && procd_set_param env OMIT_ZERO_VALUES=1
34+
3235
procd_set_param command /usr/sbin/uhttpd -f -c /dev/null -l / -L /usr/bin/prometheus-node-exporter-lua
3336
[ $keepalive -gt 0 ] && procd_append_param command -k $keepalive
3437

utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
socket = require("socket")
1010

11+
-- get configs
12+
13+
local omit_zero_values = os.getenv("OMIT_ZERO_VALUES") == "1"
14+
1115
-- Parsing
1216

1317
function space_split(s)
@@ -44,8 +48,12 @@ end
4448

4549
function metric(name, mtype, labels, value)
4650
output("# TYPE " .. name .. " " .. mtype)
51+
-- omit_zero_vales config supress time series always being zero
52+
local printall = not (mtype == "counter" and omit_zero_values)
4753
local outputter = function(labels, value)
48-
print_metric(name, labels, value)
54+
if printall or tonumber(value) ~= 0 then
55+
print_metric(name, labels, value)
56+
end
4957
end
5058
if value then
5159
outputter(labels, value)

0 commit comments

Comments
 (0)