Class: Netdata::Client::Controller
- Inherits:
-
Object
- Object
- Netdata::Client::Controller
- Defined in:
- lib/netdata/client/controller.rb
Instance Method Summary collapse
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #report_interval_2_mins ⇒ Object
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
4 5 6 7 8 |
# File 'lib/netdata/client/controller.rb', line 4 def initialize @network = Helper::Network.new @aggregator = Helper::DataAggregator.new @config = ::YAML::load_file(File.('~/.netdatacli.yml')) end |
Instance Method Details
#report_interval_2_mins ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/netdata/client/controller.rb', line 10 def report_interval_2_mins aggregator = {} threshold = 70 # numbers higher than this should trigger notifications return unless @config @config["instances"].each do |url| alarms = @network.get('alarms', url, {}) return unless alarms alarms_resp = @aggregator.parse_alarms(JSON.parse(alarms.body)) # CPU on a per-user basis users_cpu_value_history, users_cpu_value, users_cpu_users = @aggregator.get_cpu_users(url) aggregator[alarms_resp['hostname']] = {} aggregator[alarms_resp['hostname']][:cpu] = @aggregator.get_cpu(url) aggregator[alarms_resp['hostname']][:users_cpu] = { users: users_cpu_users, value: users_cpu_value, history: users_cpu_value_history.select { |val| val > threshold } } aggregator[alarms_resp['hostname']][:alarms] = alarms_resp unless alarms_resp['alarms'].nil? end pp aggregator aggregator.each_pair do |host, data| # new thread for each host so we can see mulitple notifications Thread.new { = '' += "CPU Warning - #{data[:cpu].round(2)}%\n" if data[:cpu] > threshold += "#{data[:users_cpu][:users].size} system users active (#{data[:users_cpu][:value].round(2)}% CPU)\n" if data[:users_cpu][:value] > threshold += "Alarms are ringing\n" if data[:alarms] += "#{data[:users_cpu][:history].size} CPU instance(s) > #{threshold}%\n" if data[:users_cpu][:history].size > 4 Notify.bubble(, "Netdata Warning on #{host}") if .size > 0 }.join end end |