Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : status module: group output into cpu, memory,..
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Mon, 6 Jul 2009 14:57:38 +0200
  • Message-id: <E1MNnnu-000642-4h@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 0e92dc69155eb720ed40e4bd3609a03f18820d14
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Mon Jul 6 14:57:38 2009 +0200

status module: group output into cpu, memory,..
---
plugins/status/app/models/status.rb | 58 +++++++++++---------------
plugins/status/app/views/status/show.xml.erb | 2 +-
2 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/plugins/status/app/models/status.rb
b/plugins/status/app/models/status.rb
index 023474e..4036884 100644
--- a/plugins/status/app/models/status.rb
+++ b/plugins/status/app/models/status.rb
@@ -1,27 +1,8 @@
-class Status #< ActiveRecord::Base
+class Status < ActiveRecord::Base
require 'scr'

attr_accessor :data

-
- def to_xml(options = {})
- xml = options[:builder] ||= Builder::XmlMarkup.new(options)
- xml.instruct! unless options[:skip_instruct]
-
- xml.status do
- @data.each_pair do |branch, n|
- #xml.branch
- leaf = @data["#{branch}"].split "|"
- leaf.each do |p|
- pair = p.split "=>"
- pair.each do |key, value|
- xml.tag!("#{pair[0]}", "#{pair[1]}")
- end
- end
- end
- end
- end
-
def initialize
@scr = Scr.instance
@health_status = nil
@@ -78,38 +59,47 @@ class Status #< ActiveRecord::Base
def draw_graph(heigth=nil, width=nil)
end

- #wieviele cpus?
# creates several metrics for a defined period
def collect_data(start=Time.now, stop=Time.now, data = %w{cpu memory disk})
-# def collect_data(start="16:18,07/02/2009", stop="16:19,07/02/2009",
data=%w{cpu memory disk})
- unless @timestamp.nil?
+ result = Hash.new
+ unless @timestamp.nil? # collectd not started
@metrics.each_pair do |m, n|
@metrics["#{m}"][:rrds].each do |rrdb|
- value = fetch_metric("#{m}/#{rrdb}", start, stop)
- @data["#{m}"] = "#{@data["#{m}"]}|#{rrdb.chomp(".rrd")}=>#{value}"
- # @data["#{m}"]["#{rrdb}"] = fetch_metric("#{m}/#{rrdb}", start, stop)
+ result["#{rrdb}".chomp(".rrd")] = fetch_metric("#{m}/#{rrdb}",
start, stop)
end
+ @data["#{m}"] = result
+ result = Hash.new
end
end
-@data
+ @data
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 = 1
+ result = Hash.new#Array.new
cmd = @scr.execute(["rrdtool", "fetch", "#{@datapath}/#{rrdfile}",
"AVERAGE",\
"--start"," #{start}", "--end", "
#{stop}"])
lines = cmd[:stdout].split "\n"
- lines.each do |l|
- if l =~ /\D*:\D*/
- pair = l.split ":"
- unless pair[1].include?("nan") # no valid measurement
- sum += pair[1].to_f
- counter += 1
+ 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
+ result[labels[collumn-1]] = sum/(counter-1) unless counter == 1
end
end
end
- sum/(counter-1) unless sum == 0
+ result
end
end
diff --git a/plugins/status/app/views/status/show.xml.erb
b/plugins/status/app/views/status/show.xml.erb
index 2cc15b8..e02050f 100644
--- a/plugins/status/app/views/status/show.xml.erb
+++ b/plugins/status/app/views/status/show.xml.erb
@@ -1,2 +1,2 @@
-<%= @status.to_xml( :root => "status", :dasherize => false ) -%>
+<%= @status.data.to_xml( :root => "status", :dasherize => false ) -%>

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages