neutrino_client 0.0.2 → 0.0.3
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.
- data/TODO +0 -1
- data/lib/neutrino/client.rb +1 -0
- data/lib/neutrino/config.rb +1 -0
- data/lib/neutrino/metric.rb +1 -1
- data/lib/neutrino/munin_metric.rb +60 -0
- data/lib/neutrino/reporter.rb +3 -1
- data/lib/neutrino/version.rb +1 -1
- data/test/config_test.rb +4 -0
- data/test/munin_metric_test.rb +64 -0
- data/test/reporter_test.rb +8 -0
- data/test/shell_metric_test.rb +1 -1
- metadata +6 -4
data/lib/neutrino/client.rb
CHANGED
data/lib/neutrino/config.rb
CHANGED
data/lib/neutrino/metric.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Neutrino
|
4
|
+
module Client
|
5
|
+
class MuninMetric < Metric
|
6
|
+
property :munin_plugin_path
|
7
|
+
|
8
|
+
def initialize(opts={})
|
9
|
+
super(opts)
|
10
|
+
configure
|
11
|
+
# query
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.execute_and_parse(command)
|
15
|
+
output = Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
16
|
+
stdout.read.strip
|
17
|
+
end
|
18
|
+
result = {}
|
19
|
+
output.split("\n").each do |line|
|
20
|
+
whole_line, key, value = line.match(/(\S*) (.*)/).to_a
|
21
|
+
key_parts = key.split(/\.|_/)
|
22
|
+
if key_parts.length == 2
|
23
|
+
result[key_parts.first] ||= {}
|
24
|
+
result[key_parts.first][key_parts.last] = value
|
25
|
+
else
|
26
|
+
result[key_parts.first] = value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure_plugin(path)
|
33
|
+
self.execute_and_parse("#{path} config")
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.query_plugin(path)
|
37
|
+
self.execute_and_parse(path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure
|
41
|
+
plugin_configuration = MuninMetric.configure_plugin(self.munin_plugin_path)
|
42
|
+
self.base_metadata ||= {}
|
43
|
+
if plugin_configuration["graph"]
|
44
|
+
self.base_metadata["group"] = plugin_configuration["graph"]["category"]
|
45
|
+
self.base_metadata["type"] = plugin_configuration["graph"]["vlabel"]
|
46
|
+
self.base_metadata["name"] = plugin_configuration["graph"]["title"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def query
|
51
|
+
plugin_query = MuninMetric.query_plugin(self.munin_plugin_path)
|
52
|
+
begin
|
53
|
+
self.value = plugin_query.to_a.first[1]["value"]
|
54
|
+
rescue
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/neutrino/reporter.rb
CHANGED
@@ -11,7 +11,7 @@ module Neutrino
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.get_metrics
|
14
|
-
[
|
14
|
+
ms = [
|
15
15
|
ShellMetric.new({
|
16
16
|
:name => "CPU Steal",
|
17
17
|
:command => "iostat | grep -A1 avg-cpu | tail -1 | awk '{print $5}'",
|
@@ -64,6 +64,8 @@ module Neutrino
|
|
64
64
|
:type => 'process'
|
65
65
|
})
|
66
66
|
]
|
67
|
+
Dir.glob(Config.munin_plugin_globs).each{|plugin_path| ms << MuninMetric.new(:munin_plugin_path => plugin_path)}
|
68
|
+
ms
|
67
69
|
end
|
68
70
|
|
69
71
|
def self.report
|
data/lib/neutrino/version.rb
CHANGED
data/test/config_test.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "neutrino/client"
|
2
|
+
require "test/unit"
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
module Neutrino
|
6
|
+
module Client
|
7
|
+
class TestMuninMetric < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
Config.defaults!
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_properties
|
13
|
+
path = "/path/to/plugin"
|
14
|
+
m = MuninMetric.new(:munin_plugin_path => path)
|
15
|
+
assert_equal m.munin_plugin_path, path
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_configure_plugin
|
19
|
+
path = "/some_plugin"
|
20
|
+
Open3.expects(:popen3).with("#{path} config").returns("graph_title Load average\ngraph_args --base 1000 -l 0\ngraph_vlabel load\ngraph_scale no\ngraph_category system\nload.label load\nload.warning 10\nload.critical 120\ngraph_info The load average of the machine describes how many processes are in the run-queue (scheduled to run \"immediately\").\nload.info Average load for the five minutes.\n")
|
21
|
+
m = MuninMetric.configure_plugin(path)
|
22
|
+
assert_equal m.class, Hash
|
23
|
+
assert_not_nil m["graph"]
|
24
|
+
assert_equal m["graph"]["title"], "Load average"
|
25
|
+
assert_equal m["graph"]["args"], "--base 1000 -l 0"
|
26
|
+
assert_equal m["graph"]["vlabel"], "load"
|
27
|
+
assert_equal m["graph"]["scale"], "no"
|
28
|
+
assert_equal m["graph"]["category"], "system"
|
29
|
+
assert_not_nil m["load"]
|
30
|
+
assert_equal m["load"]["label"], "load"
|
31
|
+
assert_equal m["load"]["warning"], "10"
|
32
|
+
assert_equal m["load"]["critical"], "120"
|
33
|
+
assert_equal m["load"]["info"], "Average load for the five minutes."
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_query_plugin
|
37
|
+
path = "/some_plugin"
|
38
|
+
Open3.expects(:popen3).with(path).returns("load.value 0.17\n")
|
39
|
+
m = MuninMetric.query_plugin(path)
|
40
|
+
assert_equal m.class, Hash
|
41
|
+
assert_not_nil m["load"]
|
42
|
+
assert_equal m["load"]["value"], "0.17"
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_configure
|
46
|
+
path = "/some_plugin"
|
47
|
+
Open3.expects(:popen3).with("#{path} config").returns("graph_title Load average\ngraph_args --base 1000 -l 0\ngraph_vlabel load\ngraph_scale no\ngraph_category system\nload.label load\nload.warning 10\nload.critical 120\ngraph_info The load average of the machine describes how many processes are in the run-queue (scheduled to run \"immediately\").\nload.info Average load for the five minutes.\n")
|
48
|
+
m = MuninMetric.new(:munin_plugin_path => path)
|
49
|
+
assert_equal m.base_metadata["group"], "system"
|
50
|
+
assert_equal m.base_metadata["type"], "load"
|
51
|
+
assert_equal m.base_metadata["name"], "Load average"
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_query
|
55
|
+
path = "/some_plugin"
|
56
|
+
Open3.expects(:popen3).with("#{path} config").returns("")
|
57
|
+
Open3.expects(:popen3).with(path).returns("load.value 123\n")
|
58
|
+
m = MuninMetric.new(:munin_plugin_path => path)
|
59
|
+
m.query
|
60
|
+
assert_equal m.value, "123"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/test/reporter_test.rb
CHANGED
@@ -26,6 +26,14 @@ module Neutrino
|
|
26
26
|
Log.expects(:warn).times(metrics.length)
|
27
27
|
Reporter.report
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_reporter_adds_munin_plugins
|
31
|
+
Dir.expects(:glob).with("/somedir/*").returns(["/path1", "/path2"])
|
32
|
+
MuninMetric.expects(:new).with(:munin_plugin_path => "/path1").returns(Metric.new)
|
33
|
+
MuninMetric.expects(:new).with(:munin_plugin_path => "/path2").returns(Metric.new)
|
34
|
+
Config.munin_plugin_globs "/somedir/*"
|
35
|
+
Reporter.report
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
data/test/shell_metric_test.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neutrino_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nick Stielau
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-14 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/neutrino/config.rb
|
169
169
|
- lib/neutrino/log.rb
|
170
170
|
- lib/neutrino/metric.rb
|
171
|
+
- lib/neutrino/munin_metric.rb
|
171
172
|
- lib/neutrino/reporter.rb
|
172
173
|
- lib/neutrino/shell_metric.rb
|
173
174
|
- lib/neutrino/version.rb
|
@@ -175,6 +176,7 @@ files:
|
|
175
176
|
- test/cli_test.rb
|
176
177
|
- test/config_test.rb
|
177
178
|
- test/metric_test.rb
|
179
|
+
- test/munin_metric_test.rb
|
178
180
|
- test/reporter_test.rb
|
179
181
|
- test/shell_metric_test.rb
|
180
182
|
has_rdoc: true
|