From 1288bd6473b61b10bb3539ddf4633dcfcab76adc Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Sun, 25 Nov 2018 16:57:27 +0300 Subject: [PATCH] prometheus-node-exporter-lua: close io.popen files to reap zombies Signed-off-by: Leonid Evdokimov --- utils/prometheus-node-exporter-lua/Makefile | 2 +- .../files/usr/bin/prometheus-node-exporter-lua | 4 +++- .../files/usr/lib/lua/prometheus-collectors/uname.lua | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index 2fc73562ff..6596689586 100644 --- a/utils/prometheus-node-exporter-lua/Makefile +++ b/utils/prometheus-node-exporter-lua/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=prometheus-node-exporter-lua PKG_VERSION:=2018.07.23 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_MAINTAINER:=Etienne CHAMPETIER PKG_LICENSE:=Apache-2.0 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 62e402280f..35addf1dcd 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 @@ -119,11 +119,13 @@ end col_mods = {} col_names = {} -for c in io.popen("ls -1 /usr/lib/lua/prometheus-collectors/*.lua"):lines() do +ls_fd = io.popen("ls -1 /usr/lib/lua/prometheus-collectors/*.lua") +for c in ls_fd:lines() do c = c:match("([^/]+)%.lua$") col_mods[c] = require('prometheus-collectors.'..c) col_names[#col_names+1] = c end +ls_fd:close() if port then server = assert(socket.bind(bind, port)) diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uname.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uname.lua index 9874b53a9d..75a366e3b7 100644 --- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uname.lua +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uname.lua @@ -1,12 +1,16 @@ +local uname_fd = io.popen("uname -m") + local labels = { domainname = "", nodename = "", release = string.sub(get_contents("/proc/sys/kernel/osrelease"), 1, -2), sysname = string.sub(get_contents("/proc/sys/kernel/ostype"), 1, -2), version = string.sub(get_contents("/proc/sys/kernel/version"), 1, -2), - machine = string.sub(io.popen("uname -m"):read("*a"), 1, -2) + machine = string.sub(uname_fd:read("*a"), 1, -2) } +uname_fd:close() + local function scrape() labels["domainname"] = string.sub(get_contents("/proc/sys/kernel/domainname"), 1, -2) labels["nodename"] = string.sub(get_contents("/proc/sys/kernel/hostname"), 1, -2) -- 2.30.2