From 509f208ee76393c4db1ac3aec39a908effcdd11b Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Mon, 30 Apr 2018 00:59:46 +0900 Subject: [PATCH] prometheus-node-exporter-lua: export static files Print all files from /var/prometheus/*.prom. This behaviour allow users to add metrics with non-lua scripts. Signed-off-by: Paul Spooren --- utils/prometheus-node-exporter-lua/Makefile | 14 +++++++++++++- .../usr/lib/lua/prometheus-collectors/textfile.lua | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/textfile.lua diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index 83b5e47fe..ef2cd13ec 100644 --- a/utils/prometheus-node-exporter-lua/Makefile +++ b/utils/prometheus-node-exporter-lua/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=prometheus-node-exporter-lua PKG_VERSION:=2017.12.08 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_MAINTAINER:=Christian Simon PKG_LICENSE:=Apache-2.0 @@ -70,6 +70,12 @@ define Package/prometheus-node-exporter-lua-bmx7 DEPENDS:=prometheus-node-exporter-lua bmx7 +lua-cjson +bmx7-json endef +define Package/prometheus-node-exporter-lua-textfile + $(call Package/prometheus-node-exporter-lua/Default) + TITLE+= (textfile collector) + DEPENDS:=prometheus-node-exporter-lua +luci-lib-nixio +endef + Build/Compile= define Package/prometheus-node-exporter-lua/install @@ -119,6 +125,11 @@ define Package/prometheus-node-exporter-lua-bmx7/install $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/bmx7.lua $(1)/usr/lib/lua/prometheus-collectors/ endef +define Package/prometheus-node-exporter-lua-textfile/install + $(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors + $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/textfile.lua $(1)/usr/lib/lua/prometheus-collectors/ +endef + $(eval $(call BuildPackage,prometheus-node-exporter-lua)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-nat_traffic)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-netstat)) @@ -126,3 +137,4 @@ $(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi)) $(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)) +$(eval $(call BuildPackage,prometheus-node-exporter-lua-textfile)) diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/textfile.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/textfile.lua new file mode 100644 index 000000000..118177f49 --- /dev/null +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/textfile.lua @@ -0,0 +1,11 @@ +#!/usr/bin/lua + +local fs = require "nixio.fs" + +local function scrape() + for metrics in fs.glob("/var/prometheus/*.prom") do + output(get_contents(metrics), '\n') + end +end + +return { scrape = scrape }