Update modules/database.py
This commit is contained in:
parent
a81ba6648a
commit
a766b10061
1 changed files with 37 additions and 8 deletions
|
|
@ -54,15 +54,29 @@ def add_peer_stats(stats_list):
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def get_peer_history(neighbor_address, start_date, end_date):
|
def get_peer_history(neighbor_address, start_date, end_date, interval_minutes=10):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''
|
|
||||||
SELECT timestamp, prefixes_received, prefixes_sent
|
interval_seconds = interval_minutes * 60
|
||||||
|
outlier_threshold_received = 10
|
||||||
|
|
||||||
|
query = f'''
|
||||||
|
SELECT
|
||||||
|
MAX(timestamp) as timestamp,
|
||||||
|
CAST(AVG(CASE
|
||||||
|
WHEN prefixes_received > ? THEN prefixes_received
|
||||||
|
ELSE NULL
|
||||||
|
END) AS INTEGER) as prefixes_received,
|
||||||
|
CAST(AVG(prefixes_sent) AS INTEGER) as prefixes_sent
|
||||||
FROM peer_history
|
FROM peer_history
|
||||||
WHERE neighbor_address = ? AND timestamp BETWEEN ? AND ?
|
WHERE neighbor_address = ? AND timestamp BETWEEN ? AND ?
|
||||||
|
GROUP BY
|
||||||
|
CAST(strftime('%s', timestamp) / ? AS INTEGER)
|
||||||
ORDER BY timestamp ASC
|
ORDER BY timestamp ASC
|
||||||
''', (neighbor_address, start_date, end_date))
|
'''
|
||||||
|
|
||||||
|
cursor.execute(query, (outlier_threshold_received, neighbor_address, start_date, end_date, interval_seconds))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return [dict(row) for row in rows]
|
return [dict(row) for row in rows]
|
||||||
|
|
@ -80,15 +94,30 @@ def add_total_routes_stats(stats_list):
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def get_total_routes_history(start_date, end_date):
|
def get_total_routes_history(start_date, end_date, interval_minutes=10):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''
|
|
||||||
SELECT timestamp, ip_version, total_routes
|
interval_seconds = interval_minutes * 60
|
||||||
|
outlier_threshold = 10000
|
||||||
|
|
||||||
|
query = f'''
|
||||||
|
SELECT
|
||||||
|
MAX(timestamp) as timestamp,
|
||||||
|
ip_version,
|
||||||
|
CAST(AVG(CASE
|
||||||
|
WHEN total_routes > ? THEN total_routes
|
||||||
|
ELSE NULL
|
||||||
|
END) AS INTEGER) as total_routes
|
||||||
FROM total_routes_history
|
FROM total_routes_history
|
||||||
WHERE timestamp BETWEEN ? AND ?
|
WHERE timestamp BETWEEN ? AND ?
|
||||||
|
GROUP BY
|
||||||
|
ip_version,
|
||||||
|
CAST(strftime('%s', timestamp) / ? AS INTEGER)
|
||||||
ORDER BY timestamp ASC
|
ORDER BY timestamp ASC
|
||||||
''', (start_date, end_date))
|
'''
|
||||||
|
|
||||||
|
cursor.execute(query, (outlier_threshold, start_date, end_date, interval_seconds))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return [dict(row) for row in rows]
|
return [dict(row) for row in rows]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue