[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] [PATCH] oVirt / RRD Test Data



Attached is my now functional ruby script to generate test / demo rrd data and the oVirt patch required to get it working (a few small code tweaks / fixes and a few fixture modifications).

1. To generate the data data simply run `ruby demo-rrd-data.rb`. There are a few variables at the top of the script which you can tweak to configure things like nodes generated, cpu's per node, interval in seconds between data points, etc. 2. To see the test data, you need to be running rails in the testing environment and have a populated ovirt_test db. This can be accomplished by running the tests once (eg 'rake test') 3. Alot of data needs to be generated, thus the script is slow (at least on my system), and it isn't yet set to generate the number of data points in a time period that collectd does / oVirt is expecting (change the $interval variable at the top of the script from 60 to 10 to do this, but this will be all the more slower). Since the graphs require more data points than it is currently getting, they appear a bit discrete. Perhaps we can correct this and run it on a faster machine and just send out and use the data set generated. Alternatively, I could disable some of the algorithms used to generated data and simply reuse data points for some of the graphs if series repetition is not a problem.

  -Mo

Attachment: demo-rrd-data.rb
Description: application/ruby

>From 7630bdce8877c2d103df5aa7a7c19c6339bf425f Mon Sep 17 00:00:00 2001
From: Mohammed Morsi <mmorsi redhat com>
Date: Tue, 5 Aug 2008 18:51:21 -0400
Subject: [PATCH] changes to ovirt to pull in test / demo rrd data when
 in the testing environment, and code / fixure fixes,
 cleanup to get test data working

---
 wui/src/app/controllers/graph_controller.rb |   15 +++++++--------
 wui/src/app/util/stats/Stats.rb             |   10 ++++++++--
 wui/src/test/fixtures/cpus.yml              |    6 +++---
 wui/src/test/fixtures/hosts.yml             |    4 ++--
 wui/src/test/unit/cpu_test.rb               |    2 ++
 5 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/wui/src/app/controllers/graph_controller.rb b/wui/src/app/controllers/graph_controller.rb
index dbe2afc..17a347c 100644
--- a/wui/src/app/controllers/graph_controller.rb
+++ b/wui/src/app/controllers/graph_controller.rb
@@ -336,7 +336,7 @@ class GraphController < ApplicationController
                         @snapshots[:peak]["cpu"] =  value.to_i
                         @data_points[:peak]["cpu"] += 1
                     end
-                elsif !value.nan?
+                elsif !value.nil? && !value.nan?
                     if devClass == DEV_KEY_CLASSES["load"]
                         if function == DataFunction::Average
                             @snapshots[:avg]["load"] += value.to_i
@@ -446,14 +446,13 @@ class GraphController < ApplicationController
           end
 
           # massage some of the data:
-          if devClass == DEV_KEY_CLASSES["cpu"]
-              return value.to_i
-          elsif devClass == DEV_KEY_CLASSES["netout"] && counter == DEV_KEY_COUNTER["netout"]
-              return (value.to_i * 8 / 1024 / 1024).to_i #mbits
-          elsif devClass == DEV_KEY_CLASSES["netin"] && counter == DEV_KEY_COUNTER["netin"]
-              return (value.to_i * 8 / 1024 / 1024).to_i # mbits 
+          if devClass == DEV_KEY_CLASSES["netout"] && counter == DEV_KEY_COUNTER["netout"] ||
+             devClass == DEV_KEY_CLASSES["netin"] && counter == DEV_KEY_COUNTER["netin"]
+              return (value.to_f * 8 / 1024 / 1024) # mbits 
           elsif devClass == DEV_KEY_CLASSES["memory"]
-              return (value.to_i / 1000000).to_i
+              return (value.to_f / 1000000)
+          else
+              return value
           end
       end
 
diff --git a/wui/src/app/util/stats/Stats.rb b/wui/src/app/util/stats/Stats.rb
index f6ced4b..83d5d7b 100644
--- a/wui/src/app/util/stats/Stats.rb
+++ b/wui/src/app/util/stats/Stats.rb
@@ -24,6 +24,13 @@ require 'util/stats/StatsData'
 require 'util/stats/StatsDataList'
 require 'util/stats/StatsRequest'
 
+# set path to rrd stats to use
+if ENV["RAILS_ENV"] != 'test'
+   $rrdBase="/var/lib/collectd/rrd/"
+else
+   $rrdBase="/var/lib/collectd/rrd-test/"
+end
+
 
 # This fetches a rolling average, basically average points before and after.
 
@@ -210,8 +217,7 @@ def fetchData?(node, devClass, instance, counter, startTime, duration, interval,
 
    start =  (sTime / interval).to_i * interval 
    endTime =  (eTime / interval).to_i * interval 
-   rrdBase="/var/lib/collectd/rrd/"
-   rrdNode=rrdBase + node + "/"
+   rrdNode=$rrdBase + node + "/"
 
    # Now we need to mess a bit to get the right combos
    case devClass
diff --git a/wui/src/test/fixtures/cpus.yml b/wui/src/test/fixtures/cpus.yml
index 5586303..e4c7676 100644
--- a/wui/src/test/fixtures/cpus.yml
+++ b/wui/src/test/fixtures/cpus.yml
@@ -3,19 +3,19 @@
 one:
   cpu_number: 1
   core_number: 1
-  cpu_id_level: 1
   vendor: 1
   family: 1
   model: 1
   family: MyString
   flags: MyString
+  host_id: 9
 
 two:
-  cpu_number: 1
+  cpu_number: 2
   core_number: 1
-  cpu_id_level: 1
   vendor: 1
   family: 1
   model: 1
   family: MyString
   flags: MyString
+  host_id: 9
diff --git a/wui/src/test/fixtures/hosts.yml b/wui/src/test/fixtures/hosts.yml
index f10a756..c3e98ad 100644
--- a/wui/src/test/fixtures/hosts.yml
+++ b/wui/src/test/fixtures/hosts.yml
@@ -73,9 +73,9 @@ eight:
 nine:
  id: 9
  uuid: '81c15560-dbf4-45f5-9b75-106cdbd63aeb'
- hostname: 'somehost'
+ hostname: 'node0'
  arch: 'x86'
  memory: 4096
  is_disabled: 0
  hypervisor_type: 'kvm'
- hardware_pool_id: 3
+ hardware_pool_id: 1
diff --git a/wui/src/test/unit/cpu_test.rb b/wui/src/test/unit/cpu_test.rb
index 5b64ca7..9558525 100644
--- a/wui/src/test/unit/cpu_test.rb
+++ b/wui/src/test/unit/cpu_test.rb
@@ -1,6 +1,8 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class CpuTest < ActiveSupport::TestCase
+  fixtures :cpus
+
   # Replace this with your real tests.
   def test_truth
     assert true
-- 
1.5.4.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]