Class: Microsandbox::Metrics
- Inherits:
-
Object
- Object
- Microsandbox::Metrics
- Defined in:
- lib/microsandbox/metrics.rb
Overview
A point-in-time resource-usage snapshot for a sandbox, returned by Sandbox#metrics.
Instance Attribute Summary collapse
-
#cpu_percent ⇒ Float
readonly
CPU usage as a percentage (0.0–100.0 * vCPUs).
-
#disk_read_bytes ⇒ Integer
readonly
Cumulative bytes read from disk.
-
#disk_write_bytes ⇒ Integer
readonly
Cumulative bytes written to disk.
-
#memory_available_bytes ⇒ Integer?
readonly
Memory available to the guest, in bytes.
-
#memory_bytes ⇒ Integer
readonly
Memory currently used, in bytes.
-
#memory_host_resident_bytes ⇒ Integer?
readonly
Host-resident memory for the VM, in bytes.
-
#memory_limit_bytes ⇒ Integer
readonly
Memory limit, in bytes.
-
#net_rx_bytes ⇒ Integer
readonly
Cumulative bytes received over the network.
-
#net_tx_bytes ⇒ Integer
readonly
Cumulative bytes transmitted over the network.
-
#uptime_secs ⇒ Float
readonly
Sandbox uptime in seconds.
-
#vcpu_time_ns ⇒ Integer
readonly
Cumulative vCPU time in nanoseconds.
Instance Method Summary collapse
-
#initialize(data) ⇒ Metrics
constructor
A new instance of Metrics.
- #inspect ⇒ Object
-
#timestamp ⇒ Time
When this snapshot was captured.
Constructor Details
#initialize(data) ⇒ Metrics
Returns a new instance of Metrics.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/microsandbox/metrics.rb', line 30 def initialize(data) @cpu_percent = data["cpu_percent"] @vcpu_time_ns = data["vcpu_time_ns"] @memory_bytes = data["memory_bytes"] @memory_available_bytes = data["memory_available_bytes"] @memory_host_resident_bytes = data["memory_host_resident_bytes"] @memory_limit_bytes = data["memory_limit_bytes"] @disk_read_bytes = data["disk_read_bytes"] @disk_write_bytes = data["disk_write_bytes"] @net_rx_bytes = data["net_rx_bytes"] @net_tx_bytes = data["net_tx_bytes"] @uptime_secs = data["uptime_secs"] @timestamp_ms = data["timestamp_ms"] end |
Instance Attribute Details
#cpu_percent ⇒ Float (readonly)
Returns CPU usage as a percentage (0.0–100.0 * vCPUs).
8 9 10 |
# File 'lib/microsandbox/metrics.rb', line 8 def cpu_percent @cpu_percent end |
#disk_read_bytes ⇒ Integer (readonly)
Returns cumulative bytes read from disk.
20 21 22 |
# File 'lib/microsandbox/metrics.rb', line 20 def disk_read_bytes @disk_read_bytes end |
#disk_write_bytes ⇒ Integer (readonly)
Returns cumulative bytes written to disk.
22 23 24 |
# File 'lib/microsandbox/metrics.rb', line 22 def disk_write_bytes @disk_write_bytes end |
#memory_available_bytes ⇒ Integer? (readonly)
Returns memory available to the guest, in bytes.
14 15 16 |
# File 'lib/microsandbox/metrics.rb', line 14 def memory_available_bytes @memory_available_bytes end |
#memory_bytes ⇒ Integer (readonly)
Returns memory currently used, in bytes.
12 13 14 |
# File 'lib/microsandbox/metrics.rb', line 12 def memory_bytes @memory_bytes end |
#memory_host_resident_bytes ⇒ Integer? (readonly)
Returns host-resident memory for the VM, in bytes.
16 17 18 |
# File 'lib/microsandbox/metrics.rb', line 16 def memory_host_resident_bytes @memory_host_resident_bytes end |
#memory_limit_bytes ⇒ Integer (readonly)
Returns memory limit, in bytes.
18 19 20 |
# File 'lib/microsandbox/metrics.rb', line 18 def memory_limit_bytes @memory_limit_bytes end |
#net_rx_bytes ⇒ Integer (readonly)
Returns cumulative bytes received over the network.
24 25 26 |
# File 'lib/microsandbox/metrics.rb', line 24 def net_rx_bytes @net_rx_bytes end |
#net_tx_bytes ⇒ Integer (readonly)
Returns cumulative bytes transmitted over the network.
26 27 28 |
# File 'lib/microsandbox/metrics.rb', line 26 def net_tx_bytes @net_tx_bytes end |
#uptime_secs ⇒ Float (readonly)
Returns sandbox uptime in seconds.
28 29 30 |
# File 'lib/microsandbox/metrics.rb', line 28 def uptime_secs @uptime_secs end |
#vcpu_time_ns ⇒ Integer (readonly)
Returns cumulative vCPU time in nanoseconds.
10 11 12 |
# File 'lib/microsandbox/metrics.rb', line 10 def vcpu_time_ns @vcpu_time_ns end |
Instance Method Details
#inspect ⇒ Object
50 51 52 53 |
# File 'lib/microsandbox/metrics.rb', line 50 def inspect "#<Microsandbox::Metrics cpu=#{@cpu_percent.round(1)}% " \ "mem=#{@memory_bytes}/#{@memory_limit_bytes}B uptime=#{@uptime_secs.round(1)}s>" end |
#timestamp ⇒ Time
Returns when this snapshot was captured.
46 47 48 |
# File 'lib/microsandbox/metrics.rb', line 46 def Time.at(@timestamp_ms / 1000.0) end |