diff options
| author | Alex Tomlins <alex@tomlins.org.uk> | 2019-04-03 21:08:11 +0100 |
|---|---|---|
| committer | Alex Tomlins <alex@tomlins.org.uk> | 2019-04-03 21:08:11 +0100 |
| commit | 0100a2cb26c30ee091a259625b9496dd7805aaaa (patch) | |
| tree | 19ddd8a6a16a9cfc8163283b5feba8b3b1fb54e2 /utils/prometheus-node-exporter-lua/files | |
| parent | bf3bb52c3f05fe5786f5cbb62f664580990c8927 (diff) | |
prometheus-node-exporter-lua: fix missing conntrack values
If the /proc/sys/net/netfilter/nc_conntrack_* files are not present,
this exporter was outputting a blank value, which is invalid. These
files will not be present when using an image that doesn't include the
iptables and firewall packages (eg a minimal access-point type image).
This updates the collector to only output the metrics if the
corresponding /proc files are present.
Signed-off-by: Alex Tomlins <alex@tomlins.org.uk>
Diffstat (limited to 'utils/prometheus-node-exporter-lua/files')
| -rw-r--r-- | utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/conntrack.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/conntrack.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/conntrack.lua index 93b26c266..1abb7a191 100644 --- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/conntrack.lua +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/conntrack.lua @@ -1,8 +1,12 @@ local function scrape() - metric("node_nf_conntrack_entries", "gauge", nil, - string.sub(get_contents("/proc/sys/net/netfilter/nf_conntrack_count"), 1, -2)) - metric("node_nf_conntrack_entries_limit", "gauge", nil, - string.sub(get_contents("/proc/sys/net/netfilter/nf_conntrack_max"), 1, -2)) + local count = get_contents("/proc/sys/net/netfilter/nf_conntrack_count") + local max = get_contents("/proc/sys/net/netfilter/nf_conntrack_max") + if count ~= "" then + metric("node_nf_conntrack_entries", "gauge", nil, string.sub(count, 1, -2)) + end + if max ~= "" then + metric("node_nf_conntrack_entries_limit", "gauge", nil, string.sub(max, 1, -2)) + end end return { scrape = scrape } |
