aboutsummaryrefslogtreecommitdiff
path: root/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netstat.lua
blob: d30a14cdb2e551c8a00fde2ca1447559e44f9a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local netsubstat = {
    "IcmpMsg",
    "Icmp",
    "IpExt",
    "Ip",
    "TcpExt",
    "Tcp",
    "UdpLite",
    "Udp"
}

local function scrape()
  local netstat = get_contents("/proc/net/netstat") .. get_contents("/proc/net/snmp")

  -- all devices
  for i, nss in ipairs(netsubstat) do
    local substat_s = string.match(netstat, nss .. ": ([A-Z][A-Za-z0-9 ]+)")
    if substat_s then
      local substat = space_split(substat_s)
      local substatv = space_split(string.match(netstat, nss .. ": ([0-9 -]+)"))
      for ii, ss in ipairs(substat) do
        metric("node_netstat_" .. nss .. "_" .. ss, "gauge", nil, substatv[ii])
      end
    end
  end
end

return { scrape = scrape }