netdata-client 1.0.0 → 1.1.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/README.md +10 -2
- data/com.netdata.monitor.plist.dist +1 -1
- data/lib/netdata/client/controller.rb +38 -3
- data/lib/netdata/client/helper/network.rb +18 -6
- data/lib/netdata/client/version.rb +1 -1
- data/lib/netdata/client.rb +1 -0
- metadata +2 -4
- data/lib/netdata/client/custom_alarms.rb +0 -0
- data/lib/netdata/client/netdata_alarms.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a38a94059003109a2522eef8d8a22b6122aeae8
|
4
|
+
data.tar.gz: fe162ff418f3ce9f94f2e0a37913e5e923eb27e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9042ec3a4ab22529e4181bf544f995b3cd2dd024e08e36a80f2bc3920efcf3648a019702fa0cfe44637ecfd782cd7fd46de925ac80e275f4ab169d0ff4f36e7b
|
7
|
+
data.tar.gz: bd4f068fb240f3044b9d3f6872e659bdaa129a9e959a39a3be62efc580f2f79f81d32a6c05b46e0cbda9844a504f65e35ba8d7f9960a3d5f8765aeab9d93223a
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
`netdatacli` is a command line client intended to be run as a cron/launchd job. It will check your servers every 2 minutes and give you a desktop notification if certain conditions exist.
|
4
4
|
|
5
|
-
This is
|
5
|
+
This is a prototype. It will be rebuilt as an OSX/iOS app at some point in the future. Features I'm hoping to add at this stage include:
|
6
6
|
|
7
7
|
* Data aggregation between each report point (every 2 minutes). So you don't just get a notification about what is happening right now, but also what happened since the last check in (if anything).
|
8
8
|
* More datapoints. Currently it only supports system.cpu.
|
@@ -14,10 +14,18 @@ Installation:
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
+
First, create `~/.netdatacli.yml`. Populate it as follows.
|
18
|
+
|
19
|
+
```yml
|
20
|
+
instances:
|
21
|
+
http://my.instance.tld:19999
|
22
|
+
http://my.otherinstance.tld:19999
|
23
|
+
```
|
24
|
+
|
17
25
|
If you're using OSX > 10.4:
|
18
26
|
|
19
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`).
|
20
|
-
2. `cp com.netdata.monitor.plist /Library/LaunchDaemons
|
28
|
+
2. `cp com.netdata.monitor.plist /Library/LaunchDaemons`
|
21
29
|
3. `launchtl load -w /Library/LaunchDaemons/com.netdata.monitor.plist`
|
22
30
|
|
23
31
|
If using *nix:
|
@@ -12,21 +12,56 @@ module Netdata
|
|
12
12
|
return unless @config
|
13
13
|
|
14
14
|
@config["instances"].each do |url|
|
15
|
-
alarms = @network.get("alarms", url)
|
15
|
+
alarms = @network.get("alarms", url, {})
|
16
16
|
|
17
17
|
return unless alarms
|
18
18
|
|
19
19
|
alarms_resp = JSON.parse(alarms.body)
|
20
20
|
|
21
|
-
|
21
|
+
# system CPU stats
|
22
|
+
cpu_opts = {
|
23
|
+
"chart" => "system.cpu",
|
24
|
+
"format" => "array",
|
25
|
+
"points" => 54,
|
26
|
+
"group" => "average",
|
27
|
+
"options" => "absolute|jsonwrap|nonzero",
|
28
|
+
"after" => -540
|
29
|
+
}
|
30
|
+
cpu = @network.get("data", url, cpu_opts)
|
22
31
|
cpu_value = JSON.parse(cpu.body)["result"].first
|
23
32
|
|
33
|
+
# CPU on a per-user basis
|
34
|
+
users_cpu_opts = {
|
35
|
+
"chart" => "users.cpu",
|
36
|
+
"format" => "array",
|
37
|
+
"points" => 54,
|
38
|
+
"group" => "average",
|
39
|
+
"options" => "absolute|jsonwrap|nonzero",
|
40
|
+
"after" => -540
|
41
|
+
}
|
42
|
+
users_cpu = @network.get("data", url, users_cpu_opts)
|
43
|
+
users_cpu_resp = JSON.parse(users_cpu.body)
|
44
|
+
users_cpu_value = users_cpu_resp["result"].first
|
45
|
+
users_cpu_users = users_cpu_resp["dimension_names"]
|
46
|
+
|
24
47
|
aggregator[alarms_resp["hostname"]] = {}
|
25
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?
|
26
51
|
end
|
27
52
|
|
53
|
+
pp aggregator
|
54
|
+
|
28
55
|
aggregator.each_pair do |host, data|
|
29
|
-
|
56
|
+
# new thread for each host so we can see mulitple notifications
|
57
|
+
Thread.new {
|
58
|
+
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"]
|
62
|
+
|
63
|
+
Notify.bubble(message, "Netdata Warning on #{host}") if message.size > 0
|
64
|
+
}.join
|
30
65
|
end
|
31
66
|
end
|
32
67
|
end
|
@@ -9,17 +9,22 @@ module Netdata
|
|
9
9
|
# Params:
|
10
10
|
# +url+:: The URL you want to hit
|
11
11
|
# +key+:: The authentication key to pass via headers to the URL
|
12
|
-
def get(endpoint, url, version = "v1")
|
13
|
-
|
14
|
-
|
12
|
+
def get(endpoint, url, args, version = "v1")
|
13
|
+
qs = build_qs(args)
|
14
|
+
req_url = "#{url}/api/#{version}/#{endpoint}?#{qs}"
|
15
|
+
|
16
|
+
request(req_url, :GET)
|
15
17
|
end
|
16
18
|
|
17
19
|
# Perform a POST request to a specified URL
|
18
20
|
# Params:
|
19
21
|
# +url+:: The URL you want to hit
|
20
22
|
# +key+:: The authentication key to pass via headers to the URL
|
21
|
-
def post(url)
|
22
|
-
|
23
|
+
def post(endpoint, url, args, version = "v1")
|
24
|
+
qs = build_qs(args)
|
25
|
+
req_url = "#{url}/api/#{version}/#{endpoint}?#{qs}"
|
26
|
+
|
27
|
+
request(req_url, :POST)
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
@@ -29,7 +34,7 @@ module Netdata
|
|
29
34
|
# +url+:: The URL you want to hit
|
30
35
|
# +type+:: The HTTP method to send
|
31
36
|
# +key+:: The authentication key to pass via headers to the URL
|
32
|
-
def
|
37
|
+
def request(url, type)
|
33
38
|
url = URI(URI.encode(url))
|
34
39
|
type ||= :GET
|
35
40
|
req_path = "#{url.path}?#{url.query}"
|
@@ -46,6 +51,13 @@ module Netdata
|
|
46
51
|
|
47
52
|
res
|
48
53
|
end
|
54
|
+
|
55
|
+
# Create a query string from a hash
|
56
|
+
# Params:
|
57
|
+
# +args+:: The hash
|
58
|
+
def build_qs(args)
|
59
|
+
args.map{|k, v| "#{k}=#{v}"}.join("&")
|
60
|
+
end
|
49
61
|
end
|
50
62
|
end
|
51
63
|
end
|
data/lib/netdata/client.rb
CHANGED
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.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: notifaction
|
@@ -86,9 +86,7 @@ files:
|
|
86
86
|
- exe/netdatacli
|
87
87
|
- lib/netdata/client.rb
|
88
88
|
- lib/netdata/client/controller.rb
|
89
|
-
- lib/netdata/client/custom_alarms.rb
|
90
89
|
- lib/netdata/client/helper/network.rb
|
91
|
-
- lib/netdata/client/netdata_alarms.rb
|
92
90
|
- lib/netdata/client/version.rb
|
93
91
|
- netdata-client.gemspec
|
94
92
|
homepage: http://github.com/aapis/netdata-client
|
File without changes
|
File without changes
|