Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : status module: now resst sends all values of rrd file in the form
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Tue, 7 Jul 2009 15:53:33 +0200
  • Message-id: <E1MOB87-0002UB-NX@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 2af79471cbd20121cafdf233bbee0b29cae9f579
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Tue Jul 7 15:53:33 2009 +0200

status module: now resst sends all values of rrd file in the form
<$Time>$value</$Time>
<$Time>....
---
.../status/app/controllers/status_controller.rb | 2 +-
plugins/status/app/models/status.rb | 35 ++++++++++---------
2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/plugins/status/app/controllers/status_controller.rb
b/plugins/status/app/controllers/status_controller.rb
index 9293cbe..c47ad9a 100644
--- a/plugins/status/app/controllers/status_controller.rb
+++ b/plugins/status/app/controllers/status_controller.rb
@@ -33,7 +33,7 @@ class StatusController < ApplicationController
else
@status = Status.new
# @status.collect_data(params[:start], params[:stop])
- @status.collect_data("11:13,07/03/2009", "11:14,07/03/2009", %w{cpu
disk})
+ @status.collect_data("11:13,07/03/2009", "11:14,07/03/2009", %w{cpu
memory disk})

end
end
diff --git a/plugins/status/app/models/status.rb
b/plugins/status/app/models/status.rb
index 4769773..b3eca62 100644
--- a/plugins/status/app/models/status.rb
+++ b/plugins/status/app/models/status.rb
@@ -80,7 +80,7 @@ class Status < ActiveRecord::Base
@data["#{m}"] = result
result = Hash.new
end
- else
+ else # only metrics in data
data.each do |d|
@metrics.each_pair do |m, n|
if m.include?(d)
@@ -98,34 +98,35 @@ class Status < ActiveRecord::Base
end

# creates one metric for defined period
- def fetch_metric(rrdfile, start=Time.now, stop=Time.now)#, heigth=nil,
width=nil)
- sum = 0.0
- counter = 0
+ def fetch_metric(rrdfile)#, start=Time.now, stop=Time.now)#, heigth=nil,
width=nil)
result = Hash.new#Array.new
cmd = IO.popen("rrdtool fetch #{@datapath}/#{rrdfile} AVERAGE "\
"--start #{start} --end #{stop}")
output = cmd.read
cmd.close

- output = output.gsub(",", ".") # translate 1,234e+07 to 1.234e+07
+ labels=""
+ output = output.gsub(",", ".") # translates eg. 1,234e+07 to 1.234e+07
lines = output.split "\n"
lines[0].each do |l|
if l =~ /\D*/
labels = l.split " "
- collumn = 1
- labels.each do
- lines.each do |l|
- if l =~ /\d*:\D*/ ####
- pair = l.split " "
- unless pair[collumn].include?("nan") # no valid measurement
- sum += pair[collumn].to_f
- counter += 1
- end
+ end
+ end
+ lines.each do |l|
+ if l =~ /\d*:\D*/ ####
+ unless labels.nil?
+ if l =~ /\d*:\D*/ ####
+ sum = Hash.new
+ pair = l.split ":"
+ values = pair[1].split " "
+ column = 0
+ values.each do |v| # values for each label
+ result["#{labels[column]}"] ||= Hash.new
+ result["#{labels[column]}"].merge!({"T_#{pair[0].chomp(": ")}"
=> v})
+ column += 1
end
end
- result[labels[collumn-1]] = sum/(counter) unless counter == 0
- sum, counter = 0.0, 0
- collumn += 1
end
end
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