mirror of https://github.com/Aidaho12/haproxy-wi
v2.8
parent
b02cc2fc07
commit
89192f6a8d
|
@ -17,6 +17,7 @@ try:
|
|||
user = sql.get_user_name_by_uuid(user_id.value)
|
||||
servers = sql.get_dick_permit()
|
||||
token = sql.get_token(user_id.value)
|
||||
table_stat = sql.select_table_metrics(user_id.value)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -25,5 +26,6 @@ template = template.render(h2 = 1, title = "Metrics",
|
|||
role = sql.get_user_role_by_uuid(user_id.value),
|
||||
user = user,
|
||||
onclick = "metricsShow()",
|
||||
table_stat = sql.select_table_metrics(user_id.value),
|
||||
token = token)
|
||||
print(template)
|
|
@ -15,14 +15,14 @@ fi
|
|||
if hash apt-get 2>/dev/null; then
|
||||
sudo apt-get install haproxy socat -y
|
||||
else
|
||||
sudo wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
|
||||
wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
|
||||
sudo yum install haproxy18-1.8.1-5.el7.x86_64.rpm -y
|
||||
fi
|
||||
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
sudo yum install wget socat -y > /dev/null
|
||||
sudo wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
|
||||
wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
|
||||
sudo yum install haproxy18-1.8.1-5.el7.x86_64.rpm -y
|
||||
fi
|
||||
if [ $? -eq 1 ]
|
||||
|
|
117
app/sql.py
117
app/sql.py
|
@ -707,6 +707,123 @@ def select_servers_metrics(uuid, **kwargs):
|
|||
cur.close()
|
||||
con.close()
|
||||
|
||||
def select_table_metrics(uuid):
|
||||
con, cur = create_db.get_cur()
|
||||
sql = """ select * from user where username = '%s' """ % get_user_name_by_uuid(uuid)
|
||||
|
||||
try:
|
||||
cur.execute(sql)
|
||||
except sqltool.Error as e:
|
||||
print("An error occurred:", e)
|
||||
else:
|
||||
for group in cur:
|
||||
if group[5] == '1':
|
||||
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,
|
||||
|
||||
(select servers.ip, servers.hostname as hostname from servers left join metrics as metr on servers.ip = metr.serv where servers.metrics = 1 %s) as hostname,
|
||||
|
||||
(select servers.ip,round(avg(metr.sess_rate), 1) as avg_sess_1h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-1 hours', 'localtime')
|
||||
group by servers.ip) as avg_sess_1h,
|
||||
|
||||
(select servers.ip,round(avg(metr.sess_rate), 1) as avg_sess_24h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-24 hours', 'localtime')
|
||||
group by servers.ip) as avg_sess_24h,
|
||||
|
||||
(select servers.ip,round(avg(metr.sess_rate), 1) as avg_sess_3d from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-3 days', 'localtime')
|
||||
group by servers.ip ) as avg_sess_3d,
|
||||
|
||||
(select servers.ip,max(metr.sess_rate) as max_sess_1h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-1 hours', 'localtime')
|
||||
group by servers.ip) as max_sess_1h,
|
||||
|
||||
(select servers.ip,max(metr.sess_rate) as max_sess_24h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-24 hours', 'localtime')
|
||||
group by servers.ip) as max_sess_24h,
|
||||
|
||||
(select servers.ip,max(metr.sess_rate) as max_sess_3d from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-3 days', 'localtime')
|
||||
group by servers.ip ) as max_sess_3d,
|
||||
|
||||
(select servers.ip,round(avg(metr.curr_con+metr.cur_ssl_con), 1) as avg_cur_1h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-1 hours', 'localtime')
|
||||
group by servers.ip) as avg_cur_1h,
|
||||
|
||||
(select servers.ip,round(avg(metr.curr_con+metr.cur_ssl_con), 1) as avg_cur_24h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-24 hours', 'localtime')
|
||||
group by servers.ip) as avg_cur_24h,
|
||||
|
||||
(select servers.ip,round(avg(metr.curr_con+metr.cur_ssl_con), 1) as avg_cur_3d from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-3 days', 'localtime')
|
||||
group by servers.ip ) as avg_cur_3d,
|
||||
|
||||
(select servers.ip,max(metr.curr_con) as max_con_1h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-1 hours', 'localtime')
|
||||
group by servers.ip) as max_con_1h,
|
||||
|
||||
(select servers.ip,max(metr.curr_con) as max_con_24h from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-24 hours', 'localtime')
|
||||
group by servers.ip) as max_con_24h,
|
||||
|
||||
(select servers.ip,max(metr.curr_con) as max_con_3d from servers
|
||||
left join metrics as metr on metr.serv = servers.ip
|
||||
where servers.metrics = 1 and
|
||||
metr.date <= datetime('now', 'localtime') and metr.date >= datetime('now', '-3 days', 'localtime')
|
||||
group by servers.ip ) as max_con_3d
|
||||
|
||||
where ip.ip=hostname.ip
|
||||
and ip.ip=avg_sess_1h.ip
|
||||
and ip.ip=avg_sess_24h.ip
|
||||
and ip.ip=avg_sess_3d.ip
|
||||
and ip.ip=max_sess_1h.ip
|
||||
and ip.ip=max_sess_24h.ip
|
||||
and ip.ip=max_sess_3d.ip
|
||||
and ip.ip=avg_cur_1h.ip
|
||||
and ip.ip=avg_cur_24h.ip
|
||||
and ip.ip=avg_cur_3d.ip
|
||||
and ip.ip=max_con_1h.ip
|
||||
and ip.ip=max_con_24h.ip
|
||||
and ip.ip=max_con_3d.ip
|
||||
|
||||
group by ip.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>')
|
||||
else:
|
||||
return cur.fetchall()
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
|
||||
def show_update_telegram(token, page):
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader('templates/ajax'))
|
||||
|
|
|
@ -5,7 +5,60 @@ iframe {
|
|||
border: none;
|
||||
padding: 10px;
|
||||
}
|
||||
table, th, tr, td {
|
||||
border: 1px solid #ddd;
|
||||
align: center;
|
||||
text-align: center;
|
||||
}
|
||||
th, tr, td {
|
||||
width: 6%;
|
||||
padding: 10px;
|
||||
}
|
||||
</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>
|
||||
function callIframe(url, callback) {
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 301 KiB After Width: | Height: | Size: 300 KiB |
|
@ -192,10 +192,10 @@ $( function() {
|
|||
enable = '1';
|
||||
}
|
||||
if ($('#alert').is(':checked')) {
|
||||
var alert_en = 0;
|
||||
var alert_en = '1';
|
||||
}
|
||||
if ($('#metrics').is(':checked')) {
|
||||
var alert_en = 0;
|
||||
var metrics = '1';
|
||||
}
|
||||
$.ajax( {
|
||||
url: "sql.py",
|
||||
|
|
Loading…
Reference in New Issue