|
|
10 meses atrás | |
|---|---|---|
| LICENSE | 10 meses atrás | |
| README.md | 10 meses atrás | |
| chrony-network-stats.sh | 10 meses atrás | |
| nginx.md | 10 meses atrás |
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/
chronyc command outputs.vnstat + vnstati : For network traffic monitoring + graph generation.chrony : For NTP statistics collection.rrdtool : For creating and managing the Round-Robin Database.timeout (part of coreutils) : For setting timeouts on chronyc commands.Install dependencies (on Debian/Ubuntu-based systems):
sudo apt update
sudo apt install vnstat vnstati rrdtool chrony coreutils
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 -u -i YOUR-INTERFACE
If not eth0 : ⚠️ Change your network interface in Configuration
Download the script:
wget https://raw.githubusercontent.com/TheHuman00/chrony-stats/master/chrony-network-stats.sh -O $HOME/chrony-network-stats.sh
Make the script executable:
sudo chmod +x $HOME/chrony-network-stats.sh
Test the script: Run the script manually to ensure it works:
sudo $HOME/chrony-network-stats.sh
Check the output in /var/www/chrony-network-stats/index.html and/or verify logs in /var/log/chrony-network-stats.log.
🗒️ It may take up to 5 minutes for the first values to appear on the graphs 🗒️
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 ####
# ⚠️ 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/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"
WIDTH=800
HEIGHT=300
TIMEOUT_SECONDS=5
#########################
[...]
To run the script every 5 minutes with sudo privileges, configure the root crontab :
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.
Verify Crontab: Check the crontab entry:
sudo crontab -l
Run the Script:
sudo $HOME/chrony-network-stats.sh
View the Output:
/var/www/chrony-network-stats/index.html.See here how to serve via nginx in localhost
/var/log/chrony-network-stats.log for execution details and errors.This project is licensed under the MIT License. See the LICENSE file for details.
Built with vnstat, vnstati, rrdtool, and chrony.