Sha256: 40b7cc927ec54ab3e47d81bf26191ac263dd6abc10f37f7c2ca396db11033fc0

Contents?: true

Size: 706 Bytes

Versions: 11

Compression:

Stored size: 706 Bytes

Contents

class CPUUsage
	
	include Watchman
	
	set_default :usage_threshold, 60
	
	def self.data
		out = MPstat.data.select do |line|
			line[:run][/^Average:/]
		end
		out.length > 0 ? out.first.merge({:summary => [:usr, :idle, :sys]}) : {:nodata => true}
	end
	
	add_rule(:cpu_usage_high) do |data|
		
		if (usage = data[:usr].to_i) && usage > option(:usage_threshold)
			send_alert "CPU usage is over #{option(:usage_threshold)}% (#{usage}%)", data
			set_flag :cpu_usage_high
		else
			clear_flag :cpu_usage_high
		end
		
	end
	
	dataset(:save_dataset) do |data|
		add_to_data_set(:cpu_user,data[:usr].to_f)
		add_to_data_set(:cpu_idle,data[:idle].to_f)
		add_to_data_set(:cpu_system,data[:sys].to_f)
	end
	
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
city-watch-0.7.9 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.8 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.7 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.6 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.5 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.4 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.3 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.2 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.1 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.7.0 lib/city_watch/watchmen/cpu_usage.rb
city-watch-0.6.9 lib/city_watch/watchmen/cpu_usage.rb