netdata-client 1.0.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 +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/com.netdata.monitor.plist.dist +15 -0
- data/exe/netdatacli +8 -0
- data/lib/netdata/client.rb +14 -0
- data/lib/netdata/client/controller.rb +34 -0
- data/lib/netdata/client/custom_alarms.rb +0 -0
- data/lib/netdata/client/helper/network.rb +52 -0
- data/lib/netdata/client/netdata_alarms.rb +0 -0
- data/lib/netdata/client/version.rb +5 -0
- data/netdata-client.gemspec +25 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a76ba3f0828f2b0719f2848ed2b0681443fc4bf1
|
4
|
+
data.tar.gz: 9bdee103bac5e5d08959aec2432297c7a20a4b19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc05f3d5c9bdb037531cfbf21db6454c7b6c9dd7fb25a1ed87f7ba4247815bbc90a6f0dd4663fe5302706df027343ea53e483175c55d987df53e49bd3f268d7c
|
7
|
+
data.tar.gz: 18216020adade42b17236ff94b3d24961303098a93c5951ed579b6f8f554cbe5c6ed2140582f0785fd316fa62cb2cd27615a911973ec8f7f627be98b770cc7ae
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ryan Priebe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Netdata::Client
|
2
|
+
|
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
|
+
|
5
|
+
This is very early stage software, it's just a proof of concept for now. Features I'm hoping to add include:
|
6
|
+
|
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
|
+
* More datapoints. Currently it only supports system.cpu.
|
9
|
+
* Better architecture.
|
10
|
+
|
11
|
+
Installation:
|
12
|
+
|
13
|
+
$ gem install netdata-client
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
If you're using OSX > 10.4:
|
18
|
+
|
19
|
+
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`.
|
21
|
+
3. `launchtl load -w /Library/LaunchDaemons/com.netdata.monitor.plist`
|
22
|
+
|
23
|
+
If using *nix:
|
24
|
+
|
25
|
+
1. Configure a cron job.
|
26
|
+
2. Profit.
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aapis/netdata-client.
|
31
|
+
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "netdata/client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
3
|
+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
4
|
+
<plist version="1.0">
|
5
|
+
<dict>
|
6
|
+
<key>Label</key>
|
7
|
+
<string>com.netdata.monitor</string>
|
8
|
+
<key>ProgramArguments</key>
|
9
|
+
<array>
|
10
|
+
<string>/path/to/the/gem/netdatacli</string>
|
11
|
+
</array>
|
12
|
+
<key>StartInterval</key>
|
13
|
+
<integer>120</integer>
|
14
|
+
</dict>
|
15
|
+
</plist>
|
data/exe/netdatacli
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
require "notifaction"
|
5
|
+
|
6
|
+
require "netdata/client/controller"
|
7
|
+
require "netdata/client/helper/network"
|
8
|
+
require "netdata/client/version"
|
9
|
+
|
10
|
+
module Netdata
|
11
|
+
module Client
|
12
|
+
# something...
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Netdata
|
2
|
+
module Client
|
3
|
+
class Controller
|
4
|
+
def initialize
|
5
|
+
@network = Helper::Network.new
|
6
|
+
@config = ::YAML::load_file(File.expand_path("~/.netdatacli.yml"))
|
7
|
+
end
|
8
|
+
|
9
|
+
def check
|
10
|
+
aggregator = {}
|
11
|
+
|
12
|
+
return unless @config
|
13
|
+
|
14
|
+
@config["instances"].each do |url|
|
15
|
+
alarms = @network.get("alarms", url)
|
16
|
+
|
17
|
+
return unless alarms
|
18
|
+
|
19
|
+
alarms_resp = JSON.parse(alarms.body)
|
20
|
+
|
21
|
+
cpu = @network.get("data?chart=system.cpu&format=array&points=540&group=average&options=absolute|jsonwrap|nonzero&after=-540", url)
|
22
|
+
cpu_value = JSON.parse(cpu.body)["result"].first
|
23
|
+
|
24
|
+
aggregator[alarms_resp["hostname"]] = {}
|
25
|
+
aggregator[alarms_resp["hostname"]]["cpu"] = cpu_value
|
26
|
+
end
|
27
|
+
|
28
|
+
aggregator.each_pair do |host, data|
|
29
|
+
Notify.bubble("CPU Warning on #{host} - #{data["cpu"]}", "Netdata Warning") if data["cpu"] > 50
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Netdata
|
2
|
+
module Client
|
3
|
+
module Helper
|
4
|
+
class Network
|
5
|
+
# Access the configuration object instance externally
|
6
|
+
attr_accessor :config
|
7
|
+
|
8
|
+
# Perform a GET request to a specified URL
|
9
|
+
# Params:
|
10
|
+
# +url+:: The URL you want to hit
|
11
|
+
# +key+:: The authentication key to pass via headers to the URL
|
12
|
+
def get(endpoint, url, version = "v1")
|
13
|
+
req_url = "#{url}/api/#{version}/#{endpoint}"
|
14
|
+
_request(req_url, :GET)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Perform a POST request to a specified URL
|
18
|
+
# Params:
|
19
|
+
# +url+:: The URL you want to hit
|
20
|
+
# +key+:: The authentication key to pass via headers to the URL
|
21
|
+
def post(url)
|
22
|
+
_request(url, :POST)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Create and send the HTTP request
|
28
|
+
# Params:
|
29
|
+
# +url+:: The URL you want to hit
|
30
|
+
# +type+:: The HTTP method to send
|
31
|
+
# +key+:: The authentication key to pass via headers to the URL
|
32
|
+
def _request(url, type)
|
33
|
+
url = URI(URI.encode(url))
|
34
|
+
type ||= :GET
|
35
|
+
req_path = "#{url.path}?#{url.query}"
|
36
|
+
|
37
|
+
if type == :GET
|
38
|
+
req = Net::HTTP::Get.new(req_path)
|
39
|
+
elsif type == :POST
|
40
|
+
req = Net::HTTP::Post.new(req_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
res = Net::HTTP.new(url.host, url.port).start do |http|
|
44
|
+
http.request(req)
|
45
|
+
end
|
46
|
+
|
47
|
+
res
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'netdata/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "netdata-client"
|
8
|
+
spec.version = Netdata::Client::VERSION
|
9
|
+
spec.authors = ["Ryan Priebe"]
|
10
|
+
spec.email = ["rpriebe@me.com"]
|
11
|
+
|
12
|
+
spec.summary = "Monitor your netdata instances, spawn OS notifications"
|
13
|
+
spec.homepage = "http://github.com/aapis/netdata-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'notifaction'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: netdata-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Priebe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: notifaction
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- rpriebe@me.com
|
72
|
+
executables:
|
73
|
+
- netdatacli
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- com.netdata.monitor.plist.dist
|
86
|
+
- exe/netdatacli
|
87
|
+
- lib/netdata/client.rb
|
88
|
+
- lib/netdata/client/controller.rb
|
89
|
+
- lib/netdata/client/custom_alarms.rb
|
90
|
+
- lib/netdata/client/helper/network.rb
|
91
|
+
- lib/netdata/client/netdata_alarms.rb
|
92
|
+
- lib/netdata/client/version.rb
|
93
|
+
- netdata-client.gemspec
|
94
|
+
homepage: http://github.com/aapis/netdata-client
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.14.1
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Monitor your netdata instances, spawn OS notifications
|
118
|
+
test_files: []
|