Class: Railswatch::Widgets::CPULoad
- Inherits:
-
ResourceChart
- Object
- Base
- Chart
- ResourceChart
- Railswatch::Widgets::CPULoad
- Defined in:
- lib/railswatch/widgets/resource_chart.rb
Instance Attribute Summary
Attributes inherited from ResourceChart
Attributes inherited from Chart
#description, #legend, #subtitle, #units
Attributes inherited from Base
Instance Method Summary collapse
- #format(measurement) ⇒ Object
-
#initialize(server) ⇒ CPULoad
constructor
A new instance of CPULoad.
- #measure ⇒ Object
Methods inherited from ResourceChart
Methods inherited from Chart
#data, #id, #to_partial_path, #type
Methods inherited from Base
Constructor Details
#initialize(server) ⇒ CPULoad
Returns a new instance of CPULoad.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/railswatch/widgets/resource_chart.rb', line 34 def initialize(server) super( server, key: :cpu, type: 'Percentage', subtitle: 'CPU', description: 'CPU load average (1 min), average per 1 minute', legend: 'CPU', ) end |
Instance Method Details
#format(measurement) ⇒ Object
45 46 47 |
# File 'lib/railswatch/widgets/resource_chart.rb', line 45 def format(measurement) measurement['one_min'].to_f.round(2) end |
#measure ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/railswatch/widgets/resource_chart.rb', line 49 def measure load_averages = Sys::CPU.load_avg { one_min: load_averages[0], five_min: load_averages[1], fifteen_min: load_averages[2] } rescue StandardError => e ::Rails.logger.error "Error fetching CPU usage: #{e.}" { one_min: 0.0, five_min: 0.0, fifteen_min: 0.0 } end |