netdata-client 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/netdata/client/controller.rb +51 -24
- data/lib/netdata/client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98909afdec410b912d32322eb69a25308d26cb64
|
4
|
+
data.tar.gz: b3fd0a0da36948ea9e825ed78b8f3c3684f535dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
35
|
-
|
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
|
-
|
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
|