Module: Pvectl::Presenters::TopPresenter
- Included in:
- TopContainer, TopNode, TopVm
- Defined in:
- lib/pvectl/presenters/top_presenter.rb
Overview
Shared metrics formatting for top command presenters.
Provides common display methods for CPU cores, CPU usage percentage, and generic percentage calculations used across TopNode, TopVm, and TopContainer presenters.
Instance Method Summary collapse
-
#cpu_cores_value(resource) ⇒ String
Returns CPU core count for display.
-
#cpu_usage_value(resource) ⇒ String
Returns CPU usage as percentage string.
-
#percent_display(used, total) ⇒ String
Returns percentage display string from used/total values.
-
#percent_value(used, total) ⇒ Integer?
Calculates percentage as integer from used/total values.
Instance Method Details
#cpu_cores_value(resource) ⇒ String
Returns CPU core count for display.
21 22 23 24 25 |
# File 'lib/pvectl/presenters/top_presenter.rb', line 21 def cpu_cores_value(resource) return "-" if resource.maxcpu.nil? resource.maxcpu.to_s end |
#cpu_usage_value(resource) ⇒ String
Returns CPU usage as percentage string.
31 32 33 34 35 |
# File 'lib/pvectl/presenters/top_presenter.rb', line 31 def cpu_usage_value(resource) return "-" if resource.cpu.nil? "#{(resource.cpu * 100).round}%" end |
#percent_display(used, total) ⇒ String
Returns percentage display string from used/total values.
42 43 44 45 |
# File 'lib/pvectl/presenters/top_presenter.rb', line 42 def percent_display(used, total) pct = percent_value(used, total) pct ? "#{pct}%" : "-" end |
#percent_value(used, total) ⇒ Integer?
Calculates percentage as integer from used/total values.
52 53 54 55 56 |
# File 'lib/pvectl/presenters/top_presenter.rb', line 52 def percent_value(used, total) return nil if used.nil? || total.nil? || total.zero? ((used.to_f / total) * 100).round end |