forked from unixsurfer/haproxytool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pavlos Parissis
committed
May 12, 2015
0 parents
commit 50a5315
Showing
13 changed files
with
1,217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pavlos Parissis <pavlos.parissis@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
CHANGES | ||
======= | ||
|
||
0.0.7 | ||
----- | ||
|
||
* bump version in cli.py | ||
* Update ChangeLog | ||
* use only left-aligned | ||
* use left-aligned and right-aligned in the output for servers | ||
* update ChangeLog | ||
|
||
0.0.6 | ||
----- | ||
|
||
* bump version in cli.py | ||
* change default socket dir and remove equal from usage pattern for D | ||
* Work with Python2.7 as haproxyadmin library is Python2.7 compatible | ||
* ChangeLog updates | ||
|
||
0.0.5 | ||
----- | ||
|
||
* Bumps version in cli.py | ||
* ChangeLog updates | ||
* Switches to gmail e-mail address | ||
* Adds README.rst | ||
|
||
0.0.4 | ||
----- | ||
|
||
* Bumps version in cli.py | ||
|
||
0.0.3 | ||
----- | ||
|
||
* Fix alignment in usage | ||
* Adds AUTHORS, updates ChangeLog | ||
|
||
0.0.2 | ||
----- | ||
|
||
* Drop haproxy from the file names | ||
|
||
0.0.1 | ||
----- | ||
|
||
* adds banner:- | ||
* remove extension | ||
* fix wrong path on import(thanks Juliano) | ||
* removed unused code | ||
* setup tools | ||
* it should be ready now | ||
* haproxy_dump | ||
* bugs | ||
* server is ready | ||
* refactored and moved to haproxytool dir | ||
* pylint complains and rename SETTING to OPTION | ||
* Initial commit |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.. haproxytool | ||
.. README.rst | ||
haproxytool | ||
================= | ||
|
||
*A tool to manage HAProxy via stats socket.* | ||
|
||
.. contents:: | ||
|
||
Release | ||
------- | ||
|
||
To make a release you should first create a signed tag, pbr will use this for the version number:: | ||
|
||
git tag -s 0.0.9 -m 'bump release' | ||
git push --tags | ||
|
||
Create the source distribution archive (the archive will be placed in the **dist** directory):: | ||
|
||
python setup.py sdist | ||
|
||
Installation | ||
------------ | ||
|
||
From Source:: | ||
|
||
sudo python setup.py install | ||
|
||
Build (source) RPMs:: | ||
|
||
python setup.py clean --all; python setup.py bdist_rpm | ||
|
||
Booking.com instructions:: | ||
|
||
python setup.py clean --all | ||
python setup.py sdist | ||
|
||
Build a source archive for manual installation:: | ||
|
||
python setup.py sdist | ||
|
||
Usage | ||
----- | ||
TOBEADDED | ||
|
||
Licensing | ||
--------- | ||
|
||
GPLv2 | ||
|
||
Contacts | ||
-------- | ||
|
||
**Project website**: https://github.com/unixsurfer/haproxytool | ||
|
||
**Author**: Palvos Parissis <pavlos.parissis@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
2 | ||
# _ _ _ | ||
# | |__ __ _ _ __ _ __ _____ ___ _| |_ ___ ___ | | | ||
# | '_ \ / _` | '_ \| '__/ _ \ \/ / | | | __/ _ \ / _ \| | | ||
# | | | | (_| | |_) | | | (_) > <| |_| | || (_) | (_) | | | ||
# |_| |_|\__,_| .__/|_| \___/_/\_\\__, |\__\___/ \___/|_| | ||
# |_| |___/' | ||
__title__ = 'haproxytool' | ||
__author__ = 'Pavlos Parissis' | ||
__license__ = 'GNU GENERAL PUBLIC LICENSE Version 2' | ||
__copyright__ = 'Copyright 2015 Pavlos Parissis' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
# File name: haproxy_pool.py | ||
# | ||
# Creation date: 09-05-2015 | ||
# | ||
# Created by: Pavlos Parissis <pavlos.parissis@booking.com> | ||
# | ||
"""A tool to manage HAProxy via the stats socket. | ||
Usage: haproxytool [-v | -h | --socket-dir DIR] <command> [<args>...] | ||
Options: | ||
-h, --help show this screen. | ||
-v, --version show version. | ||
-D DIR, --socket-dir=DIR directory with HAProxy socket files [default: /var/lib/haproxy] | ||
Arguments: | ||
DIR a directory path | ||
Avalable haproxytool commands are: | ||
frontend Frontend operations | ||
pool Pool operations | ||
server Server operations | ||
haproxy HAProxy operations | ||
dump Dumps all informations | ||
See 'haproxytool help <command>' for more information on a specific command. | ||
""" | ||
from docopt import docopt | ||
from operator import methodcaller | ||
|
||
|
||
def main(): | ||
args = docopt(__doc__, version='haproxytool 0.0.7', options_first=True) | ||
|
||
# print('global arguments:') | ||
# print(args) | ||
# print('command arguments:') | ||
call_main = methodcaller('main') | ||
|
||
our_cmds = ['frontend', 'pool', 'server', 'dump', 'haproxy'] | ||
if args['<command>'] in our_cmds: | ||
# get module path | ||
module = __import__('haproxytool.%s' % args['<command>']) | ||
# get the module object | ||
module_object = getattr(module, '%s' % args['<command>']) | ||
# run the main from the module object | ||
call_main(module_object) | ||
elif args['<command>'] == 'help': | ||
if len(args['<args>']) == 1 and args['<args>'][0] in our_cmds: | ||
module = __import__('haproxytool.%s' % args['<args>'][0]) | ||
module_object = getattr(module, '%s' % args['<args>'][0]) | ||
call_main(module_object) | ||
else: | ||
exit("use one of {} in help command".format(','.join(our_cmds))) | ||
else: | ||
exit("{} isn't a haproxytool command. See 'haproxytool --help'." | ||
.format(args['<command>'])) | ||
|
||
# This is the standard boilerplate that calls the main() function. | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3.4 | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
# pylint: disable=superfluous-parens | ||
# | ||
# File name: haproxy_dump.py | ||
# | ||
# Creation date: 09-05-2015 | ||
# | ||
# Created by: Pavlos Parissis <pavlos.parissis@booking.com> | ||
# | ||
"""Dump a collection of information about frontends, pools and servers | ||
Usage: | ||
haproxytool dump [-fpsh -D DIR ] | ||
Options: | ||
-h, --help show this screen | ||
-f, --frontends show frontends | ||
-p, --pools show pool | ||
-s, --servers show server | ||
-D DIR, --socket-dir=DIR directory with HAProxy socket files | ||
[default: /var/lib/haproxy] | ||
""" | ||
from docopt import docopt | ||
from haproxyadmin import haproxy | ||
|
||
|
||
def get_pools(hap): | ||
print("# pool name, status, requests, members") | ||
for pool in hap.pools(): | ||
members = ','.join([x.name for x in pool.members()]) | ||
print("{},{},{},{}".format(pool.name, pool.status, pool.requests, | ||
members)) | ||
|
||
|
||
def get_frontends(hap): | ||
print("# frontend name, status, requests, process_nb") | ||
for frontend in hap.frontends(): | ||
print("{},{},{},{}".format(frontend.name, frontend.status, | ||
frontend.requests, frontend.process_nb)) | ||
|
||
|
||
def get_servers(hap): | ||
print("# server name, status, requests, pool") | ||
for server in hap.members(): | ||
print("{},{},{},{}".format(server.name, server.status, server.requests, | ||
server.poolname)) | ||
|
||
|
||
def dump(hap): | ||
get_frontends(hap) | ||
get_pools(hap) | ||
get_servers(hap) | ||
|
||
|
||
def main(): | ||
arguments = docopt(__doc__) | ||
hap = haproxy.HAProxy(socket_dir=arguments['--socket-dir']) | ||
|
||
if (not arguments['--frontends'] and not arguments['--pools'] and not | ||
arguments['--servers']): | ||
dump(hap) | ||
|
||
if arguments['--frontends']: | ||
get_frontends(hap) | ||
|
||
if arguments['--pools']: | ||
get_pools(hap) | ||
|
||
if arguments['--servers']: | ||
get_servers(hap) | ||
|
||
# This is the standard boilerplate that calls the main() function. | ||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.