prometheus-node-exporter-lua: an unavaliable wifi interface may have stopped the scraper from functioning

Signed-off-by: Zoltan Haindrich <kirk@rxd.hu>
(cherry picked from commit 7bec619f53)
This commit is contained in:
Zoltan Haindrich 2019-10-04 15:43:50 +00:00 committed by Etienne Champetier
parent 0e69b14733
commit 928915f4a6
2 changed files with 58 additions and 54 deletions

View file

@ -13,29 +13,31 @@ local function scrape()
for dev, dev_table in pairs(status) do for dev, dev_table in pairs(status) do
for _, intf in ipairs(dev_table['interfaces']) do for _, intf in ipairs(dev_table['interfaces']) do
local ifname = intf['ifname'] local ifname = intf['ifname']
local iw = iwinfo[iwinfo.type(ifname)] if ifname ~= nil then
local labels = { local iw = iwinfo[iwinfo.type(ifname)]
channel = iw.channel(ifname), local labels = {
ssid = iw.ssid(ifname), channel = iw.channel(ifname),
bssid = iw.bssid(ifname), ssid = iw.ssid(ifname),
mode = iw.mode(ifname), bssid = iw.bssid(ifname),
ifname = ifname, mode = iw.mode(ifname),
country = iw.country(ifname), ifname = ifname,
frequency = iw.frequency(ifname), country = iw.country(ifname),
device = dev, frequency = iw.frequency(ifname),
} device = dev,
}
local qc = iw.quality(ifname) or 0 local qc = iw.quality(ifname) or 0
local qm = iw.quality_max(ifname) or 0 local qm = iw.quality_max(ifname) or 0
local quality = 0 local quality = 0
if qc > 0 and qm > 0 then if qc > 0 and qm > 0 then
quality = math.floor((100 / qm) * qc) quality = math.floor((100 / qm) * qc)
end
metric_wifi_network_quality(labels, quality)
metric_wifi_network_noise(labels, iw.noise(ifname) or 0)
metric_wifi_network_bitrate(labels, iw.bitrate(ifname) or 0)
metric_wifi_network_signal(labels, iw.signal(ifname) or -255)
end end
metric_wifi_network_quality(labels, quality)
metric_wifi_network_noise(labels, iw.noise(ifname) or 0)
metric_wifi_network_bitrate(labels, iw.bitrate(ifname) or 0)
metric_wifi_network_signal(labels, iw.signal(ifname) or -255)
end end
end end
end end

View file

@ -26,42 +26,44 @@ local function scrape()
for dev, dev_table in pairs(status) do for dev, dev_table in pairs(status) do
for _, intf in ipairs(dev_table['interfaces']) do for _, intf in ipairs(dev_table['interfaces']) do
local ifname = intf['ifname'] local ifname = intf['ifname']
local iw = iwinfo[iwinfo.type(ifname)] if ifname ~= nil then
local count = 0 local iw = iwinfo[iwinfo.type(ifname)]
local count = 0
local assoclist = iw.assoclist(ifname) local assoclist = iw.assoclist(ifname)
for mac, station in pairs(assoclist) do for mac, station in pairs(assoclist) do
local labels = { local labels = {
ifname = ifname, ifname = ifname,
mac = mac, mac = mac,
} }
if station.signal and station.signal ~= 0 then if station.signal and station.signal ~= 0 then
metric_wifi_station_signal(labels, station.signal) metric_wifi_station_signal(labels, station.signal)
end end
if station.inactive then if station.inactive then
metric_wifi_station_inactive(labels, station.inactive) metric_wifi_station_inactive(labels, station.inactive)
end end
if station.expected_throughput and station.expected_throughput ~= 0 then if station.expected_throughput and station.expected_throughput ~= 0 then
metric_wifi_station_exp_thr(labels, station.expected_throughput) metric_wifi_station_exp_thr(labels, station.expected_throughput)
end end
if station.tx_rate and station.tx_rate ~= 0 then if station.tx_rate and station.tx_rate ~= 0 then
metric_wifi_station_tx_bitrate(labels, station.tx_rate) metric_wifi_station_tx_bitrate(labels, station.tx_rate)
end end
if station.rx_rate and station.rx_rate ~= 0 then if station.rx_rate and station.rx_rate ~= 0 then
metric_wifi_station_rx_bitrate(labels, station.rx_rate) metric_wifi_station_rx_bitrate(labels, station.rx_rate)
end end
metric_wifi_station_tx_packets(labels, station.tx_packets) metric_wifi_station_tx_packets(labels, station.tx_packets)
metric_wifi_station_rx_packets(labels, station.rx_packets) metric_wifi_station_rx_packets(labels, station.rx_packets)
if station.tx_bytes then if station.tx_bytes then
metric_wifi_station_tx_bytes(labels, station.tx_bytes) metric_wifi_station_tx_bytes(labels, station.tx_bytes)
end end
if station.rx_bytes then if station.rx_bytes then
metric_wifi_station_rx_bytes(labels, station.rx_bytes) metric_wifi_station_rx_bytes(labels, station.rx_bytes)
end end
count = count + 1 count = count + 1
end
metric_wifi_stations({ifname = ifname}, count)
end end
metric_wifi_stations({ifname = ifname}, count)
end end
end end
end end