Class: MMS::Resource::Host

Inherits:
MMS::Resource show all
Defined in:
lib/mms/resource/host.rb

Instance Attribute Summary collapse

Attributes inherited from MMS::Resource

#client, #data, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MMS::Resource

#_load, cache_key, find, #from_hash, #invalidate_cache, #to_hash

Constructor Details

#initializeHost

Returns a new instance of Host.



18
19
20
# File 'lib/mms/resource/host.rb', line 18

def initialize
  @metric_list = []
end

Instance Attribute Details

#alerts_enabledObject

Returns the value of attribute alerts_enabled.



13
14
15
# File 'lib/mms/resource/host.rb', line 13

def alerts_enabled
  @alerts_enabled
end

#host_enabledObject

Returns the value of attribute host_enabled.



14
15
16
# File 'lib/mms/resource/host.rb', line 14

def host_enabled
  @host_enabled
end

#hostnameObject

Returns the value of attribute hostname.



4
5
6
# File 'lib/mms/resource/host.rb', line 4

def hostname
  @hostname
end

#ip_addressObject

Returns the value of attribute ip_address.



8
9
10
# File 'lib/mms/resource/host.rb', line 8

def ip_address
  @ip_address
end

#last_pingObject

Returns the value of attribute last_ping.



7
8
9
# File 'lib/mms/resource/host.rb', line 7

def last_ping
  @last_ping
end

#logs_enabledObject

Returns the value of attribute logs_enabled.



16
17
18
# File 'lib/mms/resource/host.rb', line 16

def logs_enabled
  @logs_enabled
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mms/resource/host.rb', line 3

def name
  @name
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/mms/resource/host.rb', line 5

def port
  @port
end

#profiler_enabledObject

Returns the value of attribute profiler_enabled.



15
16
17
# File 'lib/mms/resource/host.rb', line 15

def profiler_enabled
  @profiler_enabled
end

#replica_state_nameObject

Returns the value of attribute replica_state_name.



12
13
14
# File 'lib/mms/resource/host.rb', line 12

def replica_state_name
  @replica_state_name
end

#replicaset_nameObject

Returns the value of attribute replicaset_name.



11
12
13
# File 'lib/mms/resource/host.rb', line 11

def replicaset_name
  @replicaset_name
end

#shard_nameObject

Returns the value of attribute shard_name.



10
11
12
# File 'lib/mms/resource/host.rb', line 10

def shard_name
  @shard_name
end

#type_nameObject

Returns the value of attribute type_name.



6
7
8
# File 'lib/mms/resource/host.rb', line 6

def type_name
  @type_name
end

#versionObject

Returns the value of attribute version.



9
10
11
# File 'lib/mms/resource/host.rb', line 9

def version
  @version
end

Class Method Details

._find(client, group_id, id) ⇒ Hash

Parameters:

Returns:

  • (Hash)


60
61
62
# File 'lib/mms/resource/host.rb', line 60

def self._find(client, group_id, id)
  client.get('/groups/' + group_id + '/hosts/' + id)
end

.table_headerObject



52
53
54
# File 'lib/mms/resource/host.rb', line 52

def self.table_header
  ['Group', 'Type', 'Hostname', 'IP', 'Port', 'Last ping', 'Alerts enabled', 'HostId', 'Shard', 'Replica']
end

Instance Method Details

#_from_hash(data) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mms/resource/host.rb', line 78

def _from_hash(data)
  @hostname = data['hostname']
  @port = data['port']
  @type_name = data['typeName']
  @last_ping = data['lastPing']
  @ip_address = data['ipAddress']
  @version = data['version']
  @shard_name = data['shardName']
  @replicaset_name = data['replicaSetName']
  @replica_state_name = data['replicaStateName']
  @alerts_enabled = data['alertsEnabled']
  @host_enabled = data['hostEnabled']
  @profiler_enabled = data['profilerEnabled']
  @logs_enabled = data['logsEnabled']
  @name = @hostname
end

#_to_hashObject



95
96
97
# File 'lib/mms/resource/host.rb', line 95

def _to_hash
  @data
end

#groupMMS::Resource::Group



23
24
25
# File 'lib/mms/resource/host.rb', line 23

def group
  MMS::Resource::Group.find(@client, @data['groupId'])
end

#metricsArray<MMS::Resource::Metric>

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mms/resource/host.rb', line 65

def metrics
  if @metric_list.empty?
    @client.get('/groups/' + group.id + '/hosts/' + @id + '/metrics').each do |metric|
      m = MMS::Resource::Metric.new
      m.client(@client)
      m.data(metric)

      @metric_list.push m
    end
  end
  @metric_list
end

#snapshot(id) ⇒ Object



27
28
29
# File 'lib/mms/resource/host.rb', line 27

def snapshot(id)
  MMS::Resource::Snapshot.find(@client, group.id, nil, @id, id)
end

#snapshots(page = 1, limit = 100) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mms/resource/host.rb', line 31

def snapshots(page = 1, limit = 100)
  if @snapshots.empty?
    @client.get('/groups/' + group.id + '/hosts/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
      s = MMS::Resource::Snapshot.new
      s.client(@client)
      s.data(snapshot)

      @snapshots.push s
    end
  end
  @snapshots
end

#table_rowObject



44
45
46
# File 'lib/mms/resource/host.rb', line 44

def table_row
  [group.name, @type_name, @name, @ip_address, @port, @last_ping, @alerts_enabled, @id, @shard_name, @replicaset_name]
end

#table_sectionObject



48
49
50
# File 'lib/mms/resource/host.rb', line 48

def table_section
  [table_row]
end