Browse Source

Merge pull request #5578 from aparcar/bmx6-exporter

prometheus-node-exporter-lua: add bmx6/7 scraper
lilik-openwrt-22.03
champtar 7 years ago
committed by GitHub
parent
commit
8068fd5192
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 0 deletions
  1. +24
    -0
      utils/prometheus-node-exporter-lua/Makefile
  2. +39
    -0
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/bmx6.lua
  3. +45
    -0
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/bmx7.lua

+ 24
- 0
utils/prometheus-node-exporter-lua/Makefile View File

@ -58,6 +58,18 @@ define Package/prometheus-node-exporter-lua-wifi_stations
DEPENDS:=prometheus-node-exporter-lua +libiwinfo-lua +libubus-lua DEPENDS:=prometheus-node-exporter-lua +libiwinfo-lua +libubus-lua
endef endef
define Package/prometheus-node-exporter-lua-bmx6
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (bmx6 links collector)
DEPENDS:=prometheus-node-exporter-lua bmx6 +lua-cjson +bmx6-json
endef
define Package/prometheus-node-exporter-lua-bmx7
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (bmx7 links collector)
DEPENDS:=prometheus-node-exporter-lua bmx7 +lua-cjson +bmx7-json
endef
Build/Compile= Build/Compile=
define Package/prometheus-node-exporter-lua/install define Package/prometheus-node-exporter-lua/install
@ -97,8 +109,20 @@ 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-bmx6/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/bmx6.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
define Package/prometheus-node-exporter-lua-bmx7/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/bmx7.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-nat_traffic)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-nat_traffic))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-netstat)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-netstat))
$(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-bmx6))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx7))

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

@ -0,0 +1,39 @@
#!/usr/bin/lua
local json = require "cjson"
local function interpret_suffix(rate)
local value = string.sub(rate, 1, -2)
local suffix = string.sub(rate, -1)
if suffix == "K" then return tonumber(value) * 10^3 end
if suffix == "M" then return tonumber(value) * 10^6 end
if suffix == "G" then return tonumber(value) * 10^9 end
return rate
end
local function scrape()
local status = json.decode(get_contents("/var/run/bmx6/json/status")).status
local labels = {
version = status.version,
id = status.name,
address = status.primaryIp
}
metric("bmx6_status", "gauge", labels, 1)
local links = json.decode(get_contents("/var/run/bmx6/json/links")).links
local metric_bmx6_rxRate = metric("bmx6_link_rxRate","gauge")
local metric_bmx6_txRate = metric("bmx6_link_txRate","gauge")
for _, link in pairs(links) do
local labels = {
source = status.name,
target = link.name,
dev = link.viaDev
}
metric_bmx6_rxRate(labels, interpret_suffix(link.rxRate))
metric_bmx6_txRate(labels, interpret_suffix(link.txRate))
end
end
return { scrape = scrape }

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

@ -0,0 +1,45 @@
#!/usr/bin/lua
local json = require "cjson"
local function interpret_suffix(rate)
if rate ~= nil then
local value = string.sub(rate, 1, -2)
local suffix = string.sub(rate, -1)
if suffix == "K" then return tonumber(value) * 10^3 end
if suffix == "M" then return tonumber(value) * 10^6 end
if suffix == "G" then return tonumber(value) * 10^9 end
end
return rate
end
local function scrape()
local status = json.decode(get_contents("/var/run/bmx7/json/status")).status
local labels = {
id = status.shortId,
name = status.name,
address = status.primaryIp,
revision = status.revision,
}
metric("bmx7_status", "gauge", labels, 1)
metric("bmx7_cpu_usage", "gauge", nil, status.cpu)
metric("bmx7_mem_usage", "gauge", nil, interpret_suffix(status.mem))
local links = json.decode(get_contents("/var/run/bmx7/json/links")).links
local metric_bmx7_rxRate = metric("bmx7_link_rxRate","gauge")
local metric_bmx7_txRate = metric("bmx7_link_txRate","gauge")
for _, link in pairs(links) do
local labels = {
source = status.shortId,
target = link.shortId,
name = link.name,
dev = link.dev
}
metric_bmx7_rxRate(labels, interpret_suffix(link.rxRate))
metric_bmx7_txRate(labels, interpret_suffix(link.txRate))
end
end
return { scrape = scrape }

Loading…
Cancel
Save