Browse Source

prometheus-node-exporter-lua: improve node_uname_info

Testing on a bullet m2, uname collector was taking on average 0.12
it now takes 0.0007

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
lilik-openwrt-22.03
Etienne Champetier 7 years ago
parent
commit
58c136a521
1 changed files with 12 additions and 13 deletions
  1. +12
    -13
      utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua

+ 12
- 13
utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua View File

@ -248,20 +248,19 @@ function scraper_time()
metric("node_time", "counter", nil, os.time())
end
uname_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)
}
function scraper_uname()
-- version can have spaces, so grab it directly
local version = string.sub(io.popen("uname -v"):read("*a"), 1, -2)
-- avoid individual popen calls for the rest of the values
local uname_string = io.popen("uname -a"):read("*a")
local sysname, nodename, release = unpack(space_split(uname_string))
local labels = {domainname = "(none)", nodename = nodename, release = release,
sysname = sysname, version = version}
-- The machine hardware name is immediately after the version string, so add
-- up the values we know and add in the 4 spaces to find the offset...
machine_offset = string.len(sysname .. nodename .. release .. version) + 4
labels['machine'] = string.match(string.sub(uname_string, machine_offset), "(%S+)" )
metric("node_uname_info", "gauge", labels, 1)
uname_labels["domainname"] = string.sub(get_contents("/proc/sys/kernel/domainname"), 1, -2)
uname_labels["nodename"] = string.sub(get_contents("/proc/sys/kernel/hostname"), 1, -2)
metric("node_uname_info", "gauge", uname_labels, 1)
end
function scraper_nat()


Loading…
Cancel
Save