Parcourir la source

fix dynamic size disk usage and add enviroment variables

Manuel il y a 1 an
Parent
commit
e6113dd30a
5 fichiers modifiés avec 37 ajouts et 15 suppressions
  1. 13 8
      README.md
  2. 6 2
      parsers/cache.py
  3. 2 1
      requirements.txt
  4. 6 2
      services/fetch_data.py
  5. 10 2
      templates/components/cache_stats.html

+ 13 - 8
README.md

@@ -40,16 +40,21 @@ A modern tool for parsing and analyzing Squid logs, providing a sleek and user-f
    ```
 2. Install requeriments python:
   ```bash
-  pip install -r requirements.txt
+    pip install -r requirements.txt
+  ```
+3. Create a .env file in the project root and add the following content:
+  ```bash
+    SQUID_HOST="127.0.0.1"
+    SQUID_PORT=3128
+  ```
+4. Run App 🚀:
+  ```bash
+    python app.py
   ```
-3. Run App 🚀:
-```bash
-python app.py
-```
 4. With your preferred browser, visit the installation URL:
-```bash
-http://ip/hostname:5000
-```
+  ```bash
+    http://ip/hostname:5000 
+  ```
 
 🕒 Run on System Startup
 To ensure the application starts automatically when the system boots, add the following cron job:

+ 6 - 2
parsers/cache.py

@@ -1,8 +1,12 @@
 import socket
 import re
+from dotenv import load_dotenv
+import os
 
-SQUID_HOST = "10.34.8.15"
-SQUID_PORT = 3128
+load_dotenv()
+
+SQUID_HOST = os.getenv("SQUID_HOST", "127.0.0.1")
+SQUID_PORT = int(os.getenv("SQUID_PORT", "3128"))
 
 
 def fetch_squid_cache_stats():

+ 2 - 1
requirements.txt

@@ -1 +1,2 @@
-Flask
+Flask
+python-dotenv

+ 6 - 2
services/fetch_data.py

@@ -1,7 +1,11 @@
 import socket
+from dotenv import load_dotenv
+import os
 
-SQUID_HOST = '10.34.8.15'
-SQUID_PORT = 3128
+load_dotenv()
+
+SQUID_HOST = os.getenv("SQUID_HOST", "127.0.0.1")
+SQUID_PORT = int(os.getenv("SQUID_PORT", "3128"))
 
 def fetch_squid_data():
     try:

+ 10 - 2
templates/components/cache_stats.html

@@ -14,12 +14,20 @@
         <div class="card">
             <i class="fas fa-hdd"></i>
             <h3>Espacio total en disco</h3>
-            <p>{{ (cache_stats.fs_space_total / 1024 )|int }} MB</p>
+            {% if (cache_stats.fs_space_total / 1024) < 1024 %}
+                <p>{{ (cache_stats.fs_space_total / 1024 )|int }} MB</p>
+            {% else %}
+                <p>{{ (cache_stats.fs_space_total / 1024 / 1024 )|round(2) }} GB</p>
+            {% endif %}
         </div>
         <div class="card">
             <i class="fas fa-folder-open"></i>
             <h3>Espacio usado en disco</h3>
-            <p>{{ (cache_stats.fs_space_used / 1024 )|int }} MB</p>
+            {% if (cache_stats.fs_space_used / 1024) < 1024 %}
+                <p>{{ (cache_stats.fs_space_used / 1024 )|int }} MB</p>
+            {% else %}
+                <p>{{ (cache_stats.fs_space_used / 1024 / 1024 )|round(2) }} GB</p>
+            {% endif %}
         </div>
         <div class="card">
             <i class="fas fa-recycle"></i>