monitoring-client 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/bin/monitor-rabbitmq-queue-lengths +171 -0
- data/bin/monitor-system-info +2 -2
- data/lib/monitoring/client/version.rb +1 -1
- data/monitoring-client.gemspec +1 -0
- metadata +31 -12
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
monitoring-client (0.2.
|
4
|
+
monitoring-client (0.2.9)
|
5
5
|
yajl-ruby
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.1.3)
|
11
|
+
rake (0.9.2)
|
11
12
|
rspec (2.6.0)
|
12
13
|
rspec-core (~> 2.6.0)
|
13
14
|
rspec-expectations (~> 2.6.0)
|
@@ -23,4 +24,5 @@ PLATFORMS
|
|
23
24
|
|
24
25
|
DEPENDENCIES
|
25
26
|
monitoring-client!
|
27
|
+
rake
|
26
28
|
rspec
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Monitoring
|
4
|
+
class RabbitMqQueueLengths
|
5
|
+
|
6
|
+
require "optparse"
|
7
|
+
require "yaml"
|
8
|
+
require "monitoring/client/version"
|
9
|
+
require "monitoring/client/profiler"
|
10
|
+
|
11
|
+
RC_OK = 0
|
12
|
+
RC_USAGE = 1
|
13
|
+
RC_KILLED = 2
|
14
|
+
|
15
|
+
|
16
|
+
def initialize()
|
17
|
+
@config_fn = File.join(ENV["HOME"], ".monitoring.rabbitmq-queue-lengths.yml")
|
18
|
+
@daemon_mode = true
|
19
|
+
@pid_file_fn = "/var/run/monitor-rabbitmq-queue-lengths.pid"
|
20
|
+
@sleep_period = 60
|
21
|
+
@stdout = "/dev/null"
|
22
|
+
@stderr = "/dev/null"
|
23
|
+
@alive = true
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def parse_opts(argv)
|
28
|
+
optparser = OptionParser.new() do |o|
|
29
|
+
o.banner = "monitor-rabbitmq-queue-lengths [options]"
|
30
|
+
|
31
|
+
o.separator("")
|
32
|
+
o.separator("options")
|
33
|
+
|
34
|
+
o.on("-c", "--config=CONFIG",
|
35
|
+
"Config file to use",
|
36
|
+
"Default: #{@config_fn.inspect()}") do |v|
|
37
|
+
@config_fn = v
|
38
|
+
end
|
39
|
+
|
40
|
+
o.on("-f", "--forgeround",
|
41
|
+
"Run in forground",
|
42
|
+
"Default: #{!@daemon_mode}") do |v|
|
43
|
+
@daemon_mode = !v
|
44
|
+
end
|
45
|
+
|
46
|
+
o.on("--pid-file=FILE",
|
47
|
+
"Place to store our pid file",
|
48
|
+
"Default: " + @pid_file_fn.inspect()) do |v|
|
49
|
+
@pid_file_fn = v
|
50
|
+
end
|
51
|
+
|
52
|
+
o.on("--sleep-period=s",
|
53
|
+
"Time to sleep between posts",
|
54
|
+
"Default: #{@sleep_period}") do |v|
|
55
|
+
@sleep_period = Float(v)
|
56
|
+
end
|
57
|
+
|
58
|
+
o.on("--stdout=FILE",
|
59
|
+
"Place to write stdout to",
|
60
|
+
"Default: " + @stdout.inspect()) do |v|
|
61
|
+
@stdout = v
|
62
|
+
end
|
63
|
+
|
64
|
+
o.on("-v", "--version",
|
65
|
+
"Print version and exit") do |v|
|
66
|
+
STDOUT.puts(Monitoring::Client::VERSION)
|
67
|
+
Kernel.exit(RC_OK)
|
68
|
+
end
|
69
|
+
|
70
|
+
o.on("--stderr=FILE",
|
71
|
+
"Place to write stdout to",
|
72
|
+
"Default: " + @stderr.inspect()) do |v|
|
73
|
+
@stderr = v
|
74
|
+
end
|
75
|
+
|
76
|
+
o.separator("")
|
77
|
+
o.on_tail("-h", "--help", "You're reading it :-)") do
|
78
|
+
puts(o)
|
79
|
+
Kernel.exit(RC_USAGE)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
optparser.parse(argv)
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def load_config()
|
88
|
+
@config = YAML.load_file(@config_fn)
|
89
|
+
[
|
90
|
+
:profiler_name,
|
91
|
+
].each do |expected_key|
|
92
|
+
unless @config.has_key?(expected_key) &&
|
93
|
+
!@config[expected_key].nil? &&
|
94
|
+
@config[expected_key].size > 0
|
95
|
+
die("Bad config at #{@config_fn}: "\
|
96
|
+
"Expected #{expected_key} to exist and not be blank")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def run()
|
102
|
+
load_config()
|
103
|
+
daemonize() if @daemon_mode
|
104
|
+
|
105
|
+
trap(:INT) do
|
106
|
+
if @alive
|
107
|
+
STDOUT.puts("SIGINT: going away gracefully")
|
108
|
+
@alive = false
|
109
|
+
else
|
110
|
+
STDOUT.puts("SIGINT (again): going away not so gracefully")
|
111
|
+
Kernel.exit!(RC_KILLED)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
while @alive
|
116
|
+
post_queue_lengths
|
117
|
+
Kernel.sleep(@sleep_period)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def daemonize()
|
122
|
+
pid_file_fd = File.open(@pid_file_fn, "w")
|
123
|
+
pid_file_fd.flock(File::LOCK_EX | File::LOCK_NB) ||
|
124
|
+
die("Daemon already exists")
|
125
|
+
|
126
|
+
die("First fork failed") if (pid = Kernel.fork()) == -1
|
127
|
+
exit unless pid.nil?
|
128
|
+
|
129
|
+
Process.setsid
|
130
|
+
pid_file_fd.puts(Process.pid)
|
131
|
+
pid_file_fd.flush()
|
132
|
+
|
133
|
+
Dir.chdir("/")
|
134
|
+
File.umask(0000)
|
135
|
+
STDIN.reopen("/dev/null")
|
136
|
+
STDOUT.reopen(@stdout)
|
137
|
+
STDERR.reopen(@stderr)
|
138
|
+
end
|
139
|
+
|
140
|
+
def die(why)
|
141
|
+
STDERR.puts(why)
|
142
|
+
Kernel.exit!(1)
|
143
|
+
end
|
144
|
+
|
145
|
+
def get_profiler
|
146
|
+
@profiler ||= Monitoring::Client::Profiler.new(@config[:profiler_name])
|
147
|
+
end
|
148
|
+
|
149
|
+
def routine(routine_name)
|
150
|
+
get_profiler.routine(routine_name) do |routine|
|
151
|
+
yield(routine)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def post_queue_lengths
|
156
|
+
list_queues = %x{sudo rabbitmqctl list_queues}.split("\n")
|
157
|
+
list_queues.slice!(0)
|
158
|
+
list_queues.slice!(list_queues.size - 1)
|
159
|
+
routine("list_queues") do |m|
|
160
|
+
m.count("n-queues", list_queues.size, "n")
|
161
|
+
list_queues.each do |line|
|
162
|
+
queue_name, size = line.split("\t")
|
163
|
+
size = Integer(size)
|
164
|
+
m.count(queue_name, size, "n")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
Monitoring::RabbitMqQueueLengths.new().parse_opts(ARGV).run()
|
data/bin/monitor-system-info
CHANGED
@@ -14,9 +14,9 @@ module Monitoring
|
|
14
14
|
|
15
15
|
|
16
16
|
def initialize()
|
17
|
-
@config_fn = File.join(ENV["HOME"], ".monitoring.yml")
|
17
|
+
@config_fn = File.join(ENV["HOME"], ".monitoring.system-info.yml")
|
18
18
|
@daemon_mode = true
|
19
|
-
@pid_file_fn = "/var/run/
|
19
|
+
@pid_file_fn = "/var/run/monitor-system-info.pid"
|
20
20
|
@sleep_period = 60
|
21
21
|
@stdout = "/dev/null"
|
22
22
|
@stderr = "/dev/null"
|
data/monitoring-client.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monitoring-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 9
|
10
|
+
version: 0.2.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marc Bowes
|
@@ -15,12 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-10 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
22
|
+
type: :runtime
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
@@ -30,11 +29,11 @@ dependencies:
|
|
30
29
|
segments:
|
31
30
|
- 0
|
32
31
|
version: "0"
|
33
|
-
|
32
|
+
name: yajl-ruby
|
34
33
|
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
34
|
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
38
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
38
|
none: false
|
40
39
|
requirements:
|
@@ -44,12 +43,28 @@ dependencies:
|
|
44
43
|
segments:
|
45
44
|
- 0
|
46
45
|
version: "0"
|
47
|
-
|
46
|
+
name: rspec
|
48
47
|
version_requirements: *id002
|
48
|
+
prerelease: false
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
type: :development
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
name: rake
|
61
|
+
version_requirements: *id003
|
62
|
+
prerelease: false
|
49
63
|
description: Ruby client which uses UDP to communicate with a daemon which uses HTTP POST to communicate with a Web server
|
50
64
|
email:
|
51
65
|
- marcbowes+monitoring+client@gmail.com
|
52
66
|
executables:
|
67
|
+
- monitor-rabbitmq-queue-lengths
|
53
68
|
- monitor-system-info
|
54
69
|
- monitoringd
|
55
70
|
extensions: []
|
@@ -61,6 +76,7 @@ files:
|
|
61
76
|
- Gemfile
|
62
77
|
- Gemfile.lock
|
63
78
|
- Rakefile
|
79
|
+
- bin/monitor-rabbitmq-queue-lengths
|
64
80
|
- bin/monitor-system-info
|
65
81
|
- bin/monitoringd
|
66
82
|
- lib/monitoring.rb
|
@@ -109,5 +125,8 @@ rubygems_version: 1.6.2
|
|
109
125
|
signing_key:
|
110
126
|
specification_version: 3
|
111
127
|
summary: Simple client & daemon to post metrics
|
112
|
-
test_files:
|
113
|
-
|
128
|
+
test_files:
|
129
|
+
- spec/compiler_spec.rb
|
130
|
+
- spec/config_spec.rb
|
131
|
+
- spec/profiler_spec.rb
|
132
|
+
- spec/spec_helper.rb
|