Browse Source

Merge pull request #14158 from PolynomialDivision/snmpv6-collector

prometheus-node-exporter-lua: add snmp6 exporter
lilik-openwrt-22.03
Rosen Penev 4 years ago
committed by GitHub
parent
commit
680b76de07
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions
  1. +13
    -1
      utils/prometheus-node-exporter-lua/Makefile
  2. +39
    -0
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/snmp6.lua

+ 13
- 1
utils/prometheus-node-exporter-lua/Makefile View File

@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=prometheus-node-exporter-lua PKG_NAME:=prometheus-node-exporter-lua
PKG_VERSION:=2020.10.29
PKG_VERSION:=2020.12.07
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com> PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com>
@ -199,6 +199,17 @@ define Package/prometheus-node-exporter-lua-wifi_stations/install
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/wifi_stations.lua $(1)/usr/lib/lua/prometheus-collectors/ $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/wifi_stations.lua $(1)/usr/lib/lua/prometheus-collectors/
endef endef
define Package/prometheus-node-exporter-lua-snmp6
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (snmp6 collector)
DEPENDS:=prometheus-node-exporter-lua +libubus-lua
endef
define Package/prometheus-node-exporter-lua-snmp6/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/snmp6.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
$(eval $(call BuildPackage,prometheus-node-exporter-lua)) $(eval $(call BuildPackage,prometheus-node-exporter-lua))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx6)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx6))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx7)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx7))
@ -213,3 +224,4 @@ $(eval $(call BuildPackage,prometheus-node-exporter-lua-textfile))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-uci_dhcp_host)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-uci_dhcp_host))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi_stations)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi_stations))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-snmp6))

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

@ -0,0 +1,39 @@
local ubus = require "ubus"
local function get_devices() -- based on hostapd_stations.lua
local u = ubus.connect()
local status = u:call("network.device", "status", {})
local devices = {}
for dev, dev_table in pairs(status) do
table.insert(devices, dev)
end
return devices
end
local function get_metric(device)
local label = {
device = device
}
if device == "all" then
for e in io.lines("/proc/net/snmp6") do
local snmp6 = space_split(e)
metric("snmp6_" .. snmp6[1], "counter", label, tonumber(snmp6[2]))
end
else
for e in io.lines("/proc/net/dev_snmp6/" .. device) do
local snmp6 = space_split(e)
metric("snmp6_" .. snmp6[1], "counter", label, tonumber(snmp6[2]))
end
end
end
local function scrape()
get_metric("all")
for _, devicename in ipairs(get_devices()) do
get_metric(devicename)
end
end
return { scrape = scrape }

Loading…
Cancel
Save