mark wagner
2008-Jun-06 04:01 UTC
[ovirt-devel][PATCH] Add Status and error handling to Stats stuff
Added code to check validity of pathname to rrdfile. Added new enum for StatsStatus Added new member to StatsDataList to hold status information --- wui/src/app/util/stats/Stats.rb | 36 ++++++++++++++++++++++-------- wui/src/app/util/stats/StatsDataList.rb | 7 +++++- wui/src/app/util/stats/StatsTypes.rb | 21 ++++++++++++++++++ wui/src/app/util/stats/statsTest.rb | 17 ++++++++++---- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/wui/src/app/util/stats/Stats.rb b/wui/src/app/util/stats/Stats.rb index 73a6920..e7bd8fd 100644 --- a/wui/src/app/util/stats/Stats.rb +++ b/wui/src/app/util/stats/Stats.rb @@ -74,17 +74,33 @@ def fetchData?(node, devClass, instance, counter, startTime, duration, interval) rrd = rrdNode + rrdTail + ".rrd" - returnList = StatsDataList.new(node,devClass,instance, counter) - (fstart, fend, names, data, interval) = RRD.fetch(rrd, "--start", start.to_s, "--end", endTime.to_s, "AVERAGE", "-r", interval.to_s) - i = 0 - # For some reason, we get an extra datapoint at the end. Just chop it off now... - data.delete_at(-1) - - # Now, lets walk the returned data and create the ojects, and put them in a list. - data.each do |vdata| - i += 1 - returnList.append_data( StatsData.new(fstart + interval * i, vdata[lIndex] )) + if ( File.exists?(rrd ) ) + localStatus = StatsStatus::SUCCESS + elsif ( File.exists?(rrdNode )) + # Check the Node first + localStatus = StatsStatus::E_NOSUCHNODE + else + # Currently can't distinguish between device and counter, so return generic error + localStatus = StatsStatus::E_UNKNOWN + end + + returnList = StatsDataList.new(node,devClass,instance, counter, localStatus) + + # So if the path is bad, no need to continue, it will just thrown an error, just return + + if ( localStatus == StatsStatus::SUCCESS ) + (fstart, fend, names, data, interval) = RRD.fetch(rrd, "--start", start.to_s, "--end", endTime.to_s, "AVERAGE", "-r", interval.to_s) + i = 0 + # For some reason, we get an extra datapoint at the end. Just chop it off now... + data.delete_at(-1) + + # Now, lets walk the returned data and create the ojects, and put them in a list. + data.each do |vdata| + i += 1 + returnList.append_data( StatsData.new(fstart + interval * i, vdata[lIndex] )) + end end + return returnList end diff --git a/wui/src/app/util/stats/StatsDataList.rb b/wui/src/app/util/stats/StatsDataList.rb index 2e223ed..3ca2db2 100644 --- a/wui/src/app/util/stats/StatsDataList.rb +++ b/wui/src/app/util/stats/StatsDataList.rb @@ -20,13 +20,14 @@ #define class StatsData List class StatsDataList - def initialize(node,devClass,instance, counter) + def initialize(node,devClass,instance, counter, status) # Instance variables @node = node @devClass = devClass @instance = instance @counter = counter @data=[] + @status = status end def get_node?() @@ -49,6 +50,10 @@ class StatsDataList return @data end + def get_status?() + return @status + end + def append_data(incoming) @data << incoming end diff --git a/wui/src/app/util/stats/StatsTypes.rb b/wui/src/app/util/stats/StatsTypes.rb index 6049a2e..7a1717c 100644 --- a/wui/src/app/util/stats/StatsTypes.rb +++ b/wui/src/app/util/stats/StatsTypes.rb @@ -330,4 +330,25 @@ class RRDResolution end +class StatsStatus + def StatsStatus.add_item(key,value) + @hash ||= {} + @hash[key]=value + end + + def StatsStatus.const_missing(key) + @hash[key] + end + def StatsStatus.each + @hash.each {|key,value| yield(key,value)} + end + + # Set up the resolutions for our rrd + StatsStatus.add_item :SUCCESS, 0 + StatsStatus.add_item :E_NOSUCHNODE, 1 + StatsStatus.add_item :E_NOSUCHDEVICE, 2 + StatsStatus.add_item :E_NOSUCHCOUNTER, 3 + StatsStatus.add_item :E_UNKNOWN, 99 + +end diff --git a/wui/src/app/util/stats/statsTest.rb b/wui/src/app/util/stats/statsTest.rb index f7ce612..4978b43 100644 --- a/wui/src/app/util/stats/statsTest.rb +++ b/wui/src/app/util/stats/statsTest.rb @@ -31,10 +31,11 @@ require 'util/stats/Stats' # requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Load, 0, LoadCounter::Load_1min, 0, 3600, 10 ) # requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Load, 0, LoadCounter::Load_1min, 0, 0, RRDResolution::Long ) # requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Load, 0, LoadCounter::Load_15min, 0, 0, RRDResolution::Long ) -# requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::NIC, 0, NicCounter::Octets_rx, 0, 0, RRDResolution::Long ) -# requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::NIC, 0, NicCounter::Octets_tx, 0, 0, RRDResolution::Long ) - requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Disk, 0, DiskCounter::Octets_read, 0, 0, RRDResolution::Long ) - requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Disk, 0, DiskCounter::Octets_write, 0, 0, RRDResolution::Long ) + requestList << StatsRequest.new("node7.priv.ovirt.org", DevClass::NIC, 0, NicCounter::Octets_rx, 0, 0, RRDResolution::Long ) + requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::NIC, 1, NicCounter::Octets_rx, 0, 0, RRDResolution::Long ) + requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::NIC, 0, NicCounter::Octets_tx, 0, 0, RRDResolution::Long ) +# requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Disk, 0, DiskCounter::Octets_read, 0, 0, RRDResolution::Long ) +# requestList << StatsRequest.new("node3.priv.ovirt.org", DevClass::Disk, 0, DiskCounter::Octets_write, 0, 0, RRDResolution::Long ) # requestList << StatsRequest.new("node3.priv.ovirt.org", "cpu", 0, "idle", 1211688000, 3600, 10 ) # requestList << StatsRequest.new("node4.priv.ovirt.org", DevClass::CPU, 0, CpuCounter::Idle, 0, 3600, RRDResolution::Short ) # requestList << StatsRequest.new("node5.priv.ovirt.org", "cpu", 0, "idle", 1211688000, 3600, 500 ) @@ -55,8 +56,14 @@ require 'util/stats/Stats' myDevClass = statsList.get_devClass?() myInstance = statsList.get_instance?() myCounter = statsList.get_counter?() + myStatus = statsList.get_status?() - + case myStatus + when StatsStatus::E_NOSUCHNODE + puts "Can't find data for node " + myNodeName + when StatsStatus::E_UNKNOWN + puts "Can't find data for requested file path" + end if tmp != myNodeName then puts end -- 1.5.4.5
Mohammed Morsi
2008-Jun-06 14:50 UTC
[ovirt-devel][PATCH] Add Status and error handling to Stats stuff
Attached is the my patch that uses Mark's error checking in the WUI to ignore unsuccessful operations. -Mo -------------- next part -------------- A non-text attachment was scrubbed... Name: graphs-exceptions.patch Type: text/x-patch Size: 15885 bytes Desc: not available URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20080606/fbb96c86/attachment.bin>
Chris Lalancette
2008-Jun-06 15:56 UTC
[ovirt-devel][PATCH] Add Status and error handling to Stats stuff
mark wagner wrote:> Added code to check validity of pathname to rrdfile. > Added new enum for StatsStatus > Added new member to StatsDataList to hold status information > --- > wui/src/app/util/stats/Stats.rb | 36 ++++++++++++++++++++++-------- > wui/src/app/util/stats/StatsDataList.rb | 7 +++++- > wui/src/app/util/stats/StatsTypes.rb | 21 ++++++++++++++++++ > wui/src/app/util/stats/statsTest.rb | 17 ++++++++++---- > 4 files changed, 65 insertions(+), 16 deletions(-)We hashed this out on IRC, but I asked the question of: what gets displayed in the host details after this patch? If there is no data, then we should just display all 0's. The important part is not to error. mmorsi says that's what happens at the moment, so I think he is just going to add a slight patch to log to the log file. Assuming that is the case, and the extra little patch goes in with this, ACK from me. Chris Lalancette