Ver código fonte

feat: add auto-refresh and GitHub link options in configuration

TheHuman00 8 meses atrás
pai
commit
ec3e7980e2
2 arquivos alterados com 34 adições e 14 exclusões
  1. 15 8
      README.md
  2. 19 6
      chrony-network-stats.sh

+ 15 - 8
README.md

@@ -69,7 +69,7 @@ The script includes a configuration section at the top of `chrony-network-stats.
 
    # Enable or disable network statistics generation using vnStat
    ENABLE_NETWORK_STATS="yes"
-
+   
    # ⚠️ IMPORTANT: Replace "eth0" with your actual interface 
    #    (e.g., ens33, enp0s3, wlan0, ...)
    INTERFACE="eth0"
@@ -78,22 +78,29 @@ The script includes a configuration section at the top of `chrony-network-stats.
    OUTPUT_DIR="/var/www/html/chrony-network-stats"
    HTML_FILENAME="index.html"
 
-   ENABLE_LOGGING="yes"
-   LOG_FILE="/var/log/chrony-network-stats.log"
    RRD_DIR="/var/lib/chrony-rrd"
    RRD_FILE="$RRD_DIR/chrony.rrd"
+
+   ENABLE_LOGGING="yes"
+   LOG_FILE="/var/log/chrony-network-stats.log"
+
+   # Auto-refresh interval in seconds (0 = disabled, e.g., 300 for 5 minutes)
+   AUTO_REFRESH_SECONDS=0
+
+   ## You can display or not the link to the chrony-stats GitHub repository in the HTML page
+   ## It's completely optional by default - feel free to use it however you want, no credit needed! 👍
+   GITHUB_REPO_LINK_SHOW="no"
+
+   ###### Advanced Configuration ######
+
+   TIMEOUT_SECONDS=5
    WIDTH=800
    HEIGHT=300
-   TIMEOUT_SECONDS=5
 
    ## When chrony restarts, it can generate abnormally high statistical values (e.g., 12M packets)
    ## that distort the graph scale. This parameter filters out values above the threshold,
    ## creating gaps in the graph instead of displaying misleading spikes.
    SERVER_STATS_UPPER_LIMIT=100000
-
-   ## You can display or not the link to the chrony-stats GitHub repository in the HTML page
-   ## It's completely optional by default - feel free to use it however you want, no credit needed! 👍
-   GITHUB_REPO_LINK_SHOW="no"
    ##############################################################
    [...]
    ```

+ 19 - 6
chrony-network-stats.sh

@@ -10,17 +10,22 @@ PAGE_TITLE="Network Traffic and Chrony Statistics for ${INTERFACE}"
 OUTPUT_DIR="/var/www/html/chrony-network-stats" ## Output directory for HTML and images
 HTML_FILENAME="index.html" ## Output HTML file name
 
+RRD_DIR="/var/lib/chrony-rrd"
+RRD_FILE="$RRD_DIR/chrony.rrd" ## RRD file for storing chrony statistics
+
 ENABLE_LOGGING="yes"
 LOG_FILE="/var/log/chrony-network-stats.log"
-RRD_DIR="/var/lib/chrony-rrd"
-RRD_FILE="$RRD_DIR/chrony.rrd"
 
-WIDTH=800   ## Width of the generated graphs
-HEIGHT=300  ## Height of the generated graphs
+AUTO_REFRESH_SECONDS=0 ## Auto-refresh interval in seconds (0 = disabled, e.g., 300 for 5 minutes)
+GITHUB_REPO_LINK_SHOW="no" ## You can display the link to the repo 'chrony-stats' in the HTML footer | Not required | Default: no
+
+
+###### Advanced Configuration ######
+
 TIMEOUT_SECONDS=5
 SERVER_STATS_UPPER_LIMIT=100000 ## When chrony restarts, it generate abnormally high values (e.g., 12M) | This filters out values above the threshold
-
-GITHUB_REPO_LINK_SHOW="no" ## You can display the link to the repo 'chrony-stats' in the HTML footer | Not required | Default: no
+WIDTH=800   ## Width of the generated graphs
+HEIGHT=300  ## Height of the generated graphs
 
 ##############################################################
 
@@ -350,12 +355,19 @@ generate_graphs() {
 generate_html() {
     log_message "INFO" "Generating HTML report..."
     local GENERATED_TIMESTAMP=$(date)
+    
+    local AUTO_REFRESH_META=""
+    if [[ "$AUTO_REFRESH_SECONDS" -gt 0 ]]; then
+        AUTO_REFRESH_META="    <meta http-equiv=\"refresh\" content=\"$AUTO_REFRESH_SECONDS\">"
+    fi
+    
     cat >"$OUTPUT_DIR/$HTML_FILENAME" <<EOF
 <!DOCTYPE html>
 <html lang="en">
 <head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
+$AUTO_REFRESH_META
     <title>${PAGE_TITLE} - Server Status</title>
     <style>
         :root {
@@ -663,6 +675,7 @@ main() {
     validate_numeric "$HEIGHT" "HEIGHT"
     validate_numeric "$TIMEOUT_SECONDS" "TIMEOUT_SECONDS"
     validate_numeric "$SERVER_STATS_UPPER_LIMIT" "SERVER_STATS_UPPER_LIMIT"
+    validate_numeric "$AUTO_REFRESH_SECONDS" "AUTO_REFRESH_SECONDS"
     check_commands
     setup_directories
     generate_vnstat_images