netdata-client 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8171602fe100225682a866be89d6670d825847ee
4
- data.tar.gz: b23deb081fe6502ce501d0d81b980a90e4244eed
3
+ metadata.gz: 98909afdec410b912d32322eb69a25308d26cb64
4
+ data.tar.gz: b3fd0a0da36948ea9e825ed78b8f3c3684f535dd
5
5
  SHA512:
6
- metadata.gz: 61ff2f57377312fe4adf9eb99f6bc4334342bd607ab6c4585076e8267c7f375d383c11a552bdcaf78554d3430d787292d03ae2eda73086e77314b5606ea5204f
7
- data.tar.gz: fd23f25cde337bf43050901b879a6f4708a44a96049a6b394a252ffea7c3bd9438c4bfbe68cba2c0d663a39319e832e4ec548763cc84fd0169e6724e3e3c99a2
6
+ metadata.gz: 15e94291b79e885ea9fa105a8dfb4f0180254b1d0e16206f388ab2ca2042aa0b712050425d19f7740b83e658e959df91f9fb05986ee5987f9f9f111f340567b1
7
+ data.tar.gz: 288114bb9add9eb929f79386d59f017eee038fb27b4547db68593be1a5805e861fc1702c190181e59947207cc5cf16cd0550bd7292ae2f4512ba0050f34c1eaf
@@ -17,10 +17,55 @@ module Netdata
17
17
 
18
18
  return unless alarms
19
19
 
20
- alarms_resp = JSON.parse(alarms.body)
20
+ alarms_resp = parse_alarms(JSON.parse(alarms.body))
21
21
 
22
22
  # system CPU stats
23
- cpu_opts = {
23
+ cpu_value = get_cpu(url)
24
+
25
+ # CPU on a per-user basis
26
+ users_cpu_value_history, users_cpu_value, users_cpu_users = get_cpu_users(url)
27
+
28
+ aggregator[alarms_resp["hostname"]] = {}
29
+ aggregator[alarms_resp["hostname"]][:cpu] = cpu_value
30
+ aggregator[alarms_resp["hostname"]][:users_cpu] = { users: users_cpu_users, value: users_cpu_value, history: users_cpu_value_history.select { |val| val > threshold } }
31
+ aggregator[alarms_resp["hostname"]][:alarms] = alarms_resp unless alarms_resp["alarms"].nil?
32
+ end
33
+
34
+ pp aggregator
35
+
36
+ aggregator.each_pair do |host, data|
37
+ # new thread for each host so we can see mulitple notifications
38
+ Thread.new {
39
+ message = ""
40
+ message += "CPU Warning - #{data[:cpu].round(2)}%\n" if data[:cpu] > threshold
41
+ message += "#{data[:users_cpu][:users].size} system users active (#{data[:users_cpu][:value].round(2)}% CPU)\n" if data[:users_cpu][:value] > threshold
42
+ message += "Alarms are ringing\n" if data[:alarms]
43
+ message += "#{data[:users_cpu][:history].size} CPU instance(s) > #{threshold}%\n" if data[:users_cpu][:history].size > 0
44
+
45
+ Notify.bubble(message, "Netdata Warning on #{host}") if message.size > 0
46
+ }.join
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def parse_alarms(data)
53
+ out = data.dup
54
+ out["alarms"] = nil
55
+
56
+ return {} if data["alarms"].empty?
57
+
58
+ data['alarms'].each do |alarm|
59
+ alarm_name = alarm[0]
60
+ alarm_value = alarm[1]
61
+ out["alarms"] = alarm_value unless alarm_value["recipient"] == 'silent'
62
+ end
63
+
64
+ out
65
+ end
66
+
67
+ def get_cpu(url)
68
+ cpu_opts = {
24
69
  "chart" => "system.cpu",
25
70
  "format" => "array",
26
71
  "points" => 54,
@@ -30,9 +75,10 @@ module Netdata
30
75
  }
31
76
  cpu = @network.get("data", url, cpu_opts)
32
77
  cpu_value = JSON.parse(cpu.body)["result"].first
78
+ end
33
79
 
34
- # CPU on a per-user basis
35
- users_cpu_opts = {
80
+ def get_cpu_users(url)
81
+ users_cpu_opts = {
36
82
  "chart" => "users.cpu",
37
83
  "format" => "array",
38
84
  "points" => 54,
@@ -46,26 +92,7 @@ module Netdata
46
92
  users_cpu_value_history = users_cpu_resp["result"][0..119]
47
93
  users_cpu_users = users_cpu_resp["dimension_names"]
48
94
 
49
- aggregator[alarms_resp["hostname"]] = {}
50
- aggregator[alarms_resp["hostname"]][:cpu] = cpu_value
51
- aggregator[alarms_resp["hostname"]][:users_cpu] = { users: users_cpu_users, value: users_cpu_value, history: users_cpu_value_history.select { |val| val > threshold } }
52
- aggregator[alarms_resp["hostname"]][:alarms] = alarms_resp unless alarms_resp["alarms"].empty?
53
- end
54
-
55
- pp aggregator
56
-
57
- aggregator.each_pair do |host, data|
58
- # new thread for each host so we can see mulitple notifications
59
- Thread.new {
60
- message = ""
61
- message += "CPU Warning - #{data[:cpu].round(2)}%\n" if data[:cpu] > threshold
62
- message += "#{data[:users_cpu][:users].size} system users active (#{data[:users_cpu][:value].round(2)}% CPU)\n" if data[:users_cpu][:value] > threshold
63
- message += "Alarms are ringing" if data[:alarms]
64
- message += "#{data[:users_cpu][:history].size} CPU instance(s) > #{threshold}%" if data[:users_cpu][:history].size > 0
65
-
66
- Notify.bubble(message, "Netdata Warning on #{host}") if message.size > 0
67
- }.join
68
- end
95
+ [users_cpu_value_history, users_cpu_value, users_cpu_users]
69
96
  end
70
97
  end
71
98
  end
@@ -1,5 +1,5 @@
1
1
  module Netdata
2
2
  module Client
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netdata-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe