netdata-client 1.1.0 → 1.2.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: 5a38a94059003109a2522eef8d8a22b6122aeae8
4
- data.tar.gz: fe162ff418f3ce9f94f2e0a37913e5e923eb27e7
3
+ metadata.gz: 8171602fe100225682a866be89d6670d825847ee
4
+ data.tar.gz: b23deb081fe6502ce501d0d81b980a90e4244eed
5
5
  SHA512:
6
- metadata.gz: 9042ec3a4ab22529e4181bf544f995b3cd2dd024e08e36a80f2bc3920efcf3648a019702fa0cfe44637ecfd782cd7fd46de925ac80e275f4ab169d0ff4f36e7b
7
- data.tar.gz: bd4f068fb240f3044b9d3f6872e659bdaa129a9e959a39a3be62efc580f2f79f81d32a6c05b46e0cbda9844a504f65e35ba8d7f9960a3d5f8765aeab9d93223a
6
+ metadata.gz: 61ff2f57377312fe4adf9eb99f6bc4334342bd607ab6c4585076e8267c7f375d383c11a552bdcaf78554d3430d787292d03ae2eda73086e77314b5606ea5204f
7
+ data.tar.gz: fd23f25cde337bf43050901b879a6f4708a44a96049a6b394a252ffea7c3bd9438c4bfbe68cba2c0d663a39319e832e4ec548763cc84fd0169e6724e3e3c99a2
data/README.md CHANGED
@@ -24,7 +24,7 @@ instances:
24
24
 
25
25
  If you're using OSX > 10.4:
26
26
 
27
- 1. Rename `com.netdata.monitor.plist.dist` to `com.netdata.monitor.plist` and update the ProgramArguments value to point to where the gem lives (i.e. `/Library/Ruby/Gems/2.0.0`).
27
+ 1. Rename `com.netdata.monitor.2mins.plist.dist` to `com.netdata.monitor.2mins.plist` and update the ProgramArguments value to point to where the gem lives (i.e. `/Library/Ruby/Gems/2.0.0`).
28
28
  2. `cp com.netdata.monitor.plist /Library/LaunchDaemons`
29
29
  3. `launchtl load -w /Library/LaunchDaemons/com.netdata.monitor.plist`
30
30
 
@@ -8,8 +8,11 @@
8
8
  <key>ProgramArguments</key>
9
9
  <array>
10
10
  <string>/Library/Ruby/Gems/2.0.0/gems/netdatacli</string>
11
+ <string>-m</string>
11
12
  </array>
12
13
  <key>StartInterval</key>
13
14
  <integer>120</integer>
15
+ <key>RunAtLoad</key>
16
+ <true/>
14
17
  </dict>
15
18
  </plist>
data/exe/netdatacli CHANGED
@@ -3,6 +3,18 @@ lib = File.expand_path('../../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  require "netdata/client"
6
+ require "optparse"
7
+
8
+ main = false
9
+
10
+ OptionParser.new do |opt|
11
+ # opt.banner = "netdatacli [...flags]"
12
+
13
+ opt.on("-m", "--2min", "Trigger the 2 minute actions") { |o| main = true }
14
+ end.parse!
6
15
 
7
16
  client = Netdata::Client::Controller.new
8
- client.check
17
+
18
+ if main
19
+ client.report_interval_2_mins
20
+ end
@@ -6,8 +6,9 @@ module Netdata
6
6
  @config = ::YAML::load_file(File.expand_path("~/.netdatacli.yml"))
7
7
  end
8
8
 
9
- def check
9
+ def report_interval_2_mins
10
10
  aggregator = {}
11
+ threshold = 50 # numbers higher than this should trigger notifications
11
12
 
12
13
  return unless @config
13
14
 
@@ -42,12 +43,13 @@ module Netdata
42
43
  users_cpu = @network.get("data", url, users_cpu_opts)
43
44
  users_cpu_resp = JSON.parse(users_cpu.body)
44
45
  users_cpu_value = users_cpu_resp["result"].first
46
+ users_cpu_value_history = users_cpu_resp["result"][0..119]
45
47
  users_cpu_users = users_cpu_resp["dimension_names"]
46
48
 
47
49
  aggregator[alarms_resp["hostname"]] = {}
48
- aggregator[alarms_resp["hostname"]]["cpu"] = cpu_value
49
- aggregator[alarms_resp["hostname"]]["users_cpu"] = { "users" => users_cpu_users, "value" => users_cpu_value }
50
- aggregator[alarms_resp["hostname"]]["alarms"] = alarms_resp unless alarms_resp["alarms"].empty?
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?
51
53
  end
52
54
 
53
55
  pp aggregator
@@ -56,9 +58,10 @@ module Netdata
56
58
  # new thread for each host so we can see mulitple notifications
57
59
  Thread.new {
58
60
  message = ""
59
- message += "CPU Warning - #{data["cpu"].round(2)}%\n" if data["cpu"] > 50
60
- message += "#{data['users_cpu']['users'].size} system users active (#{data["users_cpu"]["value"].round(2)}% CPU)\n" if data["users_cpu"]["value"] > 50
61
- message += "Alarms are ringing" if data["alarms"]
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
62
65
 
63
66
  Notify.bubble(message, "Netdata Warning on #{host}") if message.size > 0
64
67
  }.join
@@ -1,5 +1,5 @@
1
1
  module Netdata
2
2
  module Client
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netdata-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: notifaction