설명 없음

TheHuman 86fac95de1 Update nginx.md 9 달 전
LICENSE 2eb9eb0451 Initial commit 10 달 전
README.md 6493961371 Update prerequisites section and usage instructions 10 달 전
chrony-network-stats.sh c2771f9183 Update OUTPUT_DIR path to include 'html' for consistency 10 달 전
nginx.md 86fac95de1 Update nginx.md 9 달 전

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

  • HTML report: Creates a styled HTML page with embedded graphs and raw chronyc command outputs.
  • Network monitoring : vnStat
  • Chrony statistics
  • Lightweight: Designed to be resource-efficient, with minimal overhead and no heavy dependencies.

Prerequisites

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

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

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

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

   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
   #########################
   [...]

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/chrony-network-stats/index.html.
    • Serve 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.

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
    

License

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

Acknowledgments

Built with vnstat, vnstati, rrdtool, and chrony.