pull/30/head
Aidaho12 2018-08-06 22:18:12 +06:00
parent 04dfb0d98b
commit 4232833dd1
4 changed files with 48 additions and 67 deletions

View File

@ -354,6 +354,19 @@ if form.getvalue('masteradd'):
if form.getvalue('haproxyaddserv'):
funct.install_haproxy(form.getvalue('haproxyaddserv'), syn_flood=form.getvalue('syn_flood'))
if form.getvalue('table_metrics'):
import http.cookies
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'))
template = env.get_template('table_metrics.html')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
table_stat = sql.select_table_metrics(user_id.value)
template = template.render(table_stat = sql.select_table_metrics(user_id.value))
print(template)
if form.getvalue('metrics'):
from datetime import timedelta
from bokeh.plotting import figure, output_file, show
@ -362,15 +375,13 @@ if form.getvalue('metrics'):
from bokeh.models.widgets import Button, RadioButtonGroup, Select
import pandas as pd
import http.cookies
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
servers = sql.select_servers_metrics(user_id.value)
p = {}
k = 0
for serv in servers:
k += 1
serv = serv[0]
p[serv] = {}
metric = sql.select_metrics(serv)
@ -414,25 +425,21 @@ if form.getvalue('metrics'):
)
p[serv].ygrid.band_fill_color = "#f3f8fb"
#p[serv].ygrid.band_fill_alpha = 0.1
p[serv].ygrid.band_fill_alpha = 0.9
p[serv].y_range.start = 0
p[serv].y_range.end = int(df['curr_con'].max()) + 150
p[serv].add_tools(hover)
p[serv].title.text_font_size = "20px"
if k == 1:
p[serv].line("Date", "curr_con", source=source, alpha=0.5, color='#5cb85c', line_width=2, legend="Conn")
p[serv].line("Date", "curr_ssl_con", source=source, alpha=0.5, color="#5d9ceb", line_width=2, legend="SSL con")
p[serv].line("Date", "sess_rate", source=source, alpha=0.5, color="#33414e", line_width=2, legend="Sessions")
#p[serv].line("Date", "max_sess_rate", source=source, alpha=0.5, color="red", line_width=2, legend="Max sess")
p[serv].legend.orientation = "horizontal"
p[serv].legend.location = "top_left"
p[serv].legend.padding = 5
else:
p[serv].line("Date", "curr_con", source=source, alpha=0.5, color='#5cb85c', line_width=2)
p[serv].line("Date", "curr_ssl_con", source=source, alpha=0.5, color="#5d9ceb", line_width=2)
p[serv].line("Date", "sess_rate", source=source, alpha=0.5, color="#33414e", line_width=2)
#p[serv].line("Date", "max_sess_rate", source=source, alpha=0.5, color="red", line_width=2)
p[serv].line("Date", "curr_con", source=source, alpha=0.5, color='#5cb85c', line_width=2, legend="Conn")
p[serv].line("Date", "curr_ssl_con", source=source, alpha=0.5, color="#5d9ceb", line_width=2, legend="SSL con")
p[serv].line("Date", "sess_rate", source=source, alpha=0.5, color="#33414e", line_width=2, legend="Sessions")
#p[serv].line("Date", "max_sess_rate", source=source, alpha=0.5, color="red", line_width=2, legend="Max sess")
p[serv].legend.orientation = "horizontal"
p[serv].legend.location = "top_left"
p[serv].legend.padding = 5
#select = Select(title="Option:", value="foo", options=["foo", "bar", "baz", "quux"])
#show(widgetbox(select, width=300))

View File

@ -709,6 +709,7 @@ def select_servers_metrics(uuid, **kwargs):
def select_table_metrics(uuid):
con, cur = create_db.get_cur()
groups = ""
sql = """ select * from user where username = '%s' """ % get_user_name_by_uuid(uuid)
try:
@ -721,6 +722,7 @@ def select_table_metrics(uuid):
groups = ""
else:
groups = "and servers.groups like '%{group}%' ".format(group=group[5])
sql = """
select ip.ip, hostname, avg_sess_1h, avg_sess_24h, avg_sess_3d, max_sess_1h, max_sess_24h, max_sess_3d, avg_cur_1h, avg_cur_24h, avg_cur_3d, max_con_1h, max_con_24h, max_con_3d from
(select servers.ip from servers where metrics = 1 ) as ip,
@ -813,12 +815,14 @@ def select_table_metrics(uuid):
and ip.ip=max_con_24h.ip
and ip.ip=max_con_3d.ip
group by ip.ip""" % groups
group by hostname.ip """ % groups
try:
cur.execute(sql)
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
print('<span class="alert alert-danger" id="error">An error occurred: ' + e.args[0] + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
else:
return cur.fetchall()
cur.close()
con.close()

View File

@ -16,51 +16,9 @@ th, tr, td {
}
</style>
<table>
<tr class="overviewHead">
<th colspan=13>Metrics</th>
</tr>
<tr>
<th class="padding10 first-collumn overviewTr" rowspan=2>Server</th>
<th colspan=3>Average sessions</th>
<th colspan=3>Peak sessions</th>
<th colspan=3>Average connections</th>
<th colspan=3>Peak connections</th>
</tr>
<tr class="overviewHead">
<th>60 minutes</th>
<th>24 hours</th>
<th>3 days</th>
<th>60 minutes</th>
<th>24 hours</th>
<th>3 days</th>
<th>60 minutes</th>
<th>24 hours</th>
<th>3 days</th>
<th>60 minutes</th>
<th>24 hours</th>
<th>3 days</th>
</tr>
{% for val in table_stat %}
<tr class="{{ loop.cycle('odd', 'even') }}">
<td class="padding10 first-collumn overviewTr"><span title="{{ val.0 }}">{{ val.1 }}</span></td>
<td>{{ val.2 }}</td>
<td>{{ val.3 }}</td>
<td>{{ val.4 }}</td>
<td>{{ val.5 }}</td>
<td>{{ val.6 }}</td>
<td>{{ val.7 }}</td>
<td>{{ val.8 }}</td>
<td>{{ val.9 }}</td>
<td>{{ val.10 }}</td>
<td>{{ val.11 }}</td>
<td>{{ val.12 }}</td>
<td>{{ val.13 }}</td>
</tr>
{% endfor %}
</table>
<div id="metrics_iframe"></div>
<script>
<div id="table_metrics"></div>
<div id="metrics_iframe"></div>
<script>
function callIframe(url, callback) {
$('#metrics_iframe').html('<iframe id="metrics" style="width:100%;height:100%;" />');
$('iframe#metrics').attr('src', url);
@ -74,6 +32,9 @@ function loadMetrics() {
$.get( "options.py?metrics=1&token="+$('#token').val(), function( data ) {
$( ".result" ).html( data );
});
$.get( "options.py?table_metrics=1&token="+$('#token').val(), function( data ) {
$( "#table_metrics" ).html( data );
});
});
}

View File

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block content %}
<br />
<form style="padding-left: 20px;" action="viewsttats.py" method="get">
<form style="padding-left: 5px;" action="viewsttats.py" method="get">
<select autofocus required name="serv" id="serv">
<option disabled>Choose server</option>
{% for select in selects %}
@ -15,7 +15,7 @@
<a class="ui-button ui-widget ui-corner-all" id="show" title="Show stats" onclick="{{ onclick }}">Show</a>
</form>
<br />
<div id="ajax" style="margin-left: 20px; margin-right: 5px;"></div>
<div id="ajax" style="margin-left: 5px; margin-right: 5px;"></div>
<script>
window.onload = showStats();
function sleep(ms) {
@ -26,10 +26,19 @@
$('form').append('<input type="hidden" name="token" value='+$('#token').val()+'>');
$( "input[type=submit], button" ).button();
$('li').css('margin-top', '0');
$('th').css('background-color', '#f5faf4');
$('table.tbl th.pxname').css('background-color', '#5d9ceb');
$('table.tbl th.pxname').css('width', '100%');
$('a.px:link').css('color', '#fff');
$('td').css('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif');
$('td').css('font-size', '11');
$('h1').css('display', 'none');
$('td').css('border-color', '#ddd');
$('td').css('padding', '4px');
$('th').css('padding-top', '4px');
$('th').css('padding-bottom', '4px');
$('th').css('border-color', '#ddd');
$('h1').next().css('display', 'none');
$('h1').next().next().css('display', 'none');
$('h1').next().next().next().css('display', 'none');