There is a huge query in sqlite of this type:
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 and servers.groups like '%2%') 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,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 If I do it directly in the database, then the output is:
172.28.5.17|server1|16.2|16.2|16.2|59|59|59|137.1|137.1|137.1|171|171|171 172.28.5.5|server12|0.0|0.0|0.0|0|0|0|0.0|0.0|0.0|0|0|0 172.28.5.6|server3|16.3|16.3|16.3|59|59|59|137.4|137.4|137.4|171|171|171 If I bring python to the site like this:
try: cur.execute(sql) except sqltool.Error as e: 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() For some reason, it is either silence or only a part of the data. I do not even know where to dig ... Tell me, who can know)
Output code:
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) print(table_stat) template = template.render(table_stat = sql.select_table_metrics(user_id.value)) print(template) UDP
#!/usr/bin/env python3 import funct from configparser import ConfigParser, ExtendedInterpolation import os import cgi import sql 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 = 'a026fef7-f1db-4342-99bb-4afa2d744617' #user_id = cookie.get('uuid') print('Content-type: text/html\n') template = template.render(table_stat = sql.select_table_metrics(user_id)) print(template) table_stat = sql.select_table_metrics('a026fef7-f1db-4342-99bb-4afa2d744617') print(sql.select_table_metrics('a026fef7-f1db-4342-99bb-4afa2d744617')) #print(table_stat)
print(cur.execute(sql).fetchall())- gil9redreturn cur.fetchall(), because There should be no problems with the sqlite driver. Here is a simple script to test this algorithm - see gil9red