Class: Microsandbox::Metrics

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_percentFloat (readonly)

Returns CPU usage as a percentage (0.0–100.0 * vCPUs).

Returns:

  • (Float)

    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_bytesInteger (readonly)

Returns cumulative bytes read from disk.

Returns:

  • (Integer)

    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_bytesInteger (readonly)

Returns cumulative bytes written to disk.

Returns:

  • (Integer)

    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_bytesInteger? (readonly)

Returns memory available to the guest, in bytes.

Returns:

  • (Integer, nil)

    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_bytesInteger (readonly)

Returns memory currently used, in bytes.

Returns:

  • (Integer)

    memory currently used, in bytes



12
13
14
# File 'lib/microsandbox/metrics.rb', line 12

def memory_bytes
  @memory_bytes
end

#memory_host_resident_bytesInteger? (readonly)

Returns host-resident memory for the VM, in bytes.

Returns:

  • (Integer, nil)

    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_bytesInteger (readonly)

Returns memory limit, in bytes.

Returns:

  • (Integer)

    memory limit, in bytes



18
19
20
# File 'lib/microsandbox/metrics.rb', line 18

def memory_limit_bytes
  @memory_limit_bytes
end

#net_rx_bytesInteger (readonly)

Returns cumulative bytes received over the network.

Returns:

  • (Integer)

    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_bytesInteger (readonly)

Returns cumulative bytes transmitted over the network.

Returns:

  • (Integer)

    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_secsFloat (readonly)

Returns sandbox uptime in seconds.

Returns:

  • (Float)

    sandbox uptime in seconds



28
29
30
# File 'lib/microsandbox/metrics.rb', line 28

def uptime_secs
  @uptime_secs
end

#vcpu_time_nsInteger (readonly)

Returns cumulative vCPU time in nanoseconds.

Returns:

  • (Integer)

    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

#inspectObject



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

#timestampTime

Returns when this snapshot was captured.

Returns:

  • (Time)

    when this snapshot was captured



46
47
48
# File 'lib/microsandbox/metrics.rb', line 46

def timestamp
  Time.at(@timestamp_ms / 1000.0)
end