Class: Atatus::Metrics::CpuMemSet::Linux::ProcStat Private
- Inherits:
-
Object
- Object
- Atatus::Metrics::CpuMemSet::Linux::ProcStat
- Defined in:
- lib/atatus/metrics/cpu_mem_set.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- CPU_FIELDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[ user nice system idle iowait irq softirq steal guest guest_nice ].freeze
Instance Attribute Summary collapse
- #total ⇒ Object readonly private
- #usage ⇒ Object readonly private
Instance Method Summary collapse
- #read! ⇒ Object private
Instance Attribute Details
#total ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
149 150 151 |
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 149 def total @total end |
#usage ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
149 150 151 |
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 149 def usage @usage end |
Instance Method Details
#read! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 163 def read! stat = IO.readlines('/proc/stat') .lazy .find { |sp| sp.start_with?('cpu ') } .split .map(&:to_i)[1..-1] values = CPU_FIELDS.each_with_index.each_with_object({}) do |(key, i), v| v[key] = stat[i] || 0 end @total = values[:user] + values[:nice] + values[:system] + values[:idle] + values[:iowait] + values[:irq] + values[:softirq] + values[:steal] @usage = @total - (values[:idle] + values[:iowait]) self end |