Skip to content

Commit 803a754

Browse files
NoctivagusObitus1715173329
authored andcommitted
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 ba55134 commit 803a754

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:=2025.07.15
7+
PKG_VERSION:=2025.11.22
88
PKG_RELEASE:=1
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,14 +11,15 @@ _log() {
1111
start_service() {
1212
. /lib/functions/network.sh
1313

14-
local interface port listenflag cert key bind4 bind6
14+
local interface port listenflag cert key 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
2020
config_get cert "main" cert
2121
config_get key "main" key
22+
config_get omit_zero_values "main" omit_zero_values 0
2223

2324
[ "$interface" = "*" ] || {
2425
network_get_ipaddr bind4 "$interface"
@@ -31,6 +32,8 @@ start_service() {
3132

3233
procd_open_instance
3334

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

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)
@@ -50,8 +54,12 @@ end
5054

5155
function metric(name, mtype, labels, value)
5256
out:write("# TYPE ", name, " ", mtype, "\n")
57+
-- omit_zero_vales config supress time series always being zero
58+
local printall = not (mtype == "counter" and omit_zero_values)
5359
local outputter = function(labels, value)
54-
print_metric(name, labels, value)
60+
if printall or tonumber(value) ~= 0 then
61+
print_metric(name, labels, value)
62+
end
5563
end
5664
if value then
5765
outputter(labels, value)

0 commit comments

Comments
 (0)