You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB

  1. local function scrape()
  2. -- documetation about nf_conntrack:
  3. -- https://www.frozentux.net/iptables-tutorial/chunkyhtml/x1309.html
  4. nat_metric = metric("node_nat_traffic", "gauge" )
  5. for e in io.lines("/proc/net/nf_conntrack") do
  6. -- output(string.format("%s\n",e ))
  7. local fields = space_split(e)
  8. local src, dest, bytes;
  9. bytes = 0;
  10. for _, field in ipairs(fields) do
  11. if src == nil and string.match(field, '^src') then
  12. src = string.match(field,"src=([^ ]+)");
  13. elseif dest == nil and string.match(field, '^dst') then
  14. dest = string.match(field,"dst=([^ ]+)");
  15. elseif string.match(field, '^bytes') then
  16. local b = string.match(field, "bytes=([^ ]+)");
  17. bytes = bytes + b;
  18. -- output(string.format("\t%d %s",ii,field ));
  19. end
  20. end
  21. -- local src, dest, bytes = string.match(natstat[i], "src=([^ ]+) dst=([^ ]+) .- bytes=([^ ]+)");
  22. -- local src, dest, bytes = string.match(natstat[i], "src=([^ ]+) dst=([^ ]+) sport=[^ ]+ dport=[^ ]+ packets=[^ ]+ bytes=([^ ]+)")
  23. local labels = { src = src, dest = dest }
  24. -- output(string.format("src=|%s| dest=|%s| bytes=|%s|", src, dest, bytes ))
  25. nat_metric(labels, bytes )
  26. end
  27. end
  28. return { scrape = scrape }