Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : status module: cleanup code
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Tue, 7 Jul 2009 16:29:34 +0200
  • Message-id: <E1MOBfk-0002xy-QN@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 8987fc07e1945a10bc5e70eca08bd0996f7d50f0
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Tue Jul 7 16:29:34 2009 +0200

status module: cleanup code
---
.../status/app/controllers/status_controller.rb | 6 +++---
plugins/status/app/models/status.rb | 11 ++++++-----
2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/plugins/status/app/controllers/status_controller.rb
b/plugins/status/app/controllers/status_controller.rb
index c47ad9a..c57f1bd 100644
--- a/plugins/status/app/controllers/status_controller.rb
+++ b/plugins/status/app/controllers/status_controller.rb
@@ -13,7 +13,7 @@ class StatusController < ApplicationController
render ErrorResult.error(403, 1, "no permission") and return
else
@status = Status.new
- @status.collect_data(params[:start], params[:stop])
+ @status.collect_data(params[:start], params[:stop], params[:data])
#logger.debug "SHOW: #{@status.inspect}"

end
@@ -32,8 +32,8 @@ class StatusController < ApplicationController
render ErrorResult.error(403, 1, "no permission") and return
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
memory disk})
+ @status.collect_data(params[:start], params[:stop], params[:data])
+# @status.collect_data("11:13,07/02/2009", "11:14,07/07/2009", %w{cpu
memory disk})

end
end
diff --git a/plugins/status/app/models/status.rb
b/plugins/status/app/models/status.rb
index b3eca62..c91762a 100644
--- a/plugins/status/app/models/status.rb
+++ b/plugins/status/app/models/status.rb
@@ -68,11 +68,11 @@ class Status < ActiveRecord::Base
end

# creates several metrics for a defined period
- def collect_data(start=Time.now, stop=Time.now, data = nil)
+ def collect_data(start=Time.now, stop=Time.now, data = %w{cpu memory disk})
result = Hash.new
- unless @timestamp.nil? # collectd not started
+ unless @timestamp.nil? # collectd not start
case data
- when nil # all metrics
+ when nil, "all", "All" # all metrics
@metrics.each_pair do |m, n|
@metrics["#{m}"][:rrds].each do |rrdb|
result["#{rrdb}".chomp(".rrd")] = fetch_metric("#{m}/#{rrdb}",
start, stop)
@@ -98,12 +98,13 @@ 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)
- result = Hash.new#Array.new
+ def fetch_metric(rrdfile, start=Time.now, stop=Time.now)
+ result = Hash.new
cmd = IO.popen("rrdtool fetch #{@datapath}/#{rrdfile} AVERAGE "\
"--start #{start} --end #{stop}")
output = cmd.read
cmd.close
+ return nil if output.nil?

labels=""
output = output.gsub(",", ".") # translates eg. 1,234e+07 to 1.234e+07
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >