munin_manager 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +30 -0
- data/README.markdown +0 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/bin/munin_manager +95 -0
- data/bin/runner +18 -0
- data/lib/munin_manager.rb +9 -0
- data/lib/munin_manager/acts_as_munin_plugin.rb +82 -0
- data/lib/munin_manager/log_reader.rb +85 -0
- data/lib/munin_manager/plugins.rb +29 -0
- data/lib/munin_manager/plugins/fbproxy_latency.rb +78 -0
- data/lib/munin_manager/plugins/haproxy_app_response_time.rb +104 -0
- data/lib/munin_manager/plugins/haproxy_response_time.rb +87 -0
- data/lib/munin_manager/plugins/haproxy_rps.rb +95 -0
- data/lib/munin_manager/plugins/network_latency.rb +53 -0
- data/lib/munin_manager/plugins/notification_classification.rb +27 -0
- data/lib/munin_manager/plugins/packet_loss.rb +53 -0
- data/lib/munin_manager/plugins/rails_rendering.rb +82 -0
- data/lib/munin_manager/plugins/rails_response_time.rb +103 -0
- data/lib/munin_manager/plugins/scribe_net.rb +81 -0
- data/lib/munin_manager/plugins/starling_age.rb +77 -0
- data/lib/munin_manager/plugins/starling_net.rb +81 -0
- data/lib/munin_manager/plugins/starling_ops.rb +85 -0
- data/lib/munin_manager/plugins/starling_queue.rb +84 -0
- data/lib/munin_manager/starling/starling_stats.rb +66 -0
- data/test/haproxy_response_time_test.rb +37 -0
- data/test/log_reader_test.rb +31 -0
- data/test/rails_response_time_test.rb +51 -0
- data/test/test_helper.rb +32 -0
- metadata +86 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
class Starling
|
2
|
+
def stats
|
3
|
+
raise MemCacheError, "No active servers" unless active?
|
4
|
+
server_stats = {}
|
5
|
+
|
6
|
+
@servers.each do |server|
|
7
|
+
sock = server.socket
|
8
|
+
raise MemCacheError, "No connection to server" if sock.nil?
|
9
|
+
|
10
|
+
value = nil
|
11
|
+
begin
|
12
|
+
sock.write "stats\r\n"
|
13
|
+
stats = {}
|
14
|
+
while line = sock.gets do
|
15
|
+
break if line == "END\r\n"
|
16
|
+
if line =~ /^STAT/ then
|
17
|
+
stat, name, value = line.split
|
18
|
+
stats[name] = case name
|
19
|
+
when 'version'
|
20
|
+
value
|
21
|
+
when 'rusage_user', 'rusage_system' then
|
22
|
+
seconds, microseconds = value.split(/:/, 2)
|
23
|
+
microseconds ||= 0
|
24
|
+
Float(seconds) + (Float(microseconds) / 1_000_000)
|
25
|
+
else
|
26
|
+
if value =~ /^\d+$/ then
|
27
|
+
value.to_i
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
server_stats["#{server.host}:#{server.port}"] = stats
|
35
|
+
rescue SocketError, SystemCallError, IOError => err
|
36
|
+
puts err.inspect
|
37
|
+
server.close
|
38
|
+
raise MemCacheError, err.message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
server_stats
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# returns the number of items in +queue+. If +queue+ is +:all+, a hash of all
|
47
|
+
# queue sizes will be returned.
|
48
|
+
|
49
|
+
def sizeof(queue, statistics = nil)
|
50
|
+
statistics ||= stats
|
51
|
+
|
52
|
+
if queue == :all
|
53
|
+
queue_sizes = {}
|
54
|
+
available_queues(statistics).each do |queue|
|
55
|
+
queue_sizes[queue] = sizeof(queue, statistics)
|
56
|
+
end
|
57
|
+
return queue_sizes
|
58
|
+
end
|
59
|
+
|
60
|
+
statistics.inject(0) { |m,(k,v)| m + v["queue_#{make_cache_key(queue)}_items"].to_i }
|
61
|
+
end
|
62
|
+
|
63
|
+
def queue_names
|
64
|
+
return available_queues
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
class HaproxyResponseTimeTest < Test::Unit::TestCase
|
4
|
+
include MuninManager::Plugins
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@reader = HaproxyResponseTime.new("#{TEST_DIR}/logs/haproxy.log")
|
8
|
+
@reader.state_dir = "#{TEST_DIR}/tmp"
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
File.unlink(@reader.state_file)
|
13
|
+
rescue
|
14
|
+
# Do nothing
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_parsing
|
18
|
+
@reader.collect!
|
19
|
+
|
20
|
+
expected_values = {
|
21
|
+
:rails_action => "0.0005463880",
|
22
|
+
:total => "0.5552000000",
|
23
|
+
:client_connect => "0.0000000000",
|
24
|
+
:waiting_in_queue => "0.0000000000",
|
25
|
+
:server_connect => "0.0000000000",
|
26
|
+
:server_response => "0.5547000000"
|
27
|
+
}
|
28
|
+
|
29
|
+
expected_values.each do |field, val|
|
30
|
+
assert_equal(val, @reader.data[field], "Value mismatch in #{field}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_has_help_text
|
35
|
+
assert !HaproxyResponseTime.help_text.empty?
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
class LogReaderTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@reader = RailsLogReader.new("#{HERE}/logs/rails.log")
|
6
|
+
|
7
|
+
File.open(@reader.file_name, 'w') do |f|
|
8
|
+
10.times {f.puts("Completed in")}
|
9
|
+
20.times {f.puts("Some other stuff")}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
File.unlink(@reader.state_file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_remembers_last_position_in_log
|
18
|
+
@reader.collect!
|
19
|
+
assert_equal 10, @reader.num_requests
|
20
|
+
|
21
|
+
File.open(@reader.file_name, 'a+') do |f|
|
22
|
+
10.times {f.puts("Completed in")}
|
23
|
+
end
|
24
|
+
|
25
|
+
@new_reader = RailsLogReader.new(@reader.file_name)
|
26
|
+
@new_reader.collect!
|
27
|
+
|
28
|
+
assert_equal 10, @new_reader.num_requests
|
29
|
+
assert_equal 40, File.new(@new_reader.file_name).readlines.length
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
class RailsResponseTimeTest < Test::Unit::TestCase
|
4
|
+
include MuninManager::Plugins
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@reader = RailsResponseTime.new("#{TEST_DIR}/logs/rails.log")
|
8
|
+
@reader.state_dir = "#{TEST_DIR}/tmp"
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
File.unlink(@reader.state_file)
|
13
|
+
rescue
|
14
|
+
# Do nothing
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_has_default_search_pattern
|
18
|
+
assert_kind_of Regexp, @reader.search_pattern
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_parsing_with_default_search_pattern
|
22
|
+
@reader.collect!
|
23
|
+
assert @reader.data.keys.length > 0
|
24
|
+
|
25
|
+
@reader.data.each_pair do |k, v|
|
26
|
+
assert v > 0, "Value mismatch for #{k}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_parsing_with_non_default_search_string
|
31
|
+
@reader.search_pattern = /UsersController.*/
|
32
|
+
@reader.collect!
|
33
|
+
|
34
|
+
@reader.data.each_pair do |action_name, time|
|
35
|
+
assert_not_nil /UsersController.*/.match(action_name), "'%s' does not match search pattern" % action_name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_config_parses_log
|
40
|
+
assert @reader.config.split("\n").select {|line| not line.starts_with?("graph_")}.length > 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_config_does_not_save_state
|
44
|
+
@reader.config
|
45
|
+
assert !File.exists?(@reader.state_file)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_has_help_text
|
49
|
+
assert !RailsResponseTime.help_text.empty?
|
50
|
+
end
|
51
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
TEST_DIR = File.dirname(__FILE__)
|
2
|
+
%w(lib ext bin test).each do |dir|
|
3
|
+
$LOAD_PATH.unshift "#{TEST_DIR}/../#{dir}"
|
4
|
+
end
|
5
|
+
|
6
|
+
%w(rubygems test/unit ruby-debug munin_manager).each do |f|
|
7
|
+
require f
|
8
|
+
end
|
9
|
+
|
10
|
+
class RailsLogReader < MuninManager::LogReader
|
11
|
+
def initialize(*params)
|
12
|
+
super
|
13
|
+
@state_dir = "#{TEST_DIR}/tmp"
|
14
|
+
@state_file = File.join(@state_dir, @me)
|
15
|
+
end
|
16
|
+
|
17
|
+
def scan(log_file)
|
18
|
+
@req_counter = 0
|
19
|
+
loop do
|
20
|
+
line = log_file.readline
|
21
|
+
@req_counter += 1 if line =~ /Completed in/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def process!
|
26
|
+
# Do nothing
|
27
|
+
end
|
28
|
+
|
29
|
+
def num_requests
|
30
|
+
@req_counter
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: munin_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rohith Ravi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-07 00:00:00 -07:00
|
13
|
+
default_executable: munin_manager
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: entombedvirus@gmail.com
|
18
|
+
executables:
|
19
|
+
- munin_manager
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- Manifest
|
26
|
+
- README.markdown
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- bin/munin_manager
|
30
|
+
- bin/runner
|
31
|
+
- lib/munin_manager.rb
|
32
|
+
- lib/munin_manager/acts_as_munin_plugin.rb
|
33
|
+
- lib/munin_manager/log_reader.rb
|
34
|
+
- lib/munin_manager/plugins.rb
|
35
|
+
- lib/munin_manager/plugins/fbproxy_latency.rb
|
36
|
+
- lib/munin_manager/plugins/haproxy_app_response_time.rb
|
37
|
+
- lib/munin_manager/plugins/haproxy_response_time.rb
|
38
|
+
- lib/munin_manager/plugins/haproxy_rps.rb
|
39
|
+
- lib/munin_manager/plugins/network_latency.rb
|
40
|
+
- lib/munin_manager/plugins/notification_classification.rb
|
41
|
+
- lib/munin_manager/plugins/packet_loss.rb
|
42
|
+
- lib/munin_manager/plugins/rails_rendering.rb
|
43
|
+
- lib/munin_manager/plugins/rails_response_time.rb
|
44
|
+
- lib/munin_manager/plugins/scribe_net.rb
|
45
|
+
- lib/munin_manager/plugins/starling_age.rb
|
46
|
+
- lib/munin_manager/plugins/starling_net.rb
|
47
|
+
- lib/munin_manager/plugins/starling_ops.rb
|
48
|
+
- lib/munin_manager/plugins/starling_queue.rb
|
49
|
+
- lib/munin_manager/starling/starling_stats.rb
|
50
|
+
- test/haproxy_response_time_test.rb
|
51
|
+
- test/log_reader_test.rb
|
52
|
+
- test/rails_response_time_test.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/entombedvirus/jeweler
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Tool to maintain and install munin plugins written in Ruby
|
82
|
+
test_files:
|
83
|
+
- test/haproxy_response_time_test.rb
|
84
|
+
- test/log_reader_test.rb
|
85
|
+
- test/rails_response_time_test.rb
|
86
|
+
- test/test_helper.rb
|