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.

40 lines
1.3 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", "gauge", nil, string.match(stat, "btime ([0-9]+)"))
  6. -- context switches since boot (all CPUs)
  7. metric("node_context_switches", "counter", nil, string.match(stat, "ctxt ([0-9]+)"))
  8. -- cpu times, per CPU, per mode
  9. local cpu_mode = {"user", "nice", "system", "idle", "iowait", "irq",
  10. "softirq", "steal", "guest", "guest_nice"}
  11. local i = 0
  12. local cpu_metric = metric("node_cpu", "counter")
  13. while true do
  14. local cpu = {string.match(stat, "cpu"..i.." (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+)")}
  15. if #cpu ~= 10 then
  16. break
  17. end
  18. for ii, mode in ipairs(cpu_mode) do
  19. cpu_metric({cpu="cpu"..i, mode=mode}, cpu[ii] / 100)
  20. end
  21. i = i + 1
  22. end
  23. -- interrupts served
  24. metric("node_intr", "counter", nil, string.match(stat, "intr ([0-9]+)"))
  25. -- processes forked
  26. metric("node_forks", "counter", nil, string.match(stat, "processes ([0-9]+)"))
  27. -- processes running
  28. metric("node_procs_running", "gauge", nil, string.match(stat, "procs_running ([0-9]+)"))
  29. -- processes blocked for I/O
  30. metric("node_procs_blocked", "gauge", nil, string.match(stat, "procs_blocked ([0-9]+)"))
  31. end
  32. return { scrape = scrape }