Browse Source

prometheus-node-exporter-lua: rework cpu collector

replace 2 string.match and 1 string.gmatch (space_split)
by 1 string.match

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
lilik-openwrt-22.03
Etienne Champetier 7 years ago
parent
commit
ea5b7492fe
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/cpu.lua

+ 6
- 5
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/cpu.lua View File

@ -13,12 +13,13 @@ local function scrape()
"softirq", "steal", "guest", "guest_nice"}
local i = 0
local cpu_metric = metric("node_cpu", "counter")
while string.match(stat, string.format("cpu%d ", i)) do
local cpu = space_split(string.match(stat, string.format("cpu%d ([0-9 ]+)", i)))
local labels = {cpu = "cpu" .. i}
while true do
local cpu = {string.match(stat, "cpu"..i.." (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+)")}
if #cpu ~= 10 then
break
end
for ii, mode in ipairs(cpu_mode) do
labels['mode'] = mode
cpu_metric(labels, cpu[ii] / 100)
cpu_metric({cpu="cpu"..i, mode=mode}, cpu[ii] / 100)
end
i = i + 1
end


Loading…
Cancel
Save