v7.2.4.0: Update date calculation to use UTC and increase version number

The commit modifies the date calculation in the database time_range checks to use the UTC timezone instead of the system's local time. This makes the time range checks more uniform and independent of the server's configuration. Additionally, it increases the version number in 'create_db.py' from '7.2.3.0' to '7.2.4.0'.
pull/377/head
Aidaho 7 months ago
parent b205d47372
commit 04e39325c8

@ -755,7 +755,7 @@ def update_db_v_7_2_3():
def update_ver(): def update_ver():
try: try:
Version.update(version='7.2.3.0').execute() Version.update(version='7.2.4.0').execute()
except Exception: except Exception:
print('Cannot update version') print('Cannot update version')

@ -167,29 +167,29 @@ def select_metrics(serv, service, **kwargs):
if mysql_enable == '1': if mysql_enable == '1':
if kwargs.get('time_range') == '60': if kwargs.get('time_range') == '60':
date_from = "and date > now() - INTERVAL 60 minute group by `date` div 100" date_from = "and date > CONVERT_TZ(NOW(),'SYSTEM','+0:00') - INTERVAL 60 minute group by `date` div 100"
elif kwargs.get('time_range') == '180': elif kwargs.get('time_range') == '180':
date_from = "and date > now() - INTERVAL 180 minute group by `date` div 200" date_from = "and date > CONVERT_TZ(NOW(),'SYSTEM','+0:00') - INTERVAL 180 minute group by `date` div 200"
elif kwargs.get('time_range') == '360': elif kwargs.get('time_range') == '360':
date_from = "and date > now() - INTERVAL 360 minute group by `date` div 300" date_from = "and date > CONVERT_TZ(NOW(),'SYSTEM','+0:00') - INTERVAL 360 minute group by `date` div 300"
elif kwargs.get('time_range') == '720': elif kwargs.get('time_range') == '720':
date_from = "and date > now() - INTERVAL 720 minute group by `date` div 500" date_from = "and date > CONVERT_TZ(NOW(),'SYSTEM','+0:00') - INTERVAL 720 minute group by `date` div 500"
else: else:
date_from = "and date > now() - INTERVAL 30 minute" date_from = "and date > CONVERT_TZ(NOW(),'SYSTEM','+0:00') - INTERVAL 30 minute"
sql = """ select * from {metrics_table} where serv = '{serv}' {date_from} order by `date` asc """.format( sql = """ select * from {metrics_table} where serv = '{serv}' {date_from} order by `date` asc """.format(
metrics_table=metrics_table, serv=serv, date_from=date_from metrics_table=metrics_table, serv=serv, date_from=date_from
) )
else: else:
if kwargs.get('time_range') == '60': if kwargs.get('time_range') == '60':
date_from = "and date > datetime('now', '-60 minutes', 'localtime') and rowid % 2 = 0" date_from = "and date > datetime('now', '-60 minutes', 'UTC') and rowid % 2 = 0"
elif kwargs.get('time_range') == '180': elif kwargs.get('time_range') == '180':
date_from = "and date > datetime('now', '-180 minutes', 'localtime') and rowid % 5 = 0" date_from = "and date > datetime('now', '-180 minutes', 'UTC') and rowid % 5 = 0"
elif kwargs.get('time_range') == '360': elif kwargs.get('time_range') == '360':
date_from = "and date > datetime('now', '-360 minutes', 'localtime') and rowid % 7 = 0" date_from = "and date > datetime('now', '-360 minutes', 'UTC') and rowid % 7 = 0"
elif kwargs.get('time_range') == '720': elif kwargs.get('time_range') == '720':
date_from = "and date > datetime('now', '-720 minutes', 'localtime') and rowid % 9 = 0" date_from = "and date > datetime('now', '-720 minutes', 'UTC') and rowid % 9 = 0"
else: else:
date_from = "and date > datetime('now', '-30 minutes', 'localtime')" date_from = "and date > datetime('now', '-30 minutes', 'UTC')"
sql = """ select * from (select * from {metrics_table} where serv = '{serv}' {date_from} order by `date`) order by `date` """.format( sql = """ select * from (select * from {metrics_table} where serv = '{serv}' {date_from} order by `date`) order by `date` """.format(
metrics_table=metrics_table, serv=serv, date_from=date_from) metrics_table=metrics_table, serv=serv, date_from=date_from)

@ -357,7 +357,6 @@ def show_system_info(server_ip: str, server_id: int) -> str:
return f'Cannot update server info: {e}' return f'Cannot update server info: {e}'
else: else:
system_info = server_sql.select_one_system_info(server_id) system_info = server_sql.select_one_system_info(server_id)
return render_template('ajax/show_system_info.html', system_info=system_info, server_ip=server_ip, server_id=server_id) return render_template('ajax/show_system_info.html', system_info=system_info, server_ip=server_ip, server_id=server_id)

Loading…
Cancel
Save