This commit is contained in:
NoctivagusObitus 2024-04-26 15:00:54 +03:00 committed by GitHub
commit 9daad1ace1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 16 deletions

View File

@ -11,12 +11,13 @@ _log() {
start_service() {
. /lib/functions/network.sh
local interface port bind4 bind6
local interface port bind4 bind6 omit_zero_values
config_load prometheus-node-exporter-lua.main
config_get keepalive "main" http_keepalive 70
config_get interface "main" listen_interface "loopback"
config_get port "main" listen_port 9100
config_get omit_zero_values "main" omit_zero_values 0
[ "$interface" = "*" ] || {
network_get_ipaddr bind4 "$interface"
@ -29,6 +30,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
@ -46,8 +49,7 @@ start_service() {
procd_close_instance
}
service_triggers()
{
service_triggers() {
local interface
procd_add_reload_trigger "prometheus-node-exporter-lua"

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)
@ -22,7 +26,7 @@ function get_contents(filename)
local f = io.open(filename, "rb")
local contents = ""
if f then
contents = f:read "*a"
contents = f:read("*a")
f:close()
end
@ -45,8 +49,10 @@ end
function metric(name, mtype, labels, value)
output("# TYPE " .. name .. " " .. mtype)
local outputter = function(labels, value)
if not (omit_zero_values and tonumber(value) == 0) then
print_metric(name, labels, value)
end
end
if value then
outputter(labels, value)
end
@ -80,7 +86,7 @@ end
-- Web server-specific functions
function handle_request(env)
if env.PATH_INFO ~= '/metrics' then
if env.PATH_INFO ~= "/metrics" then
uhttpd.send("Status: 404 Not Found\r\n")
uhttpd.send("Server: lua-metrics\r\n")
uhttpd.send("Content-Type: text/plain\r\n\r\n")
@ -107,12 +113,14 @@ col_names = {}
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_mods[c] = require("prometheus-collectors." .. c)
col_names[#col_names + 1] = c
end
ls_fd:close()
output = function (str) uhttpd.send(str.."\n") end
output = function(str)
uhttpd.send(str .. "\n")
end
if arg ~= nil then
output = print