Class: Appdynamics::Controller
- Inherits:
-
Object
- Object
- Appdynamics::Controller
- Includes:
- HTTParty
- Defined in:
- lib/appdynamics/controller.rb
Instance Attribute Summary collapse
-
#account_name ⇒ Object
readonly
Returns the value of attribute account_name.
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#application_name ⇒ Object
readonly
Returns the value of attribute application_name.
-
#applications ⇒ Object
Returns the value of attribute applications.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#host_name ⇒ Object
readonly
Returns the value of attribute host_name.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#tiers ⇒ Object
readonly
Returns the value of attribute tiers.
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
Class Method Summary collapse
Instance Method Summary collapse
- #get(path, additional_options = {}) ⇒ Object
-
#initialize(host_name, account_name, user_name, password) ⇒ Controller
constructor
A new instance of Controller.
- #metric_data_for(metric, start_time, end_time, rollup = false) ⇒ Object
- #metrics_for(obj) ⇒ Object
- #nodes_for(application) ⇒ Object
- #reset_cache! ⇒ Object
- #serialize ⇒ Object
- #tiers_for(application) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(host_name, account_name, user_name, password) ⇒ Controller
Returns a new instance of Controller.
8 9 10 11 12 13 14 15 |
# File 'lib/appdynamics/controller.rb', line 8 def initialize host_name, account_name, user_name, password @host_name = host_name @account_name = account_name @user_name = user_name @password = password @base_uri = "http://#{host_name}/controller/rest" @auth = {username: "#{user_name}@#{account_name}", password: password} end |
Instance Attribute Details
#account_name ⇒ Object (readonly)
Returns the value of attribute account_name.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def account_name @account_name end |
#application_id ⇒ Object (readonly)
Returns the value of attribute application_id.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def application_id @application_id end |
#application_name ⇒ Object (readonly)
Returns the value of attribute application_name.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def application_name @application_name end |
#applications ⇒ Object
Returns the value of attribute applications.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def applications @applications end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def base_uri @base_uri end |
#host_name ⇒ Object (readonly)
Returns the value of attribute host_name.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def host_name @host_name end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def nodes @nodes end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def password @password end |
#tiers ⇒ Object (readonly)
Returns the value of attribute tiers.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def tiers @tiers end |
#user_name ⇒ Object (readonly)
Returns the value of attribute user_name.
5 6 7 |
# File 'lib/appdynamics/controller.rb', line 5 def user_name @user_name end |
Class Method Details
.deserialize(datum) ⇒ Object
21 22 23 |
# File 'lib/appdynamics/controller.rb', line 21 def self.deserialize datum YAML.load datum end |
.from_hash(hsh) ⇒ Object
36 37 38 39 40 |
# File 'lib/appdynamics/controller.rb', line 36 def self.from_hash hsh controller = Controller.new hsh['host_name'], hsh['account_name'], hsh['user_name'], hsh['password'] controller.applications = hsh['applications'] controller end |
Instance Method Details
#get(path, additional_options = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/appdynamics/controller.rb', line 68 def get path, = {} result = self.class.get(URI.escape(path), ()) raise Exception.new "HTTP Error: #{result.response.code}" unless result.response.code == "200" result end |
#metric_data_for(metric, start_time, end_time, rollup = false) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/appdynamics/controller.rb', line 99 def metric_data_for metric, start_time, end_time, rollup = false path = "#{base_uri}/#{metric.relative_route(true)}" start_time = Time.parse start_time unless start_time.class == Time end_time = Time.parse end_time unless end_time.class == Time path = "#{base_uri}/#{metric.relative_route(true)}" = { 'time-range-type' => "BETWEEN_TIMES", 'start-time' => start_time.to_i * 1000, 'end-time' => end_time.to_i * 1000, 'rollup' => rollup } result = get path, ({query: }) result end |
#metrics_for(obj) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/appdynamics/controller.rb', line 90 def metrics_for obj path = "#{base_uri}/#{obj.relative_route}" path += "/metrics" if obj.class == Application result = get path result.map{|res| Metric.new self, obj, res } end |
#nodes_for(application) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/appdynamics/controller.rb', line 74 def nodes_for application path = "#{base_uri}/#{application.relative_route}/nodes" result = get path result.map{|res| Node.new self, application, res } end |
#reset_cache! ⇒ Object
64 65 66 |
# File 'lib/appdynamics/controller.rb', line 64 def reset_cache! @nodes = @tiers = @applications = nil end |
#serialize ⇒ Object
17 18 19 |
# File 'lib/appdynamics/controller.rb', line 17 def serialize YAML.dump self end |
#tiers_for(application) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/appdynamics/controller.rb', line 82 def tiers_for application path = "#{base_uri}/#{application.relative_route}/tiers" result = get path result.map{|res| Tier.new self, application, res } end |
#to_hash ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/appdynamics/controller.rb', line 25 def to_hash hsh = { host_name: @host_name, account_name: @account_name, user_name: @user_name, password: @password } hsh.merge!({applications: @applications.map{|app| app.to_hash}}) if @applications hsh end |