Class: Appdynamics::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/appdynamics/metric.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, parent, attrs) ⇒ Metric

Returns a new instance of Metric.



6
7
8
9
10
11
12
# File 'lib/appdynamics/metric.rb', line 6

def initialize controller, parent, attrs
    @controller = controller
    @parent = parent
    attrs.keys.each do |key|
        self.send "#{key}=", attrs[key]
    end
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



4
5
6
# File 'lib/appdynamics/metric.rb', line 4

def controller
  @controller
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/appdynamics/metric.rb', line 3

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/appdynamics/metric.rb', line 4

def parent
  @parent
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/appdynamics/metric.rb', line 3

def type
  @type
end

Class Method Details

.from_hash(hsh, controller, parent) ⇒ Object



24
25
26
# File 'lib/appdynamics/metric.rb', line 24

def self.from_hash hsh, controller, parent
    Metric.new controller, parent, hsh
end

Instance Method Details

#build_metrics_tree!(tab_level = 0) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/appdynamics/metric.rb', line 69

def build_metrics_tree! tab_level = 0
    return if leaf?
    puts "#{'    ' * tab_level}Building tree for #{name} (#{type})"
    metrics.each do |m|
        m.build_metrics_tree!(tab_level + 1)
    end
end

#child_by_name(nam) ⇒ Object



59
60
61
62
63
# File 'lib/appdynamics/metric.rb', line 59

def child_by_name nam
    metrics.select{|metric|
        metric.name == nam
    }.first
end

#data(start_time, end_time, rollup = false) ⇒ Object



93
94
95
96
# File 'lib/appdynamics/metric.rb', line 93

def data start_time, end_time, rollup = false
    raw_data = controller.metric_data_for(self, start_time, end_time, rollup).first
    raw_data["metricValues"]
end

#find_by_name(nam) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/appdynamics/metric.rb', line 49

def find_by_name nam
    return self if name == nam
    metric = nil
    metrics.each do |m|
        metric = m.find_by_name nam
        break unless metric.nil?
    end
    metric
end

#metricsObject



65
66
67
# File 'lib/appdynamics/metric.rb', line 65

def metrics
    @metrics ||= controller.metrics_for self
end

#metrics=(metrics) ⇒ Object



43
44
45
46
47
# File 'lib/appdynamics/metric.rb', line 43

def metrics= metrics
    @metrics = metrics.map {|metric|
        Metric.new @controller, self, metric
    }
end

#pathObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/appdynamics/metric.rb', line 28

def path
    return @path unless @path.nil?
    ar = [self.name]
    node = self
    while node.parent.class == Appdynamics::Metric && node = node.parent
        ar.unshift node.name
    end
    @path = ar
    @path
end

#path=(pat) ⇒ Object



39
40
41
# File 'lib/appdynamics/metric.rb', line 39

def path= pat
    @path = pat
end

#relative_route(data_requested = false) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/appdynamics/metric.rb', line 77

def relative_route data_requested = false
    rel_path = "#{parent.relative_route(data_requested)}"
    case parent
        when Appdynamics::Metric
            rel_path += "|#{name}"
        when Appdynamics::Application
            if data_requested
                rel_path += "/metric-data"
            else
                rel_path += "/metrics/"
            end
            rel_path += "?metric-path=#{name}"
    end
    rel_path
end

#to_hashObject



14
15
16
17
18
19
20
21
22
# File 'lib/appdynamics/metric.rb', line 14

def to_hash
    hsh = {
        name: @name,
        type: @type
    }
    hsh.merge!({path: path})
    hsh.merge!({metrics: @metrics.map{|metric| metric.to_hash}}) if @metrics
    hsh
end