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>
This commit is contained in:
Etienne Champetier 2017-12-08 19:03:36 -08:00
parent c79e75d0c1
commit 58c136a521

View file

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