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.

39 lines
1.0 KiB

  1. local netdevsubstat = {
  2. "receive_bytes_total",
  3. "receive_packets_total",
  4. "receive_errs_total",
  5. "receive_drop_total",
  6. "receive_fifo_total",
  7. "receive_frame_total",
  8. "receive_compressed_total",
  9. "receive_multicast_total",
  10. "transmit_bytes_total",
  11. "transmit_packets_total",
  12. "transmit_errs_total",
  13. "transmit_drop_total",
  14. "transmit_fifo_total",
  15. "transmit_colls_total",
  16. "transmit_carrier_total",
  17. "transmit_compressed_total"
  18. }
  19. local pattern = "([^%s:]+):%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)"
  20. local function scrape()
  21. local nds_table = {}
  22. for line in io.lines("/proc/net/dev") do
  23. local t = {string.match(line, pattern)}
  24. if #t == 17 then
  25. nds_table[t[1]] = t
  26. end
  27. end
  28. for i, ndss in ipairs(netdevsubstat) do
  29. netdev_metric = metric("node_network_" .. ndss, "gauge")
  30. for dev, nds_dev in pairs(nds_table) do
  31. netdev_metric({device=dev}, nds_dev[i+1])
  32. end
  33. end
  34. end
  35. return { scrape = scrape }