hastats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +9 -0
- data/README.rdoc +14 -0
- data/Rakefile +1 -0
- data/bin/hastats +70 -0
- data/hastats.gemspec +25 -0
- data/lib/hastats/actions/base.rb +22 -0
- data/lib/hastats/actions/disable.rb +12 -0
- data/lib/hastats/actions/enable.rb +12 -0
- data/lib/hastats/actions/info.rb +11 -0
- data/lib/hastats/actions/stat.rb +11 -0
- data/lib/hastats/actions.rb +8 -0
- data/lib/hastats/responses/base.rb +20 -0
- data/lib/hastats/responses/blank_result.rb +11 -0
- data/lib/hastats/responses/csv.rb +24 -0
- data/lib/hastats/responses/text.rb +12 -0
- data/lib/hastats/responses.rb +7 -0
- data/lib/hastats/socket.rb +27 -0
- data/lib/hastats/text_response.rb +1 -0
- data/lib/hastats/version.rb +4 -0
- data/lib/hastats.rb +11 -0
- metadata +115 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
== HAStats -- An HAProxy socket tool for Ruby
|
2
|
+
|
3
|
+
HAStats communicates with a running HAProxy process through the "stats socket" (not enabled by default). Through this socket you can query stats, reset counters, change server weightings, put servers in maintenance mode, and more.
|
4
|
+
|
5
|
+
=== Using the command line tool
|
6
|
+
|
7
|
+
$ hastats info
|
8
|
+
Name: HAProxy
|
9
|
+
Version: 1.4.8
|
10
|
+
Release_date: 2010/06/16
|
11
|
+
Nbproc: 1
|
12
|
+
Process_num: 1
|
13
|
+
...
|
14
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hastats
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hastats'
|
5
|
+
require 'thor'
|
6
|
+
|
7
|
+
class HAStats::Bin < Thor
|
8
|
+
map %w(-h --help) => :help
|
9
|
+
class_option :socket, :aliases => %w(-s), :default => '/usr/local/var/run/haproxy.sock'
|
10
|
+
class_option :json, :aliases => %w(-j), :type => :boolean, :default => false, :desc => "Return results in JSON for easy parsing"
|
11
|
+
|
12
|
+
desc 'info', 'Get information about the HAProxy process'
|
13
|
+
def info
|
14
|
+
print_result HAStats::Actions::Info.new(options[:socket]).run
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'stat', 'Get information about all frontends/backends/servers'
|
18
|
+
def stat
|
19
|
+
print_result HAStats::Actions::Stat.new(options[:socket]).run
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'disable [BACKEND] [SERVER]', 'Put a server into MAINT mode'
|
23
|
+
def disable(backend, server)
|
24
|
+
print_result HAStats::Actions::Disable.new(options[:socket]).run(backend, server)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'enable [BACKEND] [SERVER]', 'Remove a server from MAINT mode'
|
28
|
+
def enable(backend, server)
|
29
|
+
print_result HAStats::Actions::Enable.new(options[:socket]).run(backend, server)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'sess', '[FUTURE] Get current session information'
|
33
|
+
def sess
|
34
|
+
raise NotImplementedError
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'errors', '[FUTURE] Get current error information'
|
38
|
+
def errors
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'clear', '[FUTURE] Clear counter maximums (see --all option)'
|
43
|
+
method_option :all, :type => :boolean, :default => false, :desc => "Clear all counters"
|
44
|
+
def clear
|
45
|
+
raise NotImplementedError
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'set_weight [BACKEND] [SERVER] [WEIGHT]', '[FUTURE] Set a server\'s weight. Weight is a number or percentage of current weight'
|
49
|
+
def set_weight(backend, server, weight)
|
50
|
+
raise NotImplementedError
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'get_weight [BACKEND]/[SERVER]', '[FUTURE] Get a server\'s weight'
|
54
|
+
def get_weight(backend, server)
|
55
|
+
raise NotImplementedError
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def print_result(result)
|
61
|
+
if options[:json]
|
62
|
+
puts result.to_json
|
63
|
+
else
|
64
|
+
puts result.raw
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
HAStats::Bin.start
|
70
|
+
|
data/hastats.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hastats/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hastats"
|
7
|
+
s.version = HAStats::VERSION
|
8
|
+
s.authors = ["Travis Petticrew"]
|
9
|
+
s.email = ["bobo@petticrew.net"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A tool for interfacing with HAProxy through UNIX sockets}
|
12
|
+
s.description = %q{Allows reading and writing to the haproxy stats socket. See the HAProxy documentation for available commands.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "hastats"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "thor", '~>0.14.6'
|
24
|
+
s.add_runtime_dependency "json", '>=1'
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class HAStats::Actions::Base
|
2
|
+
|
3
|
+
attr_accessor :socket, :options
|
4
|
+
|
5
|
+
def initialize(socket, options={})
|
6
|
+
self.socket = socket.is_a?(HAStats::Socket) ? socket : HAStats::Socket.new(socket)
|
7
|
+
self.options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(*args)
|
11
|
+
response.new socket.run(command(*args))
|
12
|
+
end
|
13
|
+
|
14
|
+
def response
|
15
|
+
HAStats::Responses::Base
|
16
|
+
end
|
17
|
+
|
18
|
+
def command(*args)
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class HAStats::Responses::Base
|
2
|
+
|
3
|
+
attr_accessor :raw, :parsed
|
4
|
+
|
5
|
+
def initialize(raw)
|
6
|
+
self.raw = raw
|
7
|
+
parse
|
8
|
+
end
|
9
|
+
|
10
|
+
# The base class does no parsing
|
11
|
+
def parse
|
12
|
+
self.parsed = self.raw
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json
|
16
|
+
JSON.dump(self.parsed)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
class HAStats::Responses::CSV < HAStats::Responses::Base
|
4
|
+
|
5
|
+
def parse
|
6
|
+
self.parsed = []
|
7
|
+
header = nil
|
8
|
+
self.raw.each do |row|
|
9
|
+
row = CSV.parse(row.gsub(/#*\s*/, '').strip).first
|
10
|
+
if row && header
|
11
|
+
result = {}
|
12
|
+
header.each_index do |i|
|
13
|
+
result[header[i]] = row[i]
|
14
|
+
end
|
15
|
+
self.parsed << result
|
16
|
+
elsif row
|
17
|
+
header = row
|
18
|
+
end
|
19
|
+
end
|
20
|
+
self.parsed
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class HAStats::Responses::Text < HAStats::Responses::Base
|
2
|
+
|
3
|
+
def parse
|
4
|
+
self.parsed = {}
|
5
|
+
self.raw.split("\n").each do |line|
|
6
|
+
name, value = line.split(/:/, 2)
|
7
|
+
self.parsed[name.strip.downcase.to_sym] = value.strip if name && value
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class HAStats::Socket
|
2
|
+
|
3
|
+
attr_accessor :socket_addr
|
4
|
+
|
5
|
+
def initialize(socket_addr)
|
6
|
+
@socket_addr = socket_addr
|
7
|
+
end
|
8
|
+
|
9
|
+
def socket
|
10
|
+
@socket ||= UNIXSocket.new(socket_addr)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset
|
14
|
+
@socket = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(cmd)
|
18
|
+
reset
|
19
|
+
socket.puts(cmd)
|
20
|
+
result = ""
|
21
|
+
while out = socket.gets
|
22
|
+
result += out
|
23
|
+
end
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/lib/hastats.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hastats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Travis Petticrew
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
type: :runtime
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 43
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 14
|
32
|
+
- 6
|
33
|
+
version: 0.14.6
|
34
|
+
name: thor
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
prerelease: false
|
38
|
+
type: :runtime
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 1
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
version: "1"
|
48
|
+
name: json
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Allows reading and writing to the haproxy stats socket. See the HAProxy documentation for available commands.
|
51
|
+
email:
|
52
|
+
- bobo@petticrew.net
|
53
|
+
executables:
|
54
|
+
- hastats
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- Gemfile
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- bin/hastats
|
65
|
+
- hastats.gemspec
|
66
|
+
- lib/hastats.rb
|
67
|
+
- lib/hastats/actions.rb
|
68
|
+
- lib/hastats/actions/base.rb
|
69
|
+
- lib/hastats/actions/disable.rb
|
70
|
+
- lib/hastats/actions/enable.rb
|
71
|
+
- lib/hastats/actions/info.rb
|
72
|
+
- lib/hastats/actions/stat.rb
|
73
|
+
- lib/hastats/responses.rb
|
74
|
+
- lib/hastats/responses/base.rb
|
75
|
+
- lib/hastats/responses/blank_result.rb
|
76
|
+
- lib/hastats/responses/csv.rb
|
77
|
+
- lib/hastats/responses/text.rb
|
78
|
+
- lib/hastats/socket.rb
|
79
|
+
- lib/hastats/text_response.rb
|
80
|
+
- lib/hastats/version.rb
|
81
|
+
homepage: ""
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project: hastats
|
110
|
+
rubygems_version: 1.8.9
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: A tool for interfacing with HAProxy through UNIX sockets
|
114
|
+
test_files: []
|
115
|
+
|