Class: Pvectl::Presenters::TopNode
- Includes:
- TopPresenter
- Defined in:
- lib/pvectl/presenters/top_node.rb
Overview
Presenter for node resource usage metrics (top command).
Inherits from Presenters::Node for reuse of formatting methods. Focuses on CPU, memory, disk, and swap utilization rather than operational details (version, kernel, services).
Instance Method Summary collapse
-
#columns ⇒ Array<String>
Returns column headers for standard table output.
-
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
-
#extra_values(model, **_context) ⇒ Array<String>
Returns additional values for wide output.
-
#to_hash(model) ⇒ Hash
Converts Node model to hash for JSON/YAML output.
-
#to_row(model, **_context) ⇒ Array<String>
Converts Node model to table row with metrics values.
Methods included from TopPresenter
#cpu_cores_value, #cpu_usage_value, #percent_display, #percent_value
Methods inherited from Node
#alerts, #alerts_display, #boot_mode, #cpu_cores, #cpu_model, #cpu_percent, #cpu_sockets, #disk_total_gb, #disk_used_gb, #dns_nameservers, #dns_search, #has_alerts?, #ip_display, #kernel_display, #load_1m, #load_display, #local_time, #memory_display, #memory_total_gb, #memory_used_gb, #rootfs_display, #rootfs_usage_percent, #storage_display, #subscription_display, #swap_display, #swap_total_gb, #swap_used_gb, #timezone, #to_description, #uptime_human, #version_display
Methods inherited from Base
#tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns
Instance Method Details
#columns ⇒ Array<String>
Returns column headers for standard table output.
25 26 27 |
# File 'lib/pvectl/presenters/top_node.rb', line 25 def columns %w[NAME CPU(cores) CPU% MEMORY MEMORY%] end |
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
32 33 34 |
# File 'lib/pvectl/presenters/top_node.rb', line 32 def extra_columns %w[DISK DISK% SWAP SWAP% LOAD GUESTS] end |
#extra_values(model, **_context) ⇒ Array<String>
Returns additional values for wide output.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pvectl/presenters/top_node.rb', line 58 def extra_values(model, **_context) @node = model [ storage_display, percent_display(node.disk, node.maxdisk), swap_display, swap_percent_display(node), load_display, node.guests_total.to_s ] end |
#to_hash(model) ⇒ Hash
Converts Node model to hash for JSON/YAML output.
Returns metrics-focused hash without operational info (no version, kernel, uptime, alerts, network).
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pvectl/presenters/top_node.rb', line 77 def to_hash(model) @node = model { "name" => node.name, "cpu" => { "usage_percent" => node.cpu.nil? ? nil : (node.cpu * 100).round, "cores" => node.maxcpu }, "memory" => { "used_bytes" => node.mem, "total_bytes" => node.maxmem, "usage_percent" => memory_percent(node) }, "disk" => { "used_bytes" => node.disk, "total_bytes" => node.maxdisk, "usage_percent" => storage_percent(node) }, "swap" => { "used_bytes" => node.swap_used, "total_bytes" => node.swap_total, "usage_percent" => swap_percent(node) }, "load" => { "avg1" => node.loadavg&.dig(0), "avg5" => node.loadavg&.dig(1), "avg15" => node.loadavg&.dig(2) }, "guests" => { "total" => node.guests_total, "vms" => node.guests_vms, "cts" => node.guests_cts } } end |
#to_row(model, **_context) ⇒ Array<String>
Converts Node model to table row with metrics values.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pvectl/presenters/top_node.rb', line 41 def to_row(model, **_context) @node = model cores = node.offline? ? "-" : cpu_cores_value(node) [ node.name, cores, cpu_percent, memory_display, memory_percent_display(node) ] end |