Class: Pencil::Models::Host
- Inherits:
-
Base
- Object
- Base
- Pencil::Models::Host
show all
- Defined in:
- lib/pencil/models/host.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#[], all, #compose_metric, #compose_metric2, each, #match, #multi_match, #to_s, #update_params
Constructor Details
#initialize(name, cluster, params = {}) ⇒ Host
Returns a new instance of Host.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/pencil/models/host.rb', line 10
def initialize(name, cluster, params={})
super(name, params)
@cluster = cluster
@@objects[self.class.to_s].delete(name)
@@objects[self.class.to_s]["#{cluster}#{name}"] = self
@graphs = []
Graph.each do |graph_name, graph|
graph["hosts"].each do |h|
if match(h)
@graphs << graph
break
end
end end @graphs.sort!
end
|
Instance Attribute Details
#cluster ⇒ Object
Returns the value of attribute cluster.
8
9
10
|
# File 'lib/pencil/models/host.rb', line 8
def cluster
@cluster
end
|
#graphs ⇒ Object
Returns the value of attribute graphs.
7
8
9
|
# File 'lib/pencil/models/host.rb', line 7
def graphs
@graphs
end
|
Class Method Details
.find(name) ⇒ Object
29
30
31
|
# File 'lib/pencil/models/host.rb', line 29
def self.find(name)
return @@objects[self.name][key] rescue []
end
|
.find_by_cluster(cluster) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/pencil/models/host.rb', line 80
def self.find_by_cluster(cluster)
ret = []
Host.each do |name, host|
ret << host if host.cluster == cluster
end
return ret
end
|
.find_by_name_and_cluster(name, cluster) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/pencil/models/host.rb', line 72
def self.find_by_name_and_cluster(name, cluster)
Host.each do |host_name, host|
next unless host.name == name
return host if host.cluster == cluster
end
return nil
end
|
Instance Method Details
#<=>(other) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/pencil/models/host.rb', line 45
def <=>(other)
if @params[:host_sort] == "builtin"
return key <=> other.key
elsif @params[:host_sort] == "numeric"
regex = /\d+/
match = @name.match(regex)
match2 = other.name.match(regex)
if match.pre_match != match2.pre_match
return match.pre_match <=> match2.pre_match
else
return match[0].to_i <=> match2[0].to_i
end
else
sensible = lambda do |k|
k.to_s.split(
/((?:(?:^|\s)[-+])?(?:\.\d+|\d+(?:\.\d+?(?:[eE]\d+)?(?:$|(?![eE\.])))?))/ms
).map { |v| Float(v) rescue v.downcase }
end
return sensible.call(self) <=> sensible.call(other)
end
end
|
#==(other) ⇒ Object
41
42
43
|
# File 'lib/pencil/models/host.rb', line 41
def ==(other)
key == other.key
end
|
#eql?(other) ⇒ Boolean
37
38
39
|
# File 'lib/pencil/models/host.rb', line 37
def eql?(other)
key == other.key
end
|
#hash ⇒ Object
68
69
70
|
# File 'lib/pencil/models/host.rb', line 68
def hash
key.hash
end
|
#key ⇒ Object
33
34
35
|
# File 'lib/pencil/models/host.rb', line 33
def key
"#{@cluster}#{@name}"
end
|