Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from racker/add_metrics_support
Add support for metrics and data_points
- Loading branch information
Showing
9 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.15 | ||
0.2.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rackspace-fog/core/model' | ||
require 'rackspace-monitoring/monitoring/models/base' | ||
|
||
module Fog | ||
module Monitoring | ||
class Rackspace | ||
class DataPoint < Fog::Monitoring::Rackspace::Base | ||
attribute :num_points, :aliases => "numPoints" | ||
attribute :average | ||
attribute :variance | ||
attribute :min | ||
attribute :max | ||
attribute :timestamp | ||
attribute :metric | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'rackspace-fog/core/collection' | ||
require 'rackspace-monitoring/monitoring/models/data_point' | ||
|
||
module Fog | ||
module Monitoring | ||
class Rackspace | ||
class DataPoints < Fog::Collection | ||
|
||
attribute :metric | ||
|
||
model Fog::Monitoring::Rackspace::DataPoint | ||
|
||
def all | ||
self.fetch(:resolution => :full) | ||
end | ||
|
||
# Fetch the datapoints for a metric | ||
# ==== Parameters | ||
# | ||
# * options<~Hash> - optional paramaters | ||
# * from<~Integer> - timestamp in milliseconds | ||
# * to<~Integer> - timestamp in milliseconds | ||
# * points<~Integer> - Number of points to fetch | ||
# * resolution<~String> - Should be one of :full, :min5, :min20, :min60, :min240, :min1440 | ||
# * select<~Array> - Should be an array of :average, :max, :min, :variance | ||
# | ||
# ==== Returns | ||
# * datapoints<~Fog::Monitoring::Rackspace::Datapoints>: | ||
def fetch(options={}) | ||
requires :metric | ||
options[:from] ||= (Time.now.to_i * 1000) - (3600 * 1000) | ||
options[:to] ||= Time.now.to_i * 1000 | ||
options[:points] ||= 1 unless options[:resolution] | ||
if options[:resolution] | ||
options[:resolution] = options[:resolution].upcase | ||
end | ||
data = connection.list_data_points(metric.check.entity.id, metric.check.id, metric.name, options).body['values'] | ||
load(data) | ||
end | ||
|
||
def new(attributes = {}) | ||
requires :metric | ||
super({ :metric => metric }.merge!(attributes)) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rackspace-fog/core/model' | ||
require 'rackspace-monitoring/monitoring/models/base' | ||
|
||
module Fog | ||
module Monitoring | ||
class Rackspace | ||
class Metric < Fog::Monitoring::Rackspace::Base | ||
|
||
identity :name | ||
attribute :check | ||
|
||
def datapoints(options={}) | ||
@datapoints ||= begin | ||
Fog::Monitoring::Rackspace::DataPoints.new( | ||
:metric => self, | ||
:connection => connection | ||
) | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rackspace-fog/core/collection' | ||
require 'rackspace-monitoring/monitoring/models/metric' | ||
|
||
module Fog | ||
module Monitoring | ||
class Rackspace | ||
class Metrics < Fog::Collection | ||
|
||
attribute :check | ||
|
||
model Fog::Monitoring::Rackspace::Metric | ||
|
||
def all | ||
requires :check | ||
data = connection.list_metrics(check.entity.id, check.id).body['values'] | ||
load(data) | ||
end | ||
|
||
def new(attributes = {}) | ||
requires :check | ||
super({ :check => check }.merge!(attributes)) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
lib/rackspace-monitoring/monitoring/requests/list_data_points.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fog | ||
module Monitoring | ||
class Rackspace | ||
class Real | ||
|
||
def list_data_points(entity_id, check_id, metric_name, options) | ||
request( | ||
:expects => [200, 203], | ||
:method => 'GET', | ||
:path => "entities/#{entity_id}/checks/#{check_id}/metrics/#{metric_name}/plot", | ||
:query => options | ||
) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
lib/rackspace-monitoring/monitoring/requests/list_metrics.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fog | ||
module Monitoring | ||
class Rackspace | ||
class Real | ||
|
||
def list_metrics(entity_id, check_id) | ||
request( | ||
:expects => [200, 203], | ||
:method => 'GET', | ||
:path => "entities/#{entity_id}/checks/#{check_id}/metrics" | ||
) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
|