Browse Source

prometheus-node-exporter-lua: put wifi collector in 2 separate packages

this allow to remove libubus-lua/libiwinfo-lua dependency from main package
this also allow to have different scrape_interval

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>

split stations

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
lilik-openwrt-22.03
Etienne Champetier 7 years ago
parent
commit
fba739d32d
3 changed files with 71 additions and 20 deletions
  1. +40
    -5
      utils/prometheus-node-exporter-lua/Makefile
  2. +0
    -15
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua
  3. +31
    -0
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi_stations.lua

+ 40
- 5
utils/prometheus-node-exporter-lua/Makefile View File

@ -12,15 +12,18 @@ PKG_LICENSE:=Apache-2.0
include $(INCLUDE_DIR)/package.mk
define Package/prometheus-node-exporter-lua
define Package/prometheus-node-exporter-lua/Default
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Provides system statistics as Prometheus scraping endpoint
DEPENDS:=+luasocket +libiwinfo-lua +libubus-lua +lua
URL:=https://github.com/rbo/openwrt_exporter
TITLE:=Prometheus node exporter
PKGARCH:=all
endef
define Package/prometheus-node-exporter-lua
$(call Package/prometheus-node-exporter-lua/Default)
DEPENDS:=+luasocket +lua
endef
define Package/prometheus-node-exporter-lua/conffiles
/etc/config/prometheus-node-exporter-lua
endef
@ -31,6 +34,18 @@ define Package/prometheus-node-exporter-lua/description
This service is a lightweight rewrite in LUA of the offical Prometheus node_exporter.
endef
define Package/prometheus-node-exporter-lua-wifi
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (wifi collector)
DEPENDS:=prometheus-node-exporter-lua +libiwinfo-lua +libubus-lua
endef
define Package/prometheus-node-exporter-lua-wifi_stations
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (wifi_stations collector)
DEPENDS:=prometheus-node-exporter-lua +libiwinfo-lua +libubus-lua
endef
Build/Compile=
define Package/prometheus-node-exporter-lua/install
@ -41,7 +56,27 @@ define Package/prometheus-node-exporter-lua/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) ./files/usr/bin/prometheus-node-exporter-lua $(1)/usr/bin/prometheus-node-exporter-lua
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/* $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/cpu.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/filefd.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/loadavg.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/meminfo.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/nat_traffic.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/netstat.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/netdev.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/time.lua $(1)/usr/lib/lua/prometheus-collectors/
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/uname.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
define Package/prometheus-node-exporter-lua-wifi/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/wifi.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
define Package/prometheus-node-exporter-lua-wifi_stations/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/wifi_stations.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
$(eval $(call BuildPackage,prometheus-node-exporter-lua))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi_stations))

+ 0
- 15
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua View File

@ -7,10 +7,6 @@ local function scrape()
local metric_wifi_network_noise = metric("wifi_network_noise","gauge")
local metric_wifi_network_signal = metric("wifi_network_signal","gauge")
local metric_wifi_station_signal = metric("wifi_station_signal","gauge")
local metric_wifi_station_tx_packets = metric("wifi_station_tx_packets","gauge")
local metric_wifi_station_rx_packets = metric("wifi_station_rx_packets","gauge")
local u = ubus.connect()
local status = u:call("network.wireless", "status", {})
@ -40,17 +36,6 @@ local function scrape()
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)
local assoclist = iw.assoclist(ifname)
for mac, station in pairs(assoclist) do
local labels = {
ifname = ifname,
mac = mac,
}
metric_wifi_station_signal(labels, station.signal)
metric_wifi_station_tx_packets(labels, station.tx_packets)
metric_wifi_station_rx_packets(labels, station.rx_packets)
end
end
end
end


+ 31
- 0
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi_stations.lua View File

@ -0,0 +1,31 @@
local ubus = require "ubus"
local iwinfo = require "iwinfo"
local function scrape()
local metric_wifi_station_signal = metric("wifi_station_signal","gauge")
local metric_wifi_station_tx_packets = metric("wifi_station_tx_packets","gauge")
local metric_wifi_station_rx_packets = metric("wifi_station_rx_packets","gauge")
local u = ubus.connect()
local status = u:call("network.wireless", "status", {})
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 assoclist = iw.assoclist(ifname)
for mac, station in pairs(assoclist) do
local labels = {
ifname = ifname,
mac = mac,
}
metric_wifi_station_signal(labels, station.signal)
metric_wifi_station_tx_packets(labels, station.tx_packets)
metric_wifi_station_rx_packets(labels, station.rx_packets)
end
end
end
end
return { scrape = scrape }

Loading…
Cancel
Save