prometheus-node-exporter-lua: an unavaliable wifi interface may have stopped the...
authorZoltan Haindrich <redacted>
Fri, 4 Oct 2019 15:43:50 +0000 (15:43 +0000)
committerEtienne Champetier <redacted>
Mon, 18 Nov 2019 02:16:48 +0000 (18:16 -0800)
Signed-off-by: Zoltan Haindrich <redacted>
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi_stations.lua

index da36db9733e1e7fab976d3ccfc6935da3d2befe5..05b0ba1fc9056030b41b17573637feec4c56448f 100644 (file)
@@ -13,29 +13,31 @@ local function scrape()
   for dev, dev_table in pairs(status) do
     for _, intf in ipairs(dev_table['interfaces']) do
       local ifname = intf['ifname']
-      local iw = iwinfo[iwinfo.type(ifname)]
-      local labels = {
-        channel = iw.channel(ifname),
-        ssid = iw.ssid(ifname),
-        bssid = iw.bssid(ifname),
-        mode = iw.mode(ifname),
-        ifname = ifname,
-        country = iw.country(ifname),
-        frequency = iw.frequency(ifname),
-        device = dev,
-      }
+      if ifname ~= nil then
+        local iw = iwinfo[iwinfo.type(ifname)]
+        local labels = {
+          channel = iw.channel(ifname),
+          ssid = iw.ssid(ifname),
+          bssid = iw.bssid(ifname),
+          mode = iw.mode(ifname),
+          ifname = ifname,
+          country = iw.country(ifname),
+          frequency = iw.frequency(ifname),
+          device = dev,
+        }
 
-      local qc = iw.quality(ifname) or 0
-      local qm = iw.quality_max(ifname) or 0
-      local quality = 0
-      if qc > 0 and qm > 0 then
-        quality = math.floor((100 / qm) * qc)
-      end
+        local qc = iw.quality(ifname) or 0
+        local qm = iw.quality_max(ifname) or 0
+        local quality = 0
+        if qc > 0 and qm > 0 then
+          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)
+        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
index f241e414f0e1d79bda4126a5c4bb41e928f13912..c632f94d118269c819d534f4a58ec3d8ed82de92 100644 (file)
@@ -26,42 +26,44 @@ local function scrape()
   for dev, dev_table in pairs(status) do
     for _, intf in ipairs(dev_table['interfaces']) do
       local ifname = intf['ifname']
-      local iw = iwinfo[iwinfo.type(ifname)]
-      local count = 0
+      if ifname ~= nil then
+        local iw = iwinfo[iwinfo.type(ifname)]
+        local count = 0
 
-      local assoclist = iw.assoclist(ifname)
-      for mac, station in pairs(assoclist) do
-        local labels = {
-          ifname = ifname,
-          mac = mac,
-        }
-        if station.signal and station.signal ~= 0 then
-          metric_wifi_station_signal(labels, station.signal)
-        end
-        if station.inactive then
-          metric_wifi_station_inactive(labels, station.inactive)
-        end
-        if station.expected_throughput and station.expected_throughput ~= 0 then
-          metric_wifi_station_exp_thr(labels, station.expected_throughput)
-        end
-        if station.tx_rate and station.tx_rate ~= 0 then
-          metric_wifi_station_tx_bitrate(labels, station.tx_rate)
-        end
-        if station.rx_rate and station.rx_rate ~= 0 then
-          metric_wifi_station_rx_bitrate(labels, station.rx_rate)
-        end
-        metric_wifi_station_tx_packets(labels, station.tx_packets)
-        metric_wifi_station_rx_packets(labels, station.rx_packets)
-        if station.tx_bytes then
-          metric_wifi_station_tx_bytes(labels, station.tx_bytes)
-        end
-        if station.rx_bytes then
-          metric_wifi_station_rx_bytes(labels, station.rx_bytes)
-        end
+        local assoclist = iw.assoclist(ifname)
+        for mac, station in pairs(assoclist) do
+          local labels = {
+            ifname = ifname,
+            mac = mac,
+          }
+          if station.signal and station.signal ~= 0 then
+            metric_wifi_station_signal(labels, station.signal)
+          end
+          if station.inactive then
+            metric_wifi_station_inactive(labels, station.inactive)
+          end
+          if station.expected_throughput and station.expected_throughput ~= 0 then
+            metric_wifi_station_exp_thr(labels, station.expected_throughput)
+          end
+          if station.tx_rate and station.tx_rate ~= 0 then
+            metric_wifi_station_tx_bitrate(labels, station.tx_rate)
+          end
+          if station.rx_rate and station.rx_rate ~= 0 then
+            metric_wifi_station_rx_bitrate(labels, station.rx_rate)
+          end
+          metric_wifi_station_tx_packets(labels, station.tx_packets)
+          metric_wifi_station_rx_packets(labels, station.rx_packets)
+          if station.tx_bytes then
+            metric_wifi_station_tx_bytes(labels, station.tx_bytes)
+          end
+          if station.rx_bytes then
+            metric_wifi_station_rx_bytes(labels, station.rx_bytes)
+          end
 
-        count = count + 1
+          count = count + 1
+        end
+        metric_wifi_stations({ifname = ifname}, count)
       end
-      metric_wifi_stations({ifname = ifname}, count)
     end
   end
 end
git clone https://git.99rst.org/PROJECT