Просмотр исходного кода

some update and auto refresh connections and stats

Manuel 1 год назад
Родитель
Сommit
f97764862b

+ 7 - 0
README.md

@@ -59,6 +59,7 @@ Warning: 🚨 The first execution may cause high CPU usage.
     FLASK_DEBUG = "True"
     SQUID_LOG = "/home/manuel/Desktop/SquidStats/parsers/access.log"
     DATABASE = /home/manuel/Desktop/SquidStats/logs.db
+    REFRESH_INTERVAL = 60
   ```
 4. Run App 🚀:
   ```bash
@@ -104,6 +105,12 @@ This software has been thoroughly tested and is compatible with Squid version 6.
   ```
 4.Open a pull request.
 
+<!-- CONTACT -->
+## Contact
+Manuel - ([Telegram](https://t.me/king_0f_deathhh)) ([Email](mailto:manuelalberto.gorrin@gmail.com))
+
+Project Link: ([SquidStats](https://github.com/kaelthasmanu/cucuota))
+
 ## 📄 License
 
 This project is licensed under the MIT License. See the LICENSE file for details.

+ 10 - 3
app.py

@@ -24,6 +24,8 @@ scheduler = APScheduler()
 scheduler.init_app(app)
 scheduler.start()
 
+refresh_interval = int(os.getenv("REFRESH_INTERVAL", 60))
+
 # Configure logging
 logging.basicConfig(
     level=logging.INFO,
@@ -43,7 +45,11 @@ def index():
 
         connections = parse_raw_data(raw_data)
         grouped_connections = group_by_user(connections)
-        return render_template('index.html', grouped_connections=grouped_connections)
+
+        return render_template(
+            'index.html',
+            grouped_connections=grouped_connections,
+            refresh_interval=refresh_interval)
 
     except Exception as e:
         logger.error(f"Unexpected error in index route: {str(e)}")
@@ -57,7 +63,8 @@ def cache_stats():
         data = fetch_squid_cache_stats()
         stats_data = vars(data) if hasattr(data, '__dict__') else data
         logger.info("Successfully fetched cache statistics")
-        return render_template('cacheView.html', cache_stats=stats_data)
+        return render_template('cacheView.html', cache_stats=stats_data,
+                               refresh_interval=refresh_interval)
 
     except Exception as e:
         logger.error(f"Error fetching cache stats: {str(e)}")
@@ -75,7 +82,7 @@ def logs():
         print(f"Error en ruta /logs: {e}")
         return render_template('error.html', message="Error retrieving logs"), 500
 
-@scheduler.task('interval', id='do_job_1', seconds=30, misfire_grace_time=900)
+@scheduler.task('interval', id='do_job_1', seconds=120, misfire_grace_time=900)
 def init_scheduler():
     """Initialize and start the background scheduler for log processing"""
     log_file = os.getenv("SQUID_LOG", "access.log")

+ 11 - 1
database/database.py

@@ -32,7 +32,17 @@ class Log(Base):
     user = relationship("User", back_populates="logs")
 
 def get_engine():
-    return create_engine(f"sqlite:///{os.getenv("DATABASE", "logs.db")}", echo=False)
+    db_path = os.getenv("DATABASE", "logs.db")
+    db_dir = os.path.dirname(os.path.abspath(db_path))
+
+    try:
+        if db_dir and not os.path.exists(db_dir):
+            os.makedirs(db_dir)
+    except OSError as e:
+        print("Error creando directorio para la base de datos", e)
+        return
+
+    return create_engine(f"sqlite:///{db_path}", echo=False)
 
 def get_session():
     engine = get_engine()

+ 0 - 3
parsers/cache.py

@@ -1,10 +1,7 @@
 import socket
 import re
-from dotenv import load_dotenv
 import os
 
-load_dotenv()
-
 SQUID_HOST = os.getenv("SQUID_HOST", "127.0.0.1")
 SQUID_PORT = int(os.getenv("SQUID_PORT", "3128"))
 

+ 0 - 1
requirements.txt

@@ -1,4 +1,3 @@
 Flask
-python-dotenv
 sqlalchemy
 flask_apscheduler

+ 0 - 3
services/fetch_data.py

@@ -1,9 +1,6 @@
 import socket
-from dotenv import load_dotenv
 import os
 
-load_dotenv()
-
 SQUID_HOST = os.getenv("SQUID_HOST", "127.0.0.1")
 SQUID_PORT = int(os.getenv("SQUID_PORT", "3128"))
 

+ 2 - 0
templates/components/cache_stats.html

@@ -1,3 +1,5 @@
+<meta http-equiv="refresh" content="{{ refresh_interval }}">
+
 <section class="cache-stats">
     <h2><i class="fas fa-server"></i> Estadísticas de Caché</h2>
     <div class="stats-container">

+ 2 - 2
templates/components/logs.html

@@ -1,6 +1,6 @@
 <div class="users-dashboard">
     <div class="dashboard-header">
-        <h1 class="dashboard-title">User Activity Dashboard</h1>
+        <h1 class="dashboard-title">Panel Actividad de Usuarios</h1>
 
         <div class="search-container">
             <input type="text" id="username-search" placeholder="Search by username..." class="search-input">
@@ -117,7 +117,7 @@ document.addEventListener("DOMContentLoaded", function () {
     const pageNumbers = document.getElementById("page-numbers");
 
     let currentPage = 1;
-    const itemsPerPage = 10;
+    const itemsPerPage = 12;
     let filteredUsers = [...userCards];
 
     function renderPage(page = 1) {