Class: Xshellz::SandboxStats

Inherits:
Struct
  • Object
show all
Defined in:
lib/xshellz/models.rb

Overview

Live resource usage for a running sandbox (+Sandbox#stats+), mirroring the control plane's wire fields. *_allowed_* fields are the plan ceilings so used/allowed gauges need no second call.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#blk_read_mbObject

Returns the value of attribute blk_read_mb

Returns:

  • (Object)

    the current value of blk_read_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def blk_read_mb
  @blk_read_mb
end

#blk_write_mbObject

Returns the value of attribute blk_write_mb

Returns:

  • (Object)

    the current value of blk_write_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def blk_write_mb
  @blk_write_mb
end

#cpu_allowed_vcpusObject

Returns the value of attribute cpu_allowed_vcpus

Returns:

  • (Object)

    the current value of cpu_allowed_vcpus



60
61
62
# File 'lib/xshellz/models.rb', line 60

def cpu_allowed_vcpus
  @cpu_allowed_vcpus
end

#cpu_percentObject

Returns the value of attribute cpu_percent

Returns:

  • (Object)

    the current value of cpu_percent



60
61
62
# File 'lib/xshellz/models.rb', line 60

def cpu_percent
  @cpu_percent
end

#cpu_throttled_periodsObject

Returns the value of attribute cpu_throttled_periods

Returns:

  • (Object)

    the current value of cpu_throttled_periods



60
61
62
# File 'lib/xshellz/models.rb', line 60

def cpu_throttled_periods
  @cpu_throttled_periods
end

#disk_allowed_mbObject

Returns the value of attribute disk_allowed_mb

Returns:

  • (Object)

    the current value of disk_allowed_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def disk_allowed_mb
  @disk_allowed_mb
end

#disk_used_mbObject

Returns the value of attribute disk_used_mb

Returns:

  • (Object)

    the current value of disk_used_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def disk_used_mb
  @disk_used_mb
end

#mem_allowed_mbObject

Returns the value of attribute mem_allowed_mb

Returns:

  • (Object)

    the current value of mem_allowed_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def mem_allowed_mb
  @mem_allowed_mb
end

#mem_limit_mbObject

Returns the value of attribute mem_limit_mb

Returns:

  • (Object)

    the current value of mem_limit_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def mem_limit_mb
  @mem_limit_mb
end

#mem_used_mbObject

Returns the value of attribute mem_used_mb

Returns:

  • (Object)

    the current value of mem_used_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def mem_used_mb
  @mem_used_mb
end

#net_rx_mbObject

Returns the value of attribute net_rx_mb

Returns:

  • (Object)

    the current value of net_rx_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def net_rx_mb
  @net_rx_mb
end

#net_tx_mbObject

Returns the value of attribute net_tx_mb

Returns:

  • (Object)

    the current value of net_tx_mb



60
61
62
# File 'lib/xshellz/models.rb', line 60

def net_tx_mb
  @net_tx_mb
end

#pids_allowedObject

Returns the value of attribute pids_allowed

Returns:

  • (Object)

    the current value of pids_allowed



60
61
62
# File 'lib/xshellz/models.rb', line 60

def pids_allowed
  @pids_allowed
end

#pids_currentObject

Returns the value of attribute pids_current

Returns:

  • (Object)

    the current value of pids_current



60
61
62
# File 'lib/xshellz/models.rb', line 60

def pids_current
  @pids_current
end

Class Method Details

.from_api(payload) ⇒ Object

Build a SandboxStats from the API's JSON payload (tolerant of missing keys).



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/xshellz/models.rb', line 79

def self.from_api(payload)
  payload ||= {}
  new(
    mem_used_mb: (payload["mem_used_mb"] || 0).to_i,
    mem_limit_mb: (payload["mem_limit_mb"] || 0).to_i,
    mem_allowed_mb: (payload["mem_allowed_mb"] || 0).to_i,
    cpu_percent: (payload["cpu_percent"] || 0.0).to_f,
    cpu_allowed_vcpus: (payload["cpu_allowed_vcpus"] || 0.0).to_f,
    cpu_throttled_periods: (payload["cpu_throttled_periods"] || 0).to_i,
    pids_current: (payload["pids_current"] || 0).to_i,
    pids_allowed: (payload["pids_allowed"] || 0).to_i,
    disk_used_mb: (payload["disk_used_mb"] || 0).to_i,
    disk_allowed_mb: (payload["disk_allowed_mb"] || 0).to_i,
    net_rx_mb: (payload["net_rx_mb"] || 0).to_i,
    net_tx_mb: (payload["net_tx_mb"] || 0).to_i,
    blk_read_mb: (payload["blk_read_mb"] || 0).to_i,
    blk_write_mb: (payload["blk_write_mb"] || 0).to_i
  )
end