1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
local cjson = require "cjson"
local function scrape()
local file, output, data
file = io.popen("mmcli -L -J", 'r')
if not file then return end
output = file:read('*all')
file:close()
local ok, modem_list = pcall(cjson.decode, output)
if not ok or not modem_list["modem-list"] then return end
for _, modem in ipairs(modem_list["modem-list"]) do
file = io.popen("mmcli -m " .. modem .. " -J", 'r')
if file then
output = file:read('*all')
file:close()
ok, data = pcall(cjson.decode, output)
if ok and data["modem"] then
local quality = data["modem"]["generic"]["signal-quality"]["value"]
metric("modemmanager_signal_quality", "gauge", {modem=modem}, tonumber(quality))
end
end
file = io.popen("mmcli -m " .. modem .. " --signal-get -J", 'r')
if file then
output = file:read('*all')
file:close()
ok, data = pcall(cjson.decode, output)
if ok and data["modem"] and data["modem"]["signal"] then
for tech, values in pairs(data["modem"]["signal"]) do
for metric_name, value in pairs(values) do
local num = tonumber(value)
if num then
metric("modemmanager_signal_" .. tech .. "_" .. metric_name, "gauge", {modem=modem}, num)
end
end
end
end
end
end
end
return { scrape = scrape }
|