Sha256: ca8a17332402ac971d6ab33d9fb9c64e8b56ff75ff8d5c1d9e458a66886728a0
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
# An example SignalProcessor that generates a graph of the last 60 reported # SystemLoad signals. # # It's pretty naff - it doesn't do any sort of time bounding so I can't say # that the graph is of the last 60 minutes or anything, but it's certainly # possible to do so if you fancy recording the timestamp that came in with # the report. # # Remember, if you're doing any heavy lifting such as generating images do # push that work off into another Thread to avoid blocking the current thread. # require 'rubygems' require 'scruffy' module Smoke class SystemLoadProcessor < Smoke::SignalProcessor def initialize(*args) super @load = [] 0.upto(59) do |n| @load[n] = [0, 0, 0] end # Generate a load graph every 60 seconds. Thread.new(@load) do |load| loop do begin graph = Scruffy::Graph.new(:title => "Load Average") graph.value_formatter = Scruffy::Formatters::Number.new(:precision => 2) graph.add(:area, ' 1min', load.collect { |sample| sample[0] }, :opacity => 0.5) graph.add(:area, ' 5min', load.collect { |sample| sample[1] }, :opacity => 0.5) graph.add(:area, '15min', load.collect { |sample| sample[2] }, :opacity => 0.5) graph.render(:min_value => 0, :max_value => 1.00, :width => 700, :as => 'PNG', :to => 'load_average.png') sleep 60 rescue => e STDERR.puts e.message + ":\n\n" + e.backtrace.join("\n") + "\n\n" end end end end def process(signal) @load.shift load_averages = [ signal["report"]["one_minute"], signal["report"]["five_minutes"], signal["report"]["fifteen_minutes"] ] @load.push load_averages end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
smoke-0.0.3 | contrib/processors/smoke/system_load_processor.rb |