Module: Mastercontrol::Server

Defined in:
lib/mastercontrol/server.rb

Defined Under Namespace

Classes: DiskPartition, ServerHostname, ServerLoad

Class Method Summary collapse

Class Method Details

.disk_usageObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mastercontrol/server.rb', line 58

def self.disk_usage
  url = "#{Mastercontrol.base_url}/getdiskusage?api.version=1"
  response = RestClient.get url, {authorization: Mastercontrol.auth_header}

  # parse the json
  json_response = JSON.parse(response)

  return_array = []

  # loop through partitions and create/add their DiskPartion objects to the return array
  json_response["data"]["partition"].each do |part|
    return_array << DiskPartition.new(part["disk"], part["filesystem"], part["mount"], part["used"], part["percentage"], part["total"], part["available"])
  end

  # return the array of DiskPartition Objects
  return_array
end

.hostnameObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/mastercontrol/server.rb', line 47

def self.hostname
  url = "#{Mastercontrol.base_url}/gethostname?api.version=1"
  response = RestClient.get url, {authorization: Mastercontrol.auth_header}

  # parse the json
  json_response = JSON.parse(response)

  # build and return the ServerHostname Object
  ServerHostname.new(json_response['data']['hostname'])
end

.system_load_avgObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/mastercontrol/server.rb', line 36

def self.system_load_avg
  url = "#{Mastercontrol.base_url}/systemloadavg?api.version=1"
  response = RestClient.get url, {authorization: Mastercontrol.auth_header}

  # parse the json
  json_response = JSON.parse(response)

  # build and return the ServerLoad Object
  ServerLoad.new(json_response["data"]["one"], json_response["data"]["five"], json_response["data"]["fifteen"])
end