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.

47 lines
1.4 KiB

  1. -- stat/cpu collector
  2. local function scrape()
  3. local stat = get_contents("/proc/stat")
  4. -- system boot time, seconds since epoch
  5. metric("node_boot_time_seconds", "gauge", nil,
  6. string.match(stat, "btime ([0-9]+)"))
  7. -- context switches since boot (all CPUs)
  8. metric("node_context_switches_total", "counter", nil,
  9. string.match(stat, "ctxt ([0-9]+)"))
  10. -- cpu times, per CPU, per mode
  11. local cpu_mode = {"user", "nice", "system", "idle", "iowait", "irq",
  12. "softirq", "steal", "guest", "guest_nice"}
  13. local i = 0
  14. local cpu_metric = metric("node_cpu_seconds_total", "counter")
  15. while true do
  16. local cpu = {string.match(stat,
  17. "cpu"..i.." (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+)")}
  18. if #cpu ~= 10 then
  19. break
  20. end
  21. for ii, mode in ipairs(cpu_mode) do
  22. cpu_metric({cpu="cpu"..i, mode=mode}, cpu[ii] / 100)
  23. end
  24. i = i + 1
  25. end
  26. -- interrupts served
  27. metric("node_intr_total", "counter", nil,
  28. string.match(stat, "intr ([0-9]+)"))
  29. -- processes forked
  30. metric("node_forks_total", "counter", nil,
  31. string.match(stat, "processes ([0-9]+)"))
  32. -- processes running
  33. metric("node_procs_running_total", "gauge", nil,
  34. string.match(stat, "procs_running ([0-9]+)"))
  35. -- processes blocked for I/O
  36. metric("node_procs_blocked_total", "gauge", nil,
  37. string.match(stat, "procs_blocked ([0-9]+)"))
  38. end
  39. return { scrape = scrape }