Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : status module: fixed evaluation of intervals for metrics
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Mon, 31 Aug 2009 12:49:45 +0200
  • Message-id: <E1MiTqS-0006la-AE@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit 7fd7a8616e46b77b97d668b6782283864d32295b
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Mon Aug 31 12:49:45 2009 +0200

status module: fixed evaluation of intervals for metrics
---
plugins/status/lib/status.rb | 33 ++++++++++++------------------
plugins/status/test/unit/status_test.rb | 3 +-
2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/plugins/status/lib/status.rb b/plugins/status/lib/status.rb
index 8628dde..58b7344 100644
--- a/plugins/status/lib/status.rb
+++ b/plugins/status/lib/status.rb
@@ -9,9 +9,8 @@ class Status
:health_status,
:metrics,
:limits
-#=begin
+
def to_xml(options = {})
-# puts @limits.inspect
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]

@@ -20,7 +19,7 @@ class Status
data.each {|metric, data|
xml.metric(:name => metric, :metricgroup => metric_group) do
xml.starttime(@data[metric_group][metric]["starttime"])
- xml.interval(5)
+ xml.interval(@data[metric_group][metric]["interval"])
data.each {|label,data|
unless label == "starttime" or label == "interval"
xml.label(:type => "hash", :name => label) do
@@ -201,43 +200,37 @@ class Status
end
unless labels.blank?
# set values for each label and time
+ # evaluates interval and starttime once for each metric (not each label)
+ nexttime = 9.9e+99
+ result["starttime"] = 9.9e+99
lines.each do |l| # each time
unless l.blank?
if l =~ /\d*:\D*/
pair = l.split ":"
values = pair[1].split " "
- #puts pair[1]
column = 0
values.each do |v| # each label
- result["starttime"] ||= pair[0]
- result["starttime"] = pair[0] if pair[0].to_i <
result["starttime"].to_i
- nexttime =
+ if result["interval"].nil?
+ if pair[0].to_i < result["starttime"].to_i
+ result["starttime"] = pair[0].to_i
+ elsif pair[0].to_i < nexttime and pair[0].to_i >
result["starttime"].to_i
+ nexttime = pair[0].to_i
+ end
+ end

if v != "nan" #store valid values only
result["#{labels[column]}"] ||= Hash.new
-# result["#{labels[column]}"].merge!(v)
result["#{labels[column]}"].merge!({"#{pair[0].chomp(": ")}"
=> v})
- #result["#{labels[column]}"].merge!({"T_#{pair[0].chomp(":
")}" => v})
column += 1
else
result["#{labels[column]}"] ||= Hash.new
-# result["#{labels[column]}"].merge!("invalid")
result["#{labels[column]}"].merge!({"#{pair[0].chomp(": ")}"
=> "invalid"})
end
end
end
end
end
- #setting the limits
-# result.each do |key, value|
-# path = rrdfile[datapath.length+1..rrdfile.length-1].chomp('.rrd')
-# path +="/" + key if key!="value" #do not take care about the value
flag
-# path = path.tr('-','_')
-# if @limits.has_key?(path)
-# result[key] ||= Hash.new
-# result[key].merge!({"limit" => @limits[path] })
-# end
-# end
+ result["interval"] = nexttime.to_i - result["starttime"].to_i if
result["interval"].nil?
return result
else
raise "error reading data from rrdtool"
diff --git a/plugins/status/test/unit/status_test.rb
b/plugins/status/test/unit/status_test.rb
index 26c61dd..06eb93b 100644
--- a/plugins/status/test/unit/status_test.rb
+++ b/plugins/status/test/unit/status_test.rb
@@ -115,7 +115,8 @@ EOF
"1248092930"=>"2.5092857143e+01",
"1248092160"=>"invalid",
"1248092370"=>"4.7314285714e+01"},
- "starttime"=>"1248092090"}
+ "interval"=>70,
+ "starttime"=>1248092090}

assert_equal expected_response,
status.fetch_metric("/var/lib/collectd/test/memory-free.rrd", start, stop)
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages