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 <markus.hube@t-online.de>
This commit is contained in:
Markus Hube
2025-11-22 10:47:35 +01:00
committed by Tianling Shen
parent ba55134a1a
commit 803a754525
3 changed files with 14 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=prometheus-node-exporter-lua
PKG_VERSION:=2025.07.15
PKG_VERSION:=2025.11.22
PKG_RELEASE:=1
PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com>

View File

@@ -11,7 +11,7 @@ _log() {
start_service() {
. /lib/functions/network.sh
local interface port listenflag cert key bind4 bind6
local interface port listenflag cert key bind4 bind6 omit_zero_values
config_load prometheus-node-exporter-lua.main
config_get keepalive "main" http_keepalive 70
@@ -19,6 +19,7 @@ start_service() {
config_get port "main" listen_port 9100
config_get cert "main" cert
config_get key "main" key
config_get omit_zero_values "main" omit_zero_values 0
[ "$interface" = "*" ] || {
network_get_ipaddr bind4 "$interface"
@@ -31,6 +32,8 @@ start_service() {
procd_open_instance
[ "$omit_zero_values" -eq 1 ] && procd_set_param env OMIT_ZERO_VALUES=1
procd_set_param command /usr/sbin/uhttpd -f -c /dev/null -l / -L /usr/bin/prometheus-node-exporter-lua
[ $keepalive -gt 0 ] && procd_append_param command -k $keepalive

View File

@@ -8,6 +8,10 @@
socket = require("socket")
-- get configs
local omit_zero_values = os.getenv("OMIT_ZERO_VALUES") == "1"
-- Parsing
function space_split(s)
@@ -50,9 +54,13 @@ end
function metric(name, mtype, labels, value)
out:write("# TYPE ", name, " ", mtype, "\n")
-- omit_zero_vales config supress time series always being zero
local printall = not (mtype == "counter" and omit_zero_values)
local outputter = function(labels, value)
if printall or tonumber(value) ~= 0 then
print_metric(name, labels, value)
end
end
if value then
outputter(labels, value)
end