instrumental_tools 0.1.1 → 0.2.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.
- data/README.md +4 -2
- data/bin/instrument_server +116 -26
- data/instrumental_tools.gemspec +1 -0
- data/lib/instrumental_tools/version.rb +1 -1
- metadata +20 -9
data/README.md
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
# Instrumental Tools
|
2
2
|
|
3
|
-
|
3
|
+
A collection of tools for use with Instrumental ([www.instrumental.com](http://www.instrumentalapp.com/))
|
4
4
|
|
5
5
|
## instrument_server
|
6
6
|
|
7
7
|
Use to collect various monitoring statistics of a server. Execute with:
|
8
8
|
|
9
9
|
```sh
|
10
|
-
instrument_server
|
10
|
+
instrument_server -k <INSTRUMENTAL_API_KEY>
|
11
11
|
```
|
12
12
|
|
13
13
|
Linux note: Install iostat (part of the sysstat package) in order to collect disk I/O metrics.
|
14
14
|
|
15
|
+
Mac OS note: Due to a bug in Ruby, instrument_server can occasionally deadlock ([bug report](http://bugs.ruby-lang.org/issues/5811)).
|
16
|
+
|
15
17
|
## instrumental
|
16
18
|
|
17
19
|
Output text graphs of the different metrics in your project.
|
data/bin/instrument_server
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
|
4
|
+
begin
|
5
|
+
gem 'instrumental_agent'
|
6
|
+
rescue Gem::LoadError
|
7
|
+
puts "Requires the Instrumental Agent gem:\n"
|
8
|
+
puts ' gem install instrumental_agent'
|
9
|
+
exit 1
|
10
|
+
end
|
5
11
|
require 'instrumental_agent'
|
6
|
-
|
12
|
+
require 'pidly'
|
13
|
+
require 'tmpdir'
|
14
|
+
require 'optparse'
|
7
15
|
|
8
16
|
class SystemInspector
|
9
17
|
TYPES = [:gauges, :incrementors]
|
@@ -127,7 +135,6 @@ class SystemInspector
|
|
127
135
|
def self.load_filesystem
|
128
136
|
{}
|
129
137
|
end
|
130
|
-
|
131
138
|
end
|
132
139
|
|
133
140
|
module Linux
|
@@ -233,36 +240,119 @@ class SystemInspector
|
|
233
240
|
}
|
234
241
|
end
|
235
242
|
end
|
236
|
-
|
237
243
|
end
|
238
244
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
245
|
+
class ServerController < Pidly::Control
|
246
|
+
COMMANDS = [:start, :stop, :status, :restart, :clean, :kill]
|
247
|
+
|
248
|
+
attr_accessor :run_options
|
249
|
+
|
250
|
+
before_start do
|
251
|
+
puts "Starting daemon process: #{@pid}"
|
252
|
+
end
|
253
|
+
|
254
|
+
start :run
|
255
|
+
|
256
|
+
stop do
|
257
|
+
puts "Attempting to kill daemon process: #{@pid}"
|
258
|
+
end
|
259
|
+
|
260
|
+
# after_stop :something
|
261
|
+
|
262
|
+
error do
|
263
|
+
puts 'Error encountered'
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.run(options)
|
267
|
+
agent = Instrumental::Agent.new(options[:api_key], :collector => [options[:collector], options[:port]].compact.join(':'))
|
268
|
+
puts "Collecting stats under the hostname: #{options[:hostname]}"
|
269
|
+
loop do
|
270
|
+
inspector = SystemInspector.new
|
271
|
+
inspector.load_all
|
272
|
+
inspector.gauges.each do |stat, value|
|
273
|
+
agent.gauge("#{options[:hostname]}.#{stat}", value)
|
274
|
+
end
|
275
|
+
# agent.increment("#{host}.#{stat}", delta)
|
276
|
+
sleep 10
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def initialize(options={})
|
281
|
+
@run_options = options.delete(:run_options) || {}
|
282
|
+
super(options)
|
283
|
+
end
|
284
|
+
|
285
|
+
def run
|
286
|
+
self.class.run(run_options)
|
287
|
+
end
|
288
|
+
|
289
|
+
alias_method :clean, :clean!
|
248
290
|
end
|
249
|
-
options = collector.nil? ? {} : { :collector => collector }
|
250
|
-
I = Instrumental::Agent.new(token, options)
|
251
291
|
|
252
|
-
|
292
|
+
def terminal_messages
|
293
|
+
if `which iostat`.chomp.empty?
|
294
|
+
puts 'Install iostat (sysstat package) to collect disk I/O metrics.'
|
295
|
+
end
|
296
|
+
end
|
253
297
|
|
254
|
-
|
298
|
+
def require_api_key(options, parser)
|
299
|
+
unless options[:api_key] # present?
|
300
|
+
print parser.help
|
301
|
+
exit 1
|
302
|
+
end
|
303
|
+
end
|
255
304
|
|
256
|
-
|
257
|
-
|
305
|
+
options = {
|
306
|
+
:daemon => false,
|
307
|
+
:collector => 'instrumentalapp.com',
|
308
|
+
:port => '8000',
|
309
|
+
:hostname => `hostname`.chomp,
|
310
|
+
}
|
311
|
+
|
312
|
+
option_parser = OptionParser.new do |opts|
|
313
|
+
opts.banner = "Usage: instrument_server [-k API_KEY] [options] [-d #{ServerController::COMMANDS.join('|')}]"
|
314
|
+
opts.on('-k', '--api_key API_KEY', 'API key of your project') do |api_key|
|
315
|
+
options[:api_key] = api_key
|
316
|
+
end
|
317
|
+
opts.on('-c', '--collector COLLECTOR[:PORT]', "Collector (default #{options[:collector]}:#{options[:port]})") do |collector|
|
318
|
+
address, port = collector.split(':')
|
319
|
+
options[:collector] = address
|
320
|
+
options[:port] = port if port
|
321
|
+
end
|
322
|
+
opts.on('-d', '--daemonize', 'Run as daemon') do
|
323
|
+
options[:daemon] = true
|
324
|
+
end
|
325
|
+
opts.on('-h', '--help', 'Display this screen') do
|
326
|
+
puts opts
|
327
|
+
terminal_messages
|
328
|
+
exit
|
329
|
+
end
|
258
330
|
end
|
259
331
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
332
|
+
option_parser.parse!
|
333
|
+
options[:api_key] ||= ENV["INSTRUMENTAL_TOKEN"]
|
334
|
+
|
335
|
+
if options.delete(:daemon)
|
336
|
+
@server_controller = ServerController.spawn(
|
337
|
+
:name => 'instrument_server',
|
338
|
+
:path => Dir.tmpdir,
|
339
|
+
:pid_file => File.join(Dir.tmpdir, 'pids', 'instrument_server.pid'),
|
340
|
+
:verbose => true,
|
341
|
+
# :signal => 'kill',
|
342
|
+
:log_file => File.join(Dir.tmpdir, 'log', 'instrument_server.log'),
|
343
|
+
:run_options => options
|
344
|
+
)
|
345
|
+
command = ARGV.first && ARGV.first.to_sym
|
346
|
+
command ||= :start
|
347
|
+
if [:start, :restart].include?(command)
|
348
|
+
require_api_key(options, option_parser)
|
265
349
|
end
|
266
|
-
|
267
|
-
|
350
|
+
if ServerController::COMMANDS.include?(command)
|
351
|
+
@server_controller.send command
|
352
|
+
else
|
353
|
+
puts "Command must be one of: #{ServerController::COMMANDS.join(', ')}"
|
354
|
+
end
|
355
|
+
else
|
356
|
+
require_api_key(options, option_parser)
|
357
|
+
ServerController.run(options)
|
268
358
|
end
|
data/instrumental_tools.gemspec
CHANGED
@@ -16,5 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.add_runtime_dependency(%q<json>, [">=0"])
|
18
18
|
s.add_runtime_dependency(%q<instrumental_agent>, [">=0.5"])
|
19
|
+
s.add_runtime_dependency(%q<pidly>, [">=0.1.3"])
|
19
20
|
s.add_development_dependency(%q<rake>, [">=0"])
|
20
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instrumental_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2011-12-
|
15
|
+
date: 2011-12-27 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: json
|
19
|
-
requirement: &
|
19
|
+
requirement: &70316651665940 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70316651665940
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: instrumental_agent
|
30
|
-
requirement: &
|
30
|
+
requirement: &70316651665420 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,10 +35,21 @@ dependencies:
|
|
35
35
|
version: '0.5'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70316651665420
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: pidly
|
41
|
+
requirement: &70316651664940 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.1.3
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *70316651664940
|
39
50
|
- !ruby/object:Gem::Dependency
|
40
51
|
name: rake
|
41
|
-
requirement: &
|
52
|
+
requirement: &70316651664460 !ruby/object:Gem::Requirement
|
42
53
|
none: false
|
43
54
|
requirements:
|
44
55
|
- - ! '>='
|
@@ -46,7 +57,7 @@ dependencies:
|
|
46
57
|
version: '0'
|
47
58
|
type: :development
|
48
59
|
prerelease: false
|
49
|
-
version_requirements: *
|
60
|
+
version_requirements: *70316651664460
|
50
61
|
description: Tools for displaying information from and reporting to Instrumental (instrumentalapp.com)
|
51
62
|
email:
|
52
63
|
- support@instrumentalapp.com
|
@@ -86,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
97
|
version: '0'
|
87
98
|
requirements: []
|
88
99
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.12
|
90
101
|
signing_key:
|
91
102
|
specification_version: 3
|
92
103
|
summary: Command line tools for Instrumental
|