Geen omschrijving

Josef Straßl 01715fc6ed removing nts-ke and auth-ntp tracking 1 maand geleden
LICENSE b7bea88cf3 Update LICENSE 8 maanden geleden
README.md 02ce473770 fixing deployment path in README 1 maand geleden
chrony-network-stats.sh 01715fc6ed removing nts-ke and auth-ntp tracking 1 maand geleden
deploy-statstracking.sh 1562577508 removing silence of apt 1 maand geleden
nginx.md 8a29ba998b Update nginx.md 9 maanden geleden

README.md

Lightweight : Monitoring Chrony and Network

Bash script designed to monitor network traffic and Chrony statistics, generating visual graphs and an HTML report for easy monitoring. It’s lightweight, requires minimal system resources, and is ideal for low-resource servers

Demo here : https://thehuman00.github.io/demo-chrony-stats.github.io/

Features

  • Multi-period time views: View Chrony statistics across day, week, and month periods
  • HTML report: HTML page with graphs and raw chronyc command outputs
  • Network monitoring: with vnStat
  • Chrony statistics
  • Data quality: Filters aberrant values during Chrony restarts
  • Lightweight
  • Optional GitHub attribution: It's completely optional by default - feel free to use it however you want, no credit needed! 👍

Prerequisites

Install dependencies (on Debian/Ubuntu-based systems):

For full functionality (Chrony + Network stats):

   sudo apt update
   sudo apt install vnstat vnstati rrdtool chrony

Configure vnStat Ensure vnstat is monitoring the correct network interface (e.g., eth0): Find your interface here :

   vnstat --iflist

Replace YOUR-INTERFACE with your network interface.

   sudo vnstat -i YOUR-INTERFACE

If not eth0 : ⚠️ Change your network interface in Configuration section !!

For Chrony-only monitoring (set ENABLE_NETWORK_STATS="no"):

   sudo apt update
   sudo apt install rrdtool chrony

Installation

  1. Download the script:

    wget https://raw.githubusercontent.com/TheHuman00/chrony-stats/master/chrony-network-stats.sh -O $HOME/chrony-network-stats.sh
    
  2. Make the script executable:

    sudo chmod +x $HOME/chrony-network-stats.sh
    

Configuration

   sudo nano $HOME/chrony-network-stats.sh

The script includes a configuration section at the top of chrony-network-stats.sh. Modify these variables as needed:

   [...]
   ####################### Configuration ######################

   # 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"

   PAGE_TITLE="Network Traffic and Chrony Statistics for ${INTERFACE}"
   OUTPUT_DIR="/var/www/html/chrony-network-stats"
   HTML_FILENAME="index.html"

   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 ######

   ## DNS Lookup Configuration for chronyc commands
   ## "yes" = Allow DNS reverse lookups (default behavior)
   ## "no" = Prevent DNS reverse lookups using -n option (faster, reduces network traffic)
   CHRONY_ALLOW_DNS_LOOKUP="yes"

   # Screen preset (page & graphs). Options: default | 2k | 4k
   # Adjusts main container width, base font size, and graph image resolution
   DISPLAY_PRESET="default"

   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
   ##############################################################

   # Base graph size (scaled automatically by DISPLAY_PRESET)
   WIDTH=800
   HEIGHT=300
   ##############################################################
   [...]

Close with Ctrl+X --> Y --> Enter

Usage

  1. Run the Script:

    sudo $HOME/chrony-network-stats.sh
    
  2. View the Output:

    • The HTML report is generated at /var/www/html/chrony-network-stats/index.html
    • Serves this file via a web server (e.g., Apache or Nginx)

See here how to serve via nginx in localhost

  1. Monitor Logs: Check /var/log/chrony-network-stats.log for execution details and errors.

About responsiveness and large screens

Set DISPLAY_PRESET to 2k or 4k if the main container looks too small on high-resolution displays. The preset will:

  • Increase the max width of the main container
  • Increase the base font size
  • Generate larger graph images to keep them sharp on big screens

Setting up a crontab (Run every 5 minutes)

To run the script every 5 minutes with sudo privileges, configure the root crontab :

  1. Add in the root crontab:

    ( sudo crontab -l 2>/dev/null; echo "*/5 * * * * $HOME/chrony-network-stats.sh" ) | sudo crontab -
    

    This adds the script to the root crontab and schedules it to run every 5 minutes.

  2. Verify Crontab: Check the crontab entry:

    sudo crontab -l
    

Deployment

To deploy the statstracking script, run the following command:

curl -L https://git.medowar.de/Medowar/chrony-stats/raw/master/deploy-statstracking.sh | bash

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Built with vnstat, vnstati, rrdtool, and chrony.