Managing servers through stats page
pull/19/head
Aidaho12 2018-05-14 00:07:33 +06:00
parent d1ba6f1568
commit 8777d65598
7 changed files with 76 additions and 26 deletions

View File

@ -6,21 +6,22 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers. Leave
# Features: # Features:
1. Configure HAproxy In a jiffy with haproxy-wi 1. Configure HAproxy In a jiffy with haproxy-wi
2. View and analyse Status of all Frontend/backend server via haproxy-wi from a single control panel. 2. View and analyse Status of all Frontend/backend server via haproxy-wi from a single control panel.
3. View/Analyse HAproxy logs straight from the haproxy-wi web interface 3. Enable/disable servers through stats page without rebooting HAProxy
4. Create and visualise the HAproxy workflow from Web Ui. 4. View/Analyse HAproxy logs straight from the haproxy-wi web interface
5. Push Your changes to your HAproxy servers with a single click through web interface. 5. Create and visualise the HAproxy workflow from Web Ui.
6. Get info on past changes, Evaluate your config files and restore a previous stable config anytime with a single click straight from Web interface. 6. Push Your changes to your HAproxy servers with a single click through web interface.
7. Add/Edit Frontend or backend servers via web interface with a click of a button. 7. Get info on past changes, Evaluate your config files and restore a previous stable config anytime with a single click straight from Web interface.
8. Edit config of HAproxy and push changes to All Master/Slave server with a single click. 8. Add/Edit Frontend or backend servers via web interface with a click of a button.
9. Add Multiple server to ensure Config Sync between servers. 9. Edit config of HAproxy and push changes to All Master/Slave server with a single click.
10. Auto management of ports assigned to Fronted. 10. Add Multiple server to ensure Config Sync between servers.
11. Evaluate the changes of recent configs pushed to HAproxy instances straight from web ui 11. Auto management of ports assigned to Fronted.
12. Multiple User Roles support for privileged based Viewing and editing of Config. 12. Evaluate the changes of recent configs pushed to HAproxy instances straight from web ui
13. Create Groups and add /remove servers to ensure proper identification for your HAproxy Clusters 13. Multiple User Roles support for privileged based Viewing and editing of Config.
14. Send notifications to telegram directly from haproxy-wi. 14. Create Groups and add /remove servers to ensure proper identification for your HAproxy Clusters
15. haproxy-wi supports high Availability to ensure uptime to all Master slave servers configured. 15. Send notifications to telegram directly from haproxy-wi.
16. SSL certificate support. 16. haproxy-wi supports high Availability to ensure uptime to all Master slave servers configured.
17. SSH Key support for managing multiple HAproxy Servers straight from haproxy-wi 17. SSL certificate support.
18. SSH Key support for managing multiple HAproxy Servers straight from haproxy-wi
# Install # Install
@ -96,6 +97,8 @@ For Runtime API enable state file on HAproxt servers and need install socat on a
server-state-file /etc/haproxy/haproxy/haproxy.state server-state-file /etc/haproxy/haproxy/haproxy.state
defaults defaults
load-server-state-from-file global load-server-state-from-file global
listen stats
stats admin if TRUE
``` ```
![alt text](image/haproxy-wi-logs.jpeg "View logs page") ![alt text](image/haproxy-wi-logs.jpeg "View logs page")

View File

@ -101,9 +101,9 @@ if form.getvalue('showif'):
commands = ["sudo ip link|grep 'UP' | awk '{print $2}' |awk -F':' '{print $1}'"] commands = ["sudo ip link|grep 'UP' | awk '{print $2}' |awk -F':' '{print $1}'"]
funct.ssh_command(serv, commands, ip="1") funct.ssh_command(serv, commands, ip="1")
if form.getvalue('action') is not None and serv is not None: if form.getvalue('action_hap') is not None and serv is not None:
serv = form.getvalue('serv') serv = form.getvalue('serv')
action = form.getvalue('action') action = form.getvalue('action_hap')
if funct.check_haproxy_config(serv): if funct.check_haproxy_config(serv):
commands = [ "sudo systemctl %s haproxy" % action ] commands = [ "sudo systemctl %s haproxy" % action ]
@ -117,6 +117,31 @@ if act == "overview":
if act == "overviewServers": if act == "overviewServers":
ovw.get_overviewServers() ovw.get_overviewServers()
if form.getvalue('action'):
import requests
import json
from requests_toolbelt.utils import dump
haproxy_user = config.get('haproxy', 'stats_user')
haproxy_pass = config.get('haproxy', 'stats_password')
stats_port = config.get('haproxy', 'stats_port')
stats_page = config.get('haproxy', 'stats_page')
postdata = {
'action' : form.getvalue('action'),
's' : form.getvalue('s'),
'b' : form.getvalue('b')
}
headers = {
'User-Agent' : 'Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' : 'en-US,en;q=0.5',
'Accept-Encoding' : 'gzip, deflate'
}
q = requests.post('http://'+serv+':'+stats_port+'/'+stats_page, headers=headers, data=postdata, auth=(haproxy_user, haproxy_pass))
if serv is not None and act == "stats": if serv is not None and act == "stats":
import requests import requests
from requests_toolbelt.utils import dump from requests_toolbelt.utils import dump
@ -134,7 +159,7 @@ if serv is not None and act == "stats":
except requests.exceptions.HTTPError as errh: except requests.exceptions.HTTPError as errh:
print ("Http Error:",errh) print ("Http Error:",errh)
except requests.exceptions.ConnectionError as errc: except requests.exceptions.ConnectionError as errc:
print ("Error Connecting:",errc) print ('<div class="alert alert-danger">Error Connecting: %s</div>' % errc)
except requests.exceptions.Timeout as errt: except requests.exceptions.Timeout as errt:
print ("Timeout Error:",errt) print ("Timeout Error:",errt)
except requests.exceptions.RequestException as err: except requests.exceptions.RequestException as err:
@ -192,7 +217,7 @@ if form.getvalue('servaction') is not None:
enable = form.getvalue('servaction') enable = form.getvalue('servaction')
backend = form.getvalue('servbackend') backend = form.getvalue('servbackend')
cmd='echo "%s %s" |sudo socat stdio %s | cut -d "," -f 1-2,5-10,34-36 | column -s, -t' % (enable, backend, haproxy_sock) cmd='echo "%s %s" |sudo socat stdio %s | cut -d "," -f 1-2,5-10,18,34-36 | column -s, -t' % (enable, backend, haproxy_sock)
if form.getvalue('save') == "on": if form.getvalue('save') == "on":
save_command = 'echo "show servers state" | sudo socat stdio %s > %s' % (haproxy_sock, server_state_file) save_command = 'echo "show servers state" | sudo socat stdio %s > %s' % (haproxy_sock, server_state_file)

View File

@ -98,7 +98,7 @@
{% endif %} {% endif %}
</ul> </ul>
</nav> </nav>
<div class="copyright-menu">HAproxy-WI v2.5.4.2</div> <div class="copyright-menu">HAproxy-WI v2.5.4.3</div>
</div> </div>
</div> </div>
<div class="container"> <div class="container">

View File

@ -15,6 +15,29 @@
<a class="ui-button ui-widget ui-corner-all" id="show" title="Show stats" onclick="{{ onclick }}">Show</a> <a class="ui-button ui-widget ui-corner-all" id="show" title="Show stats" onclick="{{ onclick }}">Show</a>
</form> </form>
<div id="ajax" style="margin-left: 10px;"></div> <div id="ajax" style="margin-left: 10px;"></div>
<script> window.onload = showStats()</script> <script>
window.onload = showStats();
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function wait() {
await sleep(2000);
$('form').append('<input type="hidden" name="serv" value='+$("#serv").val()+'>');
$("form").submit(function() {
$.ajax({
type: "get",
url: "options.py",
dataType: "text",
data: $(this).serialize(),
success: function( data ) {
//$("#ajax").html(data);
showStats();
}
});
return false;
});
}
</script>
<link href="/inc/style.css" rel="stylesheet"> <link href="/inc/style.css" rel="stylesheet">
{% endblock %} {% endblock %}

View File

@ -1,10 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import html, http, os import html, http.cookies, os
import cgi import cgi
import requests
import funct import funct
import sql import sql
from requests_toolbelt.utils import dump
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/')) env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('viewstats.html') template = env.get_template('viewstats.html')

View File

@ -5,7 +5,7 @@ function ajaxActionServers(action, id) {
$.ajax( { $.ajax( {
url: "options.py", url: "options.py",
data: { data: {
action: action, action_hap: action,
serv: id serv: id
}, },
success: function( data ) { success: function( data ) {

View File

@ -137,6 +137,7 @@ function showStats() {
success: function( data ) { success: function( data ) {
$("#ajax").html(data); $("#ajax").html(data);
window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val()); window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val());
wait();
} }
} ); } );
} }