garru-ruby_scribe_client 0.0.4 → 0.0.5
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/CHANGELOG +1 -0
- data/Manifest +4 -0
- data/etc/scribe_munin_plugin.rb +85 -0
- data/etc/test.rb +3 -0
- data/lib/ruby_scribe_client/fb303_client.rb +68 -0
- data/lib/ruby_scribe_client/scribe.rb +1 -1
- data/lib/ruby_scribe_client/scribe_mgmt.rb +31 -0
- data/lib/ruby_scribe_client.rb +1 -1
- data/ruby_scribe_client.gemspec +4 -4
- metadata +8 -2
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
etc/scribe_cat.rb
|
3
|
+
etc/scribe_munin_plugin.rb
|
4
|
+
etc/test.rb
|
3
5
|
lib/ruby_scribe_client/FacebookService.rb
|
6
|
+
lib/ruby_scribe_client/fb303_client.rb
|
4
7
|
lib/ruby_scribe_client/fb303_types.rb
|
5
8
|
lib/ruby_scribe_client/reflection_limited_types.rb
|
6
9
|
lib/ruby_scribe_client/scribe.rb
|
10
|
+
lib/ruby_scribe_client/scribe_mgmt.rb
|
7
11
|
lib/ruby_scribe_client/scribe_types.rb
|
8
12
|
lib/ruby_scribe_client.rb
|
9
13
|
LICENSE
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# Munin plugin for starling.
|
3
|
+
HOST = ENV['HOST'] || '127.0.0.1';
|
4
|
+
PORT = ENV['PORT'] || 1463;
|
5
|
+
require 'rubygems'
|
6
|
+
require 'ruby_scribe_client'
|
7
|
+
|
8
|
+
#Monkey patched so the namespaced queues are included in stats
|
9
|
+
class ScribeStats
|
10
|
+
CATEGORY = 'scribe'
|
11
|
+
|
12
|
+
def initialize(host, port)
|
13
|
+
@scribe = FB303.new("#{host}:#{port}")
|
14
|
+
@category = 'scribe'
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def net_stats
|
19
|
+
stats = {
|
20
|
+
:label => 'read',
|
21
|
+
:type => 'COUNTER',
|
22
|
+
:graph => 'no',
|
23
|
+
:cdef => '8,*'
|
24
|
+
}
|
25
|
+
return stats
|
26
|
+
end
|
27
|
+
|
28
|
+
def net_munin_config
|
29
|
+
graph_config = <<-END.gsub(/ +/, '')
|
30
|
+
graph_title Scribe Traffic
|
31
|
+
graph_args --base 1000
|
32
|
+
graph_vlabel bits read(-) / written(+) per second
|
33
|
+
graph_category #{CATEGORY}
|
34
|
+
graph_order bytes_read bytes_written
|
35
|
+
END
|
36
|
+
|
37
|
+
stat_config = ''
|
38
|
+
counters.keys do |stat|
|
39
|
+
stat.gsub!(/\s/){'_'}
|
40
|
+
stats.each do |var,value|
|
41
|
+
value = "#{stat}," + value if var == :cdef
|
42
|
+
stat_config << "#{stat}.#{var} #{value}\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
return graph_config + stat_config
|
47
|
+
end
|
48
|
+
|
49
|
+
def net_munin
|
50
|
+
ret = ""
|
51
|
+
@scribe.getCounters.each do |k, v|
|
52
|
+
ret << "#{k.gsub(/\s/){'_'}}.value #{v}\n"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def munin_name(str)
|
59
|
+
str.tr(":", '_')
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
def counters
|
65
|
+
@scribe.getCounters
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# We pick the chart based on the command we were called as.
|
71
|
+
if $0 =~ /scribe_(\w+)/ then
|
72
|
+
chart_name = $1
|
73
|
+
else
|
74
|
+
$stderr.puts "can't find chart name"
|
75
|
+
end
|
76
|
+
|
77
|
+
starling = StarlingStats.new(HOST, PORT)
|
78
|
+
|
79
|
+
command = "#{chart_name}_munin"
|
80
|
+
|
81
|
+
if ARGV[0] == 'config' then
|
82
|
+
command << '_config'
|
83
|
+
end
|
84
|
+
|
85
|
+
print starling.send(command)
|
data/etc/test.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
class FB303
|
2
|
+
attr_accessor :client
|
3
|
+
|
4
|
+
COMMAND_MAP = { :reload => 'reinitialize',
|
5
|
+
:stop => 'shutdown',
|
6
|
+
:version => 'getVersion',
|
7
|
+
:name => 'getName',
|
8
|
+
:alive => 'aliveSince'
|
9
|
+
}
|
10
|
+
|
11
|
+
STATUS = {
|
12
|
+
Fb_status::DEAD => "DEAD",
|
13
|
+
Fb_status::STARTING => "STARTING",
|
14
|
+
Fb_status::ALIVE => "ALIVE",
|
15
|
+
Fb_status::STOPPING => "STOPPING",
|
16
|
+
Fb_status::STOPPED => "STOPPED",
|
17
|
+
Fb_status::WARNING => "WARNING"
|
18
|
+
}
|
19
|
+
|
20
|
+
def initialize(port)
|
21
|
+
@transport = Thrift::FramedTransport.new(Thrift::Socket.new('metrics.seriousops.com', port))
|
22
|
+
@protocol = Thrift::BinaryProtocol.new(@transport, false, false)
|
23
|
+
@client = FacebookService::Client.new(@protocol)
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(method)
|
27
|
+
if COMMAND_MAP.has_key?(method)
|
28
|
+
if [:version, :alive, :name].include?(method)
|
29
|
+
result = self.send(COMMAND_MAP[method])
|
30
|
+
puts result
|
31
|
+
elsif [:stop, :reload].include?(method)
|
32
|
+
result = self.send(COMMAND_MAP[method])
|
33
|
+
puts result
|
34
|
+
end
|
35
|
+
elsif @client.respond_to?(method)
|
36
|
+
@transport.open
|
37
|
+
return @client.send(method)
|
38
|
+
@transport.close
|
39
|
+
else
|
40
|
+
require 'ruby-debug'; debugger
|
41
|
+
raise NoMethodError.new;
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def status
|
46
|
+
status = self.getStatus
|
47
|
+
status_details = self.getStatusDetails || ""
|
48
|
+
msg = fb_status_string(status)
|
49
|
+
msg += " - %s" % status_details if status_details.size > 0
|
50
|
+
puts msg
|
51
|
+
return (status == Fb_status::ALIVE) ? 2 : 3
|
52
|
+
end
|
53
|
+
|
54
|
+
def counters
|
55
|
+
# require 'ruby-debug'; debugger
|
56
|
+
self.getCounters.each_pair do |key, value|
|
57
|
+
puts "%s: %d" % [key, value]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_counters
|
62
|
+
self.getCounters
|
63
|
+
end
|
64
|
+
|
65
|
+
def fb_status_string(status_code)
|
66
|
+
STATUS[status_code]
|
67
|
+
end
|
68
|
+
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
require File.join([File.dirname(__FILE__), '..', '..', 'vendor','thrift'])
|
8
8
|
require File.join([File.dirname(__FILE__) ,'FacebookService'])
|
9
9
|
require File.join([File.dirname(__FILE__), 'scribe_types'])
|
10
|
-
|
10
|
+
require File.join([File.dirname(__FILE__), 'fb303_client'])
|
11
11
|
module Scribe
|
12
12
|
class Client < FacebookService::Client
|
13
13
|
include ::Thrift::Client
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join([File.dirname(__FILE__), '..', '..', 'vendor','thrift'])
|
2
|
+
require File.join([File.dirname(__FILE__) ,'FacebookService'])
|
3
|
+
require File.join([File.dirname(__FILE__), 'scribe_types'])
|
4
|
+
require File.join([File.dirname(__FILE__) ,'fb303_client'])
|
5
|
+
require 'optparse'
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
begin
|
11
|
+
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: scribe_mgmt.rb [options]"
|
14
|
+
options[:port] = 9082
|
15
|
+
options[:command] = 'status'
|
16
|
+
opts.on("-c", "--command [TYPE]", ["stop","counters","status","reload","version","name","alive"], "execute this API (#{["stop","counters","status","reload","version","name","alive"].join(" ")})") do |v|
|
17
|
+
options[:command] = v
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-p", "--port #", Integer, "this service's port (default 9082)") do |port|
|
21
|
+
options[:port] = port
|
22
|
+
end
|
23
|
+
end.parse!
|
24
|
+
|
25
|
+
rescue OptionParser::ParseError => e
|
26
|
+
puts e.message
|
27
|
+
Process.exit
|
28
|
+
end
|
29
|
+
|
30
|
+
a = FB303.new(options[:port])
|
31
|
+
a.send(options[:command])
|
data/lib/ruby_scribe_client.rb
CHANGED
data/ruby_scribe_client.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ruby_scribe_client}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Gary Tsang"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-04-09}
|
10
10
|
s.description = %q{Ruby Scribe Client. Package and Wrapper for generated ruby interfaces}
|
11
11
|
s.email = %q{}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/ruby_scribe_client/FacebookService.rb", "lib/ruby_scribe_client/fb303_types.rb", "lib/ruby_scribe_client/reflection_limited_types.rb", "lib/ruby_scribe_client/scribe.rb", "lib/ruby_scribe_client/scribe_types.rb", "lib/ruby_scribe_client.rb", "LICENSE", "README"]
|
13
|
-
s.files = ["CHANGELOG", "etc/scribe_cat.rb", "lib/ruby_scribe_client/FacebookService.rb", "lib/ruby_scribe_client/fb303_types.rb", "lib/ruby_scribe_client/reflection_limited_types.rb", "lib/ruby_scribe_client/scribe.rb", "lib/ruby_scribe_client/scribe_types.rb", "lib/ruby_scribe_client.rb", "LICENSE", "Manifest", "Rakefile", "README", "ruby_scribe_client.gemspec", "vendor/thrift/client.rb", "vendor/thrift/deprecation.rb", "vendor/thrift/exceptions.rb", "vendor/thrift/processor.rb", "vendor/thrift/protocol/binaryprotocol.rb", "vendor/thrift/protocol/binaryprotocolaccelerated.rb", "vendor/thrift/protocol/tbinaryprotocol.rb", "vendor/thrift/protocol/tprotocol.rb", "vendor/thrift/protocol.rb", "vendor/thrift/serializer.rb", "vendor/thrift/server/httpserver.rb", "vendor/thrift/server/nonblockingserver.rb", "vendor/thrift/server/thttpserver.rb", "vendor/thrift/server/tserver.rb", "vendor/thrift/server.rb", "vendor/thrift/struct.rb", "vendor/thrift/thrift.rb", "vendor/thrift/transport/httpclient.rb", "vendor/thrift/transport/socket.rb", "vendor/thrift/transport/thttpclient.rb", "vendor/thrift/transport/tsocket.rb", "vendor/thrift/transport/ttransport.rb", "vendor/thrift/transport/unixsocket.rb", "vendor/thrift/transport.rb", "vendor/thrift/types.rb", "vendor/thrift.rb"]
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/ruby_scribe_client/FacebookService.rb", "lib/ruby_scribe_client/fb303_client.rb", "lib/ruby_scribe_client/fb303_types.rb", "lib/ruby_scribe_client/reflection_limited_types.rb", "lib/ruby_scribe_client/scribe.rb", "lib/ruby_scribe_client/scribe_mgmt.rb", "lib/ruby_scribe_client/scribe_types.rb", "lib/ruby_scribe_client.rb", "LICENSE", "README"]
|
13
|
+
s.files = ["CHANGELOG", "etc/scribe_cat.rb", "etc/scribe_munin_plugin.rb", "etc/test.rb", "lib/ruby_scribe_client/FacebookService.rb", "lib/ruby_scribe_client/fb303_client.rb", "lib/ruby_scribe_client/fb303_types.rb", "lib/ruby_scribe_client/reflection_limited_types.rb", "lib/ruby_scribe_client/scribe.rb", "lib/ruby_scribe_client/scribe_mgmt.rb", "lib/ruby_scribe_client/scribe_types.rb", "lib/ruby_scribe_client.rb", "LICENSE", "Manifest", "Rakefile", "README", "ruby_scribe_client.gemspec", "vendor/thrift/client.rb", "vendor/thrift/deprecation.rb", "vendor/thrift/exceptions.rb", "vendor/thrift/processor.rb", "vendor/thrift/protocol/binaryprotocol.rb", "vendor/thrift/protocol/binaryprotocolaccelerated.rb", "vendor/thrift/protocol/tbinaryprotocol.rb", "vendor/thrift/protocol/tprotocol.rb", "vendor/thrift/protocol.rb", "vendor/thrift/serializer.rb", "vendor/thrift/server/httpserver.rb", "vendor/thrift/server/nonblockingserver.rb", "vendor/thrift/server/thttpserver.rb", "vendor/thrift/server/tserver.rb", "vendor/thrift/server.rb", "vendor/thrift/struct.rb", "vendor/thrift/thrift.rb", "vendor/thrift/transport/httpclient.rb", "vendor/thrift/transport/socket.rb", "vendor/thrift/transport/thttpclient.rb", "vendor/thrift/transport/tsocket.rb", "vendor/thrift/transport/ttransport.rb", "vendor/thrift/transport/unixsocket.rb", "vendor/thrift/transport.rb", "vendor/thrift/types.rb", "vendor/thrift.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/garru/ruby_scribe_client}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby_scribe_client", "--main", "README"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garru-ruby_scribe_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Tsang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,9 +22,11 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- CHANGELOG
|
24
24
|
- lib/ruby_scribe_client/FacebookService.rb
|
25
|
+
- lib/ruby_scribe_client/fb303_client.rb
|
25
26
|
- lib/ruby_scribe_client/fb303_types.rb
|
26
27
|
- lib/ruby_scribe_client/reflection_limited_types.rb
|
27
28
|
- lib/ruby_scribe_client/scribe.rb
|
29
|
+
- lib/ruby_scribe_client/scribe_mgmt.rb
|
28
30
|
- lib/ruby_scribe_client/scribe_types.rb
|
29
31
|
- lib/ruby_scribe_client.rb
|
30
32
|
- LICENSE
|
@@ -32,10 +34,14 @@ extra_rdoc_files:
|
|
32
34
|
files:
|
33
35
|
- CHANGELOG
|
34
36
|
- etc/scribe_cat.rb
|
37
|
+
- etc/scribe_munin_plugin.rb
|
38
|
+
- etc/test.rb
|
35
39
|
- lib/ruby_scribe_client/FacebookService.rb
|
40
|
+
- lib/ruby_scribe_client/fb303_client.rb
|
36
41
|
- lib/ruby_scribe_client/fb303_types.rb
|
37
42
|
- lib/ruby_scribe_client/reflection_limited_types.rb
|
38
43
|
- lib/ruby_scribe_client/scribe.rb
|
44
|
+
- lib/ruby_scribe_client/scribe_mgmt.rb
|
39
45
|
- lib/ruby_scribe_client/scribe_types.rb
|
40
46
|
- lib/ruby_scribe_client.rb
|
41
47
|
- LICENSE
|