graphiterb 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -14
- data/VERSION +1 -1
- data/examples/toy.rb +4 -16
- data/graphiterb.gemspec +3 -12
- data/lib/graphiterb.rb +2 -1
- data/lib/graphiterb/utils/system.rb +9 -2
- metadata +4 -13
- data/examples/api_call_monitor.rb +0 -51
- data/examples/file_monitor.rb +0 -113
- data/examples/loadavg_graphite_sender.rb +0 -36
- data/examples/run_servers.sh +0 -2
- data/examples/storage_monitor.rb +0 -23
data/.gitignore
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
1
|
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
2
|
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
3
|
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
4
|
|
5
|
+
|
6
|
+
## EMACS
|
7
|
+
## MAC OS
|
16
8
|
## PROJECT::GENERAL
|
9
|
+
## PROJECT::SPECIFIC
|
10
|
+
## TEXTMATE
|
11
|
+
## VIM
|
12
|
+
*.swp
|
13
|
+
*.tmproj
|
14
|
+
*~
|
15
|
+
.DS_Store
|
16
|
+
.\#*
|
17
|
+
/TAGS
|
18
|
+
\#*
|
17
19
|
coverage
|
18
|
-
rdoc
|
19
20
|
pkg
|
20
|
-
|
21
|
-
|
21
|
+
rdoc
|
22
|
+
tmtags
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.12
|
data/examples/toy.rb
CHANGED
@@ -3,24 +3,12 @@ require 'rubygems'
|
|
3
3
|
$: << File.dirname(__FILE__)+'/../lib'
|
4
4
|
require 'graphiterb'
|
5
5
|
Configliere.use :commandline, :config_file
|
6
|
-
|
7
|
-
Settings.read 'graphite.yaml'
|
8
6
|
Settings.resolve!
|
9
|
-
Log = Logger.new($stderr) unless defined?(Log)
|
10
|
-
|
11
|
-
monitor = Graphiterb::GraphiteLogger.new(:iters => nil, :time => 5)
|
12
|
-
|
13
|
-
handle = 'simple_toy'
|
14
7
|
|
15
|
-
|
16
|
-
|
17
|
-
metrics << [
|
18
|
-
metrics << ["scraper.toy.#{handle}.iter", iter]
|
19
|
-
metrics << ["scraper.toy.#{handle}.iter", iter]
|
20
|
-
metrics << ["scraper.toy.#{handle}.iter", iter]
|
8
|
+
class ToyMonitor < Graphiterb::Monitors::PeriodicMonitor
|
9
|
+
def get_metrics metrics, since
|
10
|
+
metrics << [scope('random', graphite_identifier), rand]
|
21
11
|
end
|
22
|
-
delay = 2
|
23
|
-
sleep delay
|
24
|
-
print delay.to_s+"\t"
|
25
12
|
end
|
26
13
|
|
14
|
+
ToyMonitor.new('toy').run! if $0 == __FILE__
|
data/graphiterb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{graphiterb}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Philip (flip) Kromer (@mrflip)"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-28}
|
13
13
|
s.description = %q{Uses http://github.com/mrflip/configliere and http://graphite.wikidot.com}
|
14
14
|
s.email = %q{info@infochimps.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,11 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.textile",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
-
"examples/api_call_monitor.rb",
|
28
|
-
"examples/file_monitor.rb",
|
29
|
-
"examples/loadavg_graphite_sender.rb",
|
30
|
-
"examples/run_servers.sh",
|
31
|
-
"examples/storage_monitor.rb",
|
32
27
|
"examples/toy.rb",
|
33
28
|
"graphiterb.gemspec",
|
34
29
|
"lib/graphiterb.rb",
|
@@ -55,11 +50,7 @@ Gem::Specification.new do |s|
|
|
55
50
|
s.test_files = [
|
56
51
|
"spec/graphiterb_spec.rb",
|
57
52
|
"spec/spec_helper.rb",
|
58
|
-
"examples/toy.rb"
|
59
|
-
"examples/storage_monitor.rb",
|
60
|
-
"examples/loadavg_graphite_sender.rb",
|
61
|
-
"examples/file_monitor.rb",
|
62
|
-
"examples/api_call_monitor.rb"
|
53
|
+
"examples/toy.rb"
|
63
54
|
]
|
64
55
|
|
65
56
|
if s.respond_to? :specification_version then
|
data/lib/graphiterb.rb
CHANGED
@@ -13,5 +13,6 @@ Settings.define :carbon_server, :default => 'localhost', :description => "Host
|
|
13
13
|
Settings.define :carbon_port, :default => '2003', :description => "Port for carbon database server", :required => true
|
14
14
|
Settings.define :update_delay, :default => 30, :description => "How long to wait between updates. Must be faster than the value in the graphite/conf/storage-schemas", :required => true, :type => Integer
|
15
15
|
Settings.define :on_error_delay, :default => 0.1, :description => "How long to wait on connect errors", :required => true, :type => Float
|
16
|
-
|
16
|
+
Settings.define :node_name_file, :default => '/etc/node_name', :description => "Path to a file which contains the name of this node", :type => String
|
17
17
|
Settings.read '/etc/graphiterb/graphiterb.yaml' if File.exist? '/etc/graphiterb/graphiterb.yaml'
|
18
|
+
Settings.resolve!
|
@@ -8,9 +8,16 @@ module Graphiterb
|
|
8
8
|
module SystemInfo
|
9
9
|
|
10
10
|
def hostname
|
11
|
-
@hostname ||= `hostname`.chomp.gsub("
|
11
|
+
@hostname ||= `hostname`.chomp.gsub(/\./,"_")
|
12
|
+
end
|
13
|
+
|
14
|
+
def node_name
|
15
|
+
@node_name ||= Settings[:node_name_file] && File.exist?(Settings[:node_name_file]) && File.read(Settings[:node_name_file]).chomp.strip.gsub(/\./, '_')
|
16
|
+
end
|
17
|
+
|
18
|
+
def graphite_identifier
|
19
|
+
node_name || hostname
|
12
20
|
end
|
13
|
-
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 12
|
10
|
+
version: 0.2.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philip (flip) Kromer (@mrflip)
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-28 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -79,11 +79,6 @@ files:
|
|
79
79
|
- README.textile
|
80
80
|
- Rakefile
|
81
81
|
- VERSION
|
82
|
-
- examples/api_call_monitor.rb
|
83
|
-
- examples/file_monitor.rb
|
84
|
-
- examples/loadavg_graphite_sender.rb
|
85
|
-
- examples/run_servers.sh
|
86
|
-
- examples/storage_monitor.rb
|
87
82
|
- examples/toy.rb
|
88
83
|
- graphiterb.gemspec
|
89
84
|
- lib/graphiterb.rb
|
@@ -139,7 +134,3 @@ test_files:
|
|
139
134
|
- spec/graphiterb_spec.rb
|
140
135
|
- spec/spec_helper.rb
|
141
136
|
- examples/toy.rb
|
142
|
-
- examples/storage_monitor.rb
|
143
|
-
- examples/loadavg_graphite_sender.rb
|
144
|
-
- examples/file_monitor.rb
|
145
|
-
- examples/api_call_monitor.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$: << File.dirname(__FILE__)+'/../lib/'
|
3
|
-
require 'graphiterb'
|
4
|
-
require 'graphiterb/graphite_script'
|
5
|
-
|
6
|
-
WC_EXEC = '/usr/bin/wc'
|
7
|
-
|
8
|
-
class ApiCallMonitor < Graphiterb::GraphiteLogger
|
9
|
-
API_CALLS_TO_MONITOR = %w[trstrank wordbag influence conversation]
|
10
|
-
ERROR_CODES_TO_MONITOR = %w[4.. 5.. 200]
|
11
|
-
|
12
|
-
def initialize *args
|
13
|
-
super *args
|
14
|
-
@current_total = Hash.new
|
15
|
-
@prev_total = Hash.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def calls api
|
19
|
-
total_calls = `cat /var/www/apeyeye/shared/log/apeyeye-access.log | egrep 'GET /soc/net/tw/#{api}' | #{WC_EXEC} -l` rescue 0
|
20
|
-
@current_total[api] = total_calls.to_i
|
21
|
-
end
|
22
|
-
|
23
|
-
def errors error_code
|
24
|
-
log_cat = `cat /var/www/apeyeye/shared/log/apeyeye-access.log | egrep 'GET /soc/net/tw/.*HTTP/1\.[0-1]..#{error_code}' | #{WC_EXEC} -l` rescue 0
|
25
|
-
@current_total[error_code] = log_cat.to_i
|
26
|
-
end
|
27
|
-
|
28
|
-
def rate item
|
29
|
-
@prev_total[item] ||= @current_total[item]
|
30
|
-
rate = @current_total[item].to_i - @prev_total[item].to_i
|
31
|
-
@prev_total[item] = @current_total[item]
|
32
|
-
[0, rate].max
|
33
|
-
end
|
34
|
-
|
35
|
-
def get_metrics metrics, iter, since
|
36
|
-
API_CALLS_TO_MONITOR.each do |api|
|
37
|
-
metrics << [scope_name(hostname, api, 'total_accesses'), calls(api)]
|
38
|
-
metrics << [scope_name(hostname, api, 'accesses'), rate(api)]
|
39
|
-
end
|
40
|
-
ERROR_CODES_TO_MONITOR.each do |code|
|
41
|
-
metrics << [scope_name(hostname, code.gsub('.','x'), 'total_errors'), errors(code)]
|
42
|
-
metrics << [scope_name(hostname, code.gsub('.','x'), 'errors'), rate(code)]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
warn "Update delay is #{Settings.update_delay} seconds. You probably want something larger: some of these checks are data-intensive" if Settings.update_delay < 60
|
49
|
-
Settings.die "Update delay is #{Settings.update_delay} seconds. You need to radio in at least as often as /usr/local/share/graphite/conf/storage-schemas says -- this is typically 5 minutes." if Settings.update_delay >= 300
|
50
|
-
|
51
|
-
ApiCallMonitor.new('apeyeye', :iters => nil, :time => Settings.update_delay).run!
|
data/examples/file_monitor.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$: << File.dirname(__FILE__)+'/../lib/'
|
3
|
-
require 'graphiterb'
|
4
|
-
Settings.define :work_dir, :description => "Base directory where scrapers store files. (Ex: /data/ripd/com.tw)", :required => true
|
5
|
-
require 'graphiterb/graphite_script'
|
6
|
-
|
7
|
-
#
|
8
|
-
# Usage:
|
9
|
-
#
|
10
|
-
# nohup ~/ics/backend/graphiterb/bin/file_monitor.rb --work_dir=/data/ripd/com.tw --carbon_server=whatever --update_delay=120 > /data/log/file_monitor.log 2>&1 &
|
11
|
-
#
|
12
|
-
|
13
|
-
WC_EXEC = '/usr/bin/wc'
|
14
|
-
|
15
|
-
class FilePool
|
16
|
-
# Path to sample for files
|
17
|
-
attr_accessor :path
|
18
|
-
# wildcard sequence for files under the current directory
|
19
|
-
attr_accessor :filter_re
|
20
|
-
# A recent file was modified within this window
|
21
|
-
attr_accessor :recent_window
|
22
|
-
# Only consider the last this-many files
|
23
|
-
MAX_FILES = 30
|
24
|
-
|
25
|
-
def initialize path, filter_re=/.*/, options={}
|
26
|
-
self.path = path
|
27
|
-
self.filter_re = filter_re
|
28
|
-
end
|
29
|
-
|
30
|
-
# Name for this pool, suitable for inclusion in a metrics handle
|
31
|
-
def name
|
32
|
-
path.gsub(/\./,'_').gsub(%r{/}, '.').gsub(%r{(^\.|\.$)},'')
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Lists all files in the pool
|
37
|
-
# @param filter_block files only keeps filenames that pass this filter
|
38
|
-
#
|
39
|
-
def files &filter_block
|
40
|
-
Dir[File.join(path, '**/*')].
|
41
|
-
reject{|f| File.directory?(f) }.
|
42
|
-
select{|f| f =~ filter_re }.
|
43
|
-
sort.reverse[0..MAX_FILES].
|
44
|
-
select(&filter_block)
|
45
|
-
end
|
46
|
-
|
47
|
-
def num_files &filter_block
|
48
|
-
files(&filter_block).count
|
49
|
-
end
|
50
|
-
|
51
|
-
def sizes &filter_block
|
52
|
-
files(&filter_block).map{|f| File.size(f) rescue nil }.compact
|
53
|
-
end
|
54
|
-
def size &filter_block
|
55
|
-
sizes(&filter_block).sum
|
56
|
-
end
|
57
|
-
def avg_size &filter_block
|
58
|
-
sizes(&filter_block).sum.to_f / num_files(&filter_block).to_f
|
59
|
-
end
|
60
|
-
|
61
|
-
def lines_in_result_of command, *args
|
62
|
-
begin
|
63
|
-
escaped_args = args.map{|f| "'#{f}'" }
|
64
|
-
result = `#{command} #{escaped_args.join(" ")}`.chomp
|
65
|
-
result.split(/[\r\n]+/)
|
66
|
-
rescue StandardError => e ; warn(e.backtrace, e) ; return nil ; end
|
67
|
-
end
|
68
|
-
|
69
|
-
def line_counts &filter_block
|
70
|
-
files = files(&filter_block) ; return 0 if files.blank?
|
71
|
-
result = lines_in_result_of(WC_EXEC, '-l', *files) or return 0
|
72
|
-
counts = result.map{|wc| wc =~ /^\s*(\d+)\s+/ and $1 }.compact
|
73
|
-
counts.map(&:to_i).sum
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.recent? file
|
77
|
-
(Time.now - File.mtime(file)) < 3600
|
78
|
-
end
|
79
|
-
def self.recency_filter
|
80
|
-
Proc.new{|file| recent?(file) }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class FileMonitor < Graphiterb::GraphiteSystemLogger
|
85
|
-
attr_accessor :path
|
86
|
-
attr_accessor :pools
|
87
|
-
|
88
|
-
def initialize *args
|
89
|
-
super *args
|
90
|
-
self.path = Settings.work_dir
|
91
|
-
self.pools = {}
|
92
|
-
populate_pools!
|
93
|
-
end
|
94
|
-
|
95
|
-
def populate_pools!
|
96
|
-
Dir[File.join(path, '*')].select{|d| File.directory?(d) }.each do |dir|
|
97
|
-
self.pools[dir] ||= FilePool.new(dir, %r{20\d*/.*\.(?:tsv|json|xml)})
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def get_metrics metrics, iter, since
|
102
|
-
recent = FilePool.recency_filter
|
103
|
-
pools.each do |pool_path, pool|
|
104
|
-
metrics << [scope_name(pool.name, hostname, 'active_files'), pool.num_files(&recent) ]
|
105
|
-
metrics << [scope_name(pool.name, hostname, 'active_file_size'), pool.size(&recent) ]
|
106
|
-
metrics << [scope_name(pool.name, hostname, 'line_counts'), pool.line_counts(&recent) ]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
warn "Update delay is #{Settings.update_delay} seconds. You probably want something larger: some of the metrics are expensive." if Settings.update_delay < 60
|
112
|
-
warn "Update delay is #{Settings.update_delay} seconds. You probably want something smaller: need to report in faster than the value in the graphite/conf/storage-schemas." if Settings.update_delay >= 300
|
113
|
-
FileMonitor.new('scraper', :iters => nil, :time => Settings.update_delay).run!
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'rubygems'
|
3
|
-
$: << File.dirname(__FILE__)+'/../lib'
|
4
|
-
require 'graphiterb'
|
5
|
-
Configliere.use :commandline, :config_file
|
6
|
-
|
7
|
-
Settings.read 'graphite.yaml'
|
8
|
-
Settings.resolve!
|
9
|
-
Log = Logger.new($stderr) unless defined?(Log)
|
10
|
-
|
11
|
-
class LoadavgGraphiteSender < Graphiterb::GraphiteSender
|
12
|
-
def hostname
|
13
|
-
@hostname ||= `hostname`.chomp
|
14
|
-
end
|
15
|
-
|
16
|
-
def loadavgs
|
17
|
-
# File.open('/proc/loadavg').read.strip.split[0..2]
|
18
|
-
`uptime`.chomp.gsub(/.*:\s+/, '').split(/[,\s]+/)
|
19
|
-
end
|
20
|
-
|
21
|
-
def loadavgs_metrics
|
22
|
-
%w[1min 5min 15min].zip(loadavgs).map do |duration, avg|
|
23
|
-
["system.#{hostname}.loadavg_#{duration}", avg]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def send_loop
|
28
|
-
loop do
|
29
|
-
send *loadavgs_metrics
|
30
|
-
Log.info "Sleeping #{Settings.update_delay}"
|
31
|
-
sleep Settings.update_delay.to_i
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
LoadavgGraphiteSender.new.send_loop
|
data/examples/run_servers.sh
DELETED
data/examples/storage_monitor.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$: << File.dirname(__FILE__)+'/../lib/'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'graphiterb/graphite_script'
|
5
|
-
|
6
|
-
class AvailSpaceMonitor < Graphiterb::GraphiteLogger
|
7
|
-
def diskfree
|
8
|
-
`/bin/df`.chomp.split("\n").
|
9
|
-
grep(%r{^/dev/}).
|
10
|
-
map{|line| line.split(/\s+/) } rescue []
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_metrics metrics, iter, since
|
14
|
-
diskfree.each do |handle, size, spaceused, spacefree, percentfree, location|
|
15
|
-
metrics << ["system.#{hostname}#{handle.gsub(/\//,'.')}.available", spacefree.to_i]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
warn "Update delay is #{Settings.update_delay} seconds. You probably want something larger: some of the metrics are expensive." if Settings.update_delay < 30
|
21
|
-
warn "Update delay is #{Settings.update_delay} seconds. You probably want something smaller: need to report in faster than the value in the graphite/conf/storage-schemas." if Settings.update_delay >= 60
|
22
|
-
|
23
|
-
AvailSpaceMonitor.new('system').run!
|