Class: CpuInspectCore::Collectors::MacosCollector
- Inherits:
-
CpuInspectCore::Collector
- Object
- CpuInspectCore::Collector
- CpuInspectCore::Collectors::MacosCollector
- Defined in:
- lib/cpu_inspect_core/collectors/macos_collector.rb
Overview
macOS fallback — reports aggregate CPU only (no per-core breakdown without root access). Suitable for local development. Uses ‘top -l 2 -n 0`: the second iteration gives a live rate rather than a since-boot average.
Constant Summary collapse
- CPU_LINE_RE =
/CPU usage:\s+([\d.]+)%\s+user,\s+([\d.]+)%\s+sys/
Instance Method Summary collapse
Instance Method Details
#available? ⇒ Boolean
14 15 16 |
# File 'lib/cpu_inspect_core/collectors/macos_collector.rb', line 14 def available? platform.include?('darwin') end |
#sample ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/cpu_inspect_core/collectors/macos_collector.rb', line 18 def sample raw = `top -l 2 -n 0 2>/dev/null` lines = raw.lines.grep(CPU_LINE_RE) return {} if lines.empty? match = lines.last.match(CPU_LINE_RE) { 'cpu' => (match[1].to_f + match[2].to_f).round(1) } end |