deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/2] git commit: mock: added metrics support
Date Thu, 12 Jul 2012 09:54:17 GMT
Updated Branches:
  refs/heads/master a213b54a1 -> eaa726b47


mock: added metrics support


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/a46d190a
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/a46d190a
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/a46d190a

Branch: refs/heads/master
Commit: a46d190ac74f69dff7c6725df93485055490bf55
Parents: a213b54
Author: Dies Koper <diesk@fast.au.fujitsu.com>
Authored: Thu Jul 12 00:27:29 2012 +1000
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Thu Jul 12 11:54:26 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/mock/mock_driver.rb |   74 ++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a46d190a/server/lib/deltacloud/drivers/mock/mock_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index ba817c6..72ba642 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -76,6 +76,7 @@ module Deltacloud::Drivers::Mock
     feature :instances, :user_name
     feature :instances, :user_data
     feature :instances, :authentication_key
+    feature :instances, :metrics
     feature :images, :user_name
     feature :images, :user_description
 
@@ -447,6 +448,55 @@ module Deltacloud::Drivers::Mock
       end
     end
 
+    #--
+    # Metrics
+    #--
+    def metrics(credentials, opts={})
+      check_credentials( credentials )
+      instances = @client.build_all(Instance)
+      instances = filter_on( instances, :id, opts )
+
+      metrics_arr = instances.collect do |instance|
+        Metric.new(
+          :id     => instance.id,
+          :entity => instance.name
+        )
+      end
+
+      # add metric names to metrics
+      metrics_arr.each do |metric|
+        @@METRIC_NAMES.each do |name|
+          metric.add_property(name)
+        end
+        metric.properties.sort! {|a,b| a.name <=> b.name}
+      end
+      metrics_arr
+    end
+
+    def metric(credentials, opts={})
+      metric = metrics(credentials, opts).first
+      sample_count = rand(10) + 1
+
+      metric.properties.each do |property|
+
+        property.values = (0..5).collect do |i|
+
+          unit = metric_unit_for(property.name)
+          average = (property.name == 'cpuUtilization') ? (rand * 1000).to_i / 10.0 : rand(1000)
+          max = (property.name == 'cpuUtilization') ? (1000 + 10 * average).to_i / 20.0 :
average * (i + 1)
+          min = (property.name == 'cpuUtilization') ? (2.5 * average).to_i / 10.0 : (average
/ 4).to_i
+          {
+            :minimum   => min,
+            :maximum   => max,
+            :average   => average,
+            :timestamp => Time.now - i * 60,
+            :unit      => unit
+          }
+        end
+      end
+      metric
+    end
+
     def valid_credentials?(credentials)
       begin
         check_credentials(credentials)
@@ -492,6 +542,30 @@ module Deltacloud::Drivers::Mock
       StorageVolume.new(volume)
     end
 
+    def metric_unit_for(name)
+      case name
+        when /Utilization/ then 'Percent'
+        when /Byte/ then 'Bytes'
+        when /Sector/ then 'Count'
+        when /Count/ then 'Count'
+        when /Packet/ then 'Count'
+        else 'None'
+      end
+    end
+
+    # names copied from FGCP driver
+    @@METRIC_NAMES = [
+      'cpuUtilization',
+      'diskReadRequestCount',
+      'diskReadSector',
+      'diskWriteRequestCount',
+      'diskWriteSector',
+      'nicInputByte',
+      'nicInputPacket',
+      'nicOutputByte',
+      'nicOutputPacket'
+    ]
+
     exceptions do
 
       on /AuthFailure/ do


Mime
View raw message