1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[stormondemand|monitoring] Add a new Monitoring service and add/move load/bandwidth/service APIs

This commit is contained in:
Eric Wong 2013-05-24 21:11:28 +08:00
parent 3de8f5c9c4
commit 55d0925de1
20 changed files with 336 additions and 54 deletions

24
lib/fog/monitoring.rb Normal file
View file

@ -0,0 +1,24 @@
module Fog
module Monitoring
def self.[](provider)
self.new(:provider => provider)
end
def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand
require 'fog/storm_on_demand/billing'
Fog::Monitoring::StormOnDemand.new(attributes)
else
raise ArgumentError.new("#{provider} has no monitoring service")
end
end
def self.providers
Fog.services[:monitoring]
end
end
end

View file

@ -9,6 +9,7 @@ module Fog
service(:storage, 'storm_on_demand/storage', 'Storage') service(:storage, 'storm_on_demand/storage', 'Storage')
service(:dns, 'storm_on_demand/dns', 'DNS') service(:dns, 'storm_on_demand/dns', 'DNS')
service(:billing, 'storm_on_demand/billing', 'Billing') service(:billing, 'storm_on_demand/billing', 'Billing')
service(:monitoring, 'storm_on_demand/monitoring', 'Monitoring')
end end
end end

View file

@ -30,8 +30,6 @@ module Fog
collection :pools collection :pools
model :zone model :zone
collection :zones collection :zones
model :stat
collection :stats
model :template model :template
collection :templates collection :templates
model :product model :product
@ -79,9 +77,6 @@ module Fog
request :get_image_details request :get_image_details
request :update_image request :update_image
request :restore_image request :restore_image
request :get_stats
request :get_stats_graph
request :list_private_ips request :list_private_ips
request :get_private_ip request :get_private_ip

View file

@ -1,26 +0,0 @@
require 'fog/core/collection'
require 'fog/storm_on_demand/models/compute/stat'
module Fog
module Compute
class StormOnDemand
class Stats < Fog::Collection
model Fog::Compute::StormOnDemand::Stat
def get(options)
data = service.get_stats(options).body
load(data)
rescue Excon::Errors::Forbidden
nil
end
def graph(options)
service.get_stats_graph(options).body
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/core/model'
module Fog
module Monitoring
class StormOnDemand
class Bandwidth < Fog::Model
attribute :actual
attribute :averages
attribute :cost
attribute :domain
attribute :pricing
attribute :projected
def initialize(attributes={})
super
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/core/collection'
require 'fog/storm_on_demand/models/monitoring/bandwidth'
module Fog
module Monitoring
class StormOnDemand
class Bandwidths < Fog::Collection
model Fog::Monitoring::StormOnDemand::Bandwidth
def graph(options)
service.get_bandwidth_graph(options).body
end
def stats(uniq_id)
bw = service.get_bandwidth_stats(:uniq_id => uniq_id).body
new(bw)
end
end
end
end
end

View file

@ -1,17 +1,17 @@
require 'fog/core/model' require 'fog/core/model'
module Fog module Fog
module Compute module Monitoring
class StormOnDemand class StormOnDemand
class Stat < Fog::Model class Load < Fog::Model
attribute :disk
attribute :domain
attribute :loadavg attribute :loadavg
attribute :memory attribute :memory
attribute :proc attribute :proc
attribute :domain
attribute :disk
attribute :uptime attribute :uptime
def initialize(attributes={}) def initialize(attributes={})
super super
end end

View file

@ -0,0 +1,24 @@
require 'fog/core/collection'
require 'fog/storm_on_demand/models/monitoring/load'
module Fog
module Monitoring
class StormOnDemand
class Loads < Fog::Collection
model Fog::Monitoring::StormOnDemand::Load
def graph(options)
service.get_load_graph(options).body
end
def stats(uniq_id)
load = service.get_load_stats(:uniq_id => uniq_id).body
new(load)
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'fog/core/model'
module Fog
module Monitoring
class StormOnDemand
class MonitorService < Fog::Model
attribute :can_monitor
attribute :enabled
attribute :services
attribute :uniq_id
attribute :unmonitored
def initialize(attributes={})
super
end
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
require 'fog/storm_on_demand/models/monitoring/monitor_service'
module Fog
module Monitoring
class StormOnDemand
class MonitorServices < Fog::Collection
model Fog::Monitoring::StormOnDemand::MonitorService
def get(uniq_id)
status = service.get_service(:uniq_id => uniq_id).body
new(status)
end
def monitoring_ips
service.monitoring_ips.body['ips']
end
def status(uniq_id)
service.get_service_status(:uniq_id => uniq_id).body
end
def update(options)
status = service.update_service(options).body
new(status)
end
end
end
end
end

View file

@ -0,0 +1,68 @@
require 'fog/storm_on_demand'
require 'fog/monitoring'
require 'fog/storm_on_demand/shared'
module Fog
module Monitoring
class StormOnDemand < Fog::Service
requires :storm_on_demand_username, :storm_on_demand_password
recognizes :storm_on_demand_auth_url
model_path 'fog/storm_on_demand/models/monitoring'
model :load
collection :loads
model :bandwidth
collection :bandwidths
model :monitor_service
collection :monitor_services
request_path 'fog/storm_on_demand/requests/monitoring'
request :get_load_graph
request :get_load_stats
request :get_bandwidth_graph
request :get_bandwidth_stats
request :get_service
request :monitoring_ips
request :get_service_status
request :update_service
class Mock
def self.data
@data ||= Hash.new
end
def self.reset
@data = nil
end
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end
def initialize(options={})
@storm_on_demand_username = options[:storm_on_demand_username]
end
def data
self.class.data[@storm_on_demand_username]
end
def reset_data
self.class.data.delete(@storm_on_demand_username)
end
end
class Real
include Fog::StormOnDemand::RealShared
end
end
end
end

View file

@ -1,16 +0,0 @@
module Fog
module Compute
class StormOnDemand
class Real
def get_stats(options = {})
request(
:path => "/Monitoring/Load/stats",
:body => Fog::JSON.encode({:params => options})
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def get_bandwidth_graph(options={})
request(
:path => '/Monitoring/Bandwidth/graph',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def get_bandwidth_stats(options={})
request(
:path => '/Monitoring/Bandwidth/stats',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -1,9 +1,9 @@
module Fog module Fog
module Compute module Monitoring
class StormOnDemand class StormOnDemand
class Real class Real
def get_stats_graph(options={}) def get_load_graph(options={})
request( request(
:path => '/Monitoring/Load/graph', :path => '/Monitoring/Load/graph',
:body => Fog::JSON.encode(:params => options) :body => Fog::JSON.encode(:params => options)

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def get_load_stats(options={})
request(
:path => '/Monitoring/Load/stats',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def get_service(options={})
request(
:path => '/Monitoring/Services/get',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def get_service_status(options={})
request(
:path => '/Monitoring/Services/status',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def monitoring_ips(options={})
request(
:path => '/Monitoring/Services/monitoringIps',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Monitoring
class StormOnDemand
class Real
def update_service(options={})
request(
:path => '/Monitoring/Services/update',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end