This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "YaST web service".
The branch, master has been updated
via b26fec308d7cb1e2b6d9eecc22dd9023dce0ae59 (commit)
from 85c30f654261f5e9f2a31df97468f828df77f270 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b26fec308d7cb1e2b6d9eecc22dd9023dce0ae59
Author: Bjoern Geuken
Date: Fri Jul 3 15:14:12 2009 +0200
status module: * fixed some hardcoded methods/variables
* added Readme
-----------------------------------------------------------------------
Summary of changes and diff:
plugins/status/README | 18 +++++++++++
plugins/status/app/models/status.rb | 55 ++++++++++++++++++++--------------
2 files changed, 50 insertions(+), 23 deletions(-)
create mode 100644 plugins/status/README
diff --git a/plugins/status/README b/plugins/status/README
new file mode 100644
index 0000000..b95ad0a
--- /dev/null
+++ b/plugins/status/README
@@ -0,0 +1,18 @@
+Status
+=========
+
+REST interface for handling collectd/grabbing system information.
+
+Installation:
+-------------
+
+1. Add the Status-policy-file
+
+ sudo cp status/package/org.opensuse.yast.system.status.policy /usr/share/PolicyKit/policy
+
+2. Install rrdtool and collectd packages. You can get them from http://software.opensuse.org/search
+
+3. Start the rest-service
+
+Copyright (c) 2009 Novell, released under the MIT license
+
diff --git a/plugins/status/app/models/status.rb b/plugins/status/app/models/status.rb
index 5f7196c..ecc3fcc 100644
--- a/plugins/status/app/models/status.rb
+++ b/plugins/status/app/models/status.rb
@@ -1,6 +1,6 @@
class Status
require 'scr'
-
+=begin
def to_xml(options = {})
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]
@@ -9,6 +9,26 @@ class Status
xml.tag!(:memory, @memory)
end
end
+=end
+
+ def to_xml(options = {})
+ xml = options[:builder] ||= Builder::XmlMarkup.new(options)
+ xml.instruct! unless options[:skip_instruct]
+
+ xml.status do
+# @data.each_pair do |key, value|
+# @data.each do |m|
+ @data.each_pair do |m, n|
+ @data["#{m}"].each_pair do |key, value|
+# @data["#{m}"]["#{key}"].each do |v|
+ xml.tag!("#{key}", "#{value}")
+# end
+ end
+ end
+ end
+# end
+#@data
+ end
def initialize
@scr = Scr.instance
@@ -19,6 +39,7 @@ class Status
@timestamp = Time.now #nil
# @collectd_base_dir = "/var/lib/collectd/"
@datapath = set_datapath
+ @metrics = available_metrics
end
def start_collectd
@@ -31,6 +52,7 @@ class Status
@timestamp = nil
end
+ # set path of stored rrd files, default: /var/lib/collectd/$host.$domain
def set_datapath(path=nil)
default = "/var/lib/collectd/"
unless path.nil?
@@ -43,15 +65,11 @@ class Status
@datapath
end
- def reset_datapath(path)
- @datapath = "/var/lib/collectd/#{host}"
- end
-
def available_metrics
metrics = Hash.new
cmd = Scr.instance.execute(["ls", "#{@datapath}"])
cmd[:stdout].split(" ").each do |l|
- files = Scr.instance.execute(["ls", "#{@datapath}#{l}"])
+ files = Scr.instance.execute(["ls", "#{@datapath}/#{l}"])
metrics["#{l}"] = { :rrds => files[:stdout].split(" ")}
end
metrics
@@ -62,9 +80,6 @@ class Status
lines = cmd[:stdout].split "\n"
end
- def update
- end
-
def determine_status
end
@@ -72,33 +87,27 @@ class Status
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?
- data.each do |d|
- case d
- when "cpu"
-# @cpu = fetch_metric("cpu-0/cpu-idle.rrd", "16:18,07/02/2009", "16:19,07/02/2009")
- @cpu = fetch_metric("/cpu-0/cpu-idle.rrd", start, stop)
- when "memory"
-# @memory = fetch_metric("memory/memory-free.rrd", "16:18,07/02/2009", "16:19,07/02/2009")
- @memory = fetch_metric("/memory/memory-free.rrd", start, stop)
- when "disk"
- #fetch_metric
+ @metrics.each_pair do |m, n|
+ @metrics["#{m}"][:rrds].each do |rrdb|
+ @data["#{m}"] = {"#{rrdb}" => fetch_metric("#{m}/#{rrdb}", start, stop)}
end
end
end
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
- cmd = @scr.execute(["rrdtool", "fetch", "#{@datapath}#{rrdfile}", "AVERAGE",\
+ cmd = @scr.execute(["rrdtool", "fetch", "#{@datapath}/#{rrdfile}", "AVERAGE",\
"--start"," #{start}", "--end", " #{stop}"])
lines = cmd[:stdout].split "\n"
lines.each do |l|
- l.to_s.strip
- unless l.blank? or l.include?("value")
+ if l =~ /\D*:\D*/
pair = l.split ":"
unless pair[1].include?("nan") # no valid measurement
sum += pair[1].to_f
@@ -106,6 +115,6 @@ class Status
end
end
end
- sum/(counter-1)
+ sum/(counter-1) unless sum == 0
end
end
hooks/post-receive
--
YaST web service
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org