dashboard: add system monitoring and enhanced stats

- prominent check type badge in header (SSL/judges/http/irc)
- system monitor bar: load, memory, disk, process RSS
- anonymity breakdown: elite/anonymous/transparent counts
- database health: size, recent activity, dead proxy count
- enhanced Tor pool stats: requests, success rate, latency
- SQLite ANALYZE/VACUUM functions for query optimization
- database statistics API functions
This commit is contained in:
Username
2025-12-23 17:47:12 +01:00
parent 20fc1b01fd
commit 53f37510f3
2 changed files with 341 additions and 9 deletions

77
dbs.py
View File

@@ -476,3 +476,80 @@ def get_stats_history(sqlite, hours=24):
'proto_http', 'proto_socks4', 'proto_socks5']
return [dict(zip(cols, row)) for row in rows]
def analyze_database(sqlite):
"""Run ANALYZE to update SQLite query planner statistics.
Should be called periodically (e.g., hourly) for optimal query performance.
Also enables stat4 for better index statistics on complex queries.
Args:
sqlite: Database connection
"""
try:
# Enable advanced statistics (persists in database)
sqlite.execute('PRAGMA analysis_limit=1000')
# Run ANALYZE on all tables and indexes
sqlite.execute('ANALYZE')
sqlite.commit()
_log('database ANALYZE completed', 'debug')
except Exception as e:
_log('database ANALYZE failed: %s' % str(e), 'warn')
def vacuum_database(sqlite):
"""Run VACUUM to reclaim unused space and defragment database.
Should be called infrequently (e.g., daily or weekly) as it's expensive.
Requires no active transactions.
Args:
sqlite: Database connection
"""
try:
sqlite.execute('VACUUM')
_log('database VACUUM completed', 'info')
except Exception as e:
_log('database VACUUM failed: %s' % str(e), 'warn')
def get_database_stats(sqlite):
"""Get database statistics for monitoring.
Args:
sqlite: Database connection
Returns:
Dict with database statistics
"""
stats = {}
try:
row = sqlite.execute('PRAGMA page_count').fetchone()
stats['page_count'] = row[0] if row else 0
row = sqlite.execute('PRAGMA page_size').fetchone()
stats['page_size'] = row[0] if row else 4096
row = sqlite.execute('PRAGMA freelist_count').fetchone()
stats['freelist_count'] = row[0] if row else 0
# Calculate sizes
stats['total_size'] = stats['page_count'] * stats['page_size']
stats['free_size'] = stats['freelist_count'] * stats['page_size']
stats['used_size'] = stats['total_size'] - stats['free_size']
# Table row counts
row = sqlite.execute('SELECT COUNT(*) FROM proxylist').fetchone()
stats['proxy_count'] = row[0] if row else 0
row = sqlite.execute('SELECT COUNT(*) FROM proxylist WHERE failed=0').fetchone()
stats['working_count'] = row[0] if row else 0
row = sqlite.execute('SELECT COUNT(*) FROM uris').fetchone()
stats['uri_count'] = row[0] if row else 0
except Exception:
pass
return stats