
The definitive analysis for your proxy
[](https://github.com/kaelthasmanu/SquidStats/)
[](https://github.com/kaelthasmanu/SquidStats/blob/master/LICENSE)
[](https://github.com/kaelthasmanu/SquidStats/stargazers)
[](https://github.com/kaelthasmanu/SquidStats/members)
[](https://github.com/kaelthasmanu/SquidStats/)
[](https://github.com/kaelthasmanu/SquidStats/)
[](https://github.com/kaelthasmanu/SquidStats/watchers)
:star: Give me one star — it will motivate me to keep improving it!!
Table of contents
-
About the Project
-
Getting Started
-
Accessing the Admin Panel
-
Multi-Proxy Mode (Load Balancing)
-
Telegram Notifications Setup
-
Resetting Forgotten Password
-
Update Project
-
Run on System Startup
-
Testing Information
-
Uninstall SquidStats
-
Upcoming Features
- Contributing
- License
- Contact
- Technologies Used
- Special thanks
## About the Project
_A modern tool for parsing and analyzing Squid logs, providing a user-friendly dashboard to visualize real-time connection data. This project helps network administrators monitor and manage Squid proxy connections effectively._
**You can view the example [here](https://github.com/kaelthasmanu/SquidStats/tree/main/assets "Examples").**
### Goals of this project :
- **_Real-time Log Parsing_**: Parses active Squid connections and displays detailed information.
- **_User Monitoring_**: Identifies connections by username, URI, and log type.
- **_Metrics Overview_**:
- Total read and written data for each connection.
- Number of requests per connection.
- Delay pool usage.
- **_Interactive Dashboard_**: Clean interface for easy data interpretation.
- **_Squid Cache Statistics_**:
- Stored entries.
- Used and free capacity
- Maximum and current cache size
- Disk space and inode usage
- Age of cached objects
- **_Logs Users_**:
- User activity monitoring 👥
- Beautiful visualizations 📊
- Advanced filtering & search 🔍
- Paginated results 📄
- **_Top Graphs_**:
- Top 20 Users Activity
- Top 20 Users Data Usage
- Total Users
- Total Transmitted Data
- Total Request
- And More...
- **_Quota System_**:
- Quota per users
- Quota per group
- **_And More_**
##
## Getting Started
[](https://github.com/kaelthasmanu/SquidStats/)
**The entire installation process in more detail can be found [here](https://www.sysadminsdecuba.com/2025/04/squidstat-analizador-de-logs-de-squid-diferente-y-100-cubano/).**
### Prerequisites
- Python 3.14+
- Squid proxy server
```bash
apt install git python3 python3-pip python3-venv libmariadb-dev curl
```
#### Resetting a client's connections
The **Reset connections** action in a user's menu terminates the active
network states associated with that user's IP address. This is an operating
system operation, not a Squid reconfiguration, and requires root-equivalent
privileges:
- **Linux:** install `conntrack` (`apt install conntrack`) and grant
SquidStats the required access to the binary. SquidStats runs
`conntrack -D -s IP`.
- **macOS/BSD:** the action uses `pfctl -k IP`; PF must be enabled, and the
process must be allowed to run `pfctl` with administrative privileges.
- **Other systems:** the interface reports that this capability is not
available without modifying any connections.
On Linux, add the following `iptables` rules on the Squid proxy host so that
`conntrack` can track the proxy connections on port 3128:
```bash
iptables -t filter -I INPUT -p tcp --dport 3128 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -t filter -I OUTPUT -p tcp --sport 3128 -m state --state ESTABLISHED -j ACCEPT
iptables -t filter -I FORWARD -p tcp --dport 3128 -j ACCEPT
iptables -t filter -I FORWARD -p tcp --sport 3128 -j ACCEPT
```
Resetting only affects states tracked by the host firewall. In a Docker
installation, or when Squid is behind another NAT device, the operation must
run on the host that actually maintains those states; otherwise, client
connections cannot be closed by IP address.
> **Note:** If your Squid proxy **does not use user authentication** (i.e., you do not use login or password for clients), you can keep the **default log format** that comes with Squid. The detailed format below is only required for full compatibility with user-based reports.
- ⚠️ !!Important (Only work before version 7.1) ⚠️ For compatibility with user logs, use this format in /etc/squid/squid.conf:
```bash
logformat detailed \
"%ts.%03tu %>a %ui %un [%tl] \"%rm %ru HTTP/%rv\" %>Hs %a %mt % **Note:** Package names include the SquidStats version number and may change between releases. Always download the latest version available for your distribution.
3. Install the downloaded package:
```bash
sudo dpkg -i squidstats_*.deb
```
4. If the system reports unmet dependencies, install them with:
```bash
sudo apt install -f
```
---
### Installation from the official PPA (Ubuntu)
The recommended way to install SquidStats on Ubuntu is via the official PPA, which allows you to receive updates automatically through the system package manager.
#### Add the repository
```bash
sudo add-apt-repository ppa:kaelthasmanu/squidstats
sudo apt update
```
#### Install SquidStats
```bash
sudo apt install squidstats
```
---
## Update
If SquidStats was installed from the PPA, new versions will be available through the system updates:
```bash
sudo apt update
sudo apt upgrade
```
---
## Verify installation
To verify the installation was successful:
```bash
squidstats --version
```
If the command returns the installed version, SquidStats is ready to use.
##
### Installation Manual(The hard way)
1. Clone the repository:
```bash
mkdir -p /opt/squidstats
git clone https://github.com/kaelthasmanu/SquidStats.git /opt/squidstats
```
2. Creating a virtual environment (venv):
```bash
cd /opt/squidstats/
python3 -m venv "/opt/squidstats/venv"
source venv/bin/activate
pip install --upgrade pip
```
3. Install requeriments python with pip or pip3:
```bash
pip install -r /opt/squidstats/requirements.txt
```
4. Create a .env file in the project root and add the following content:\
Note: for use MARIADB need your own database running
```bash
# Application Version
VERSION="2.5.1"
# Security Keys
SECRET_KEY="your-secret-key-here" # Generate with: python3 -c 'import secrets; print(secrets.token_hex(32))'
# Squid Configuration
SQUID_HOST="127.0.0.1"
SQUID_PORT="3128"
SQUID_LOG="/var/log/squid/access.log"
SQUID_CACHE_LOG="/var/log/squid/cache.log"
SQUID_CONFIG_PATH="/etc/squid/squid.conf"
ACL_FILES_DIR="/etc/squid/acls"
LOG_FORMAT="DETAILED" # Options: DETAILED or DEFAULT
# Database Configuration
DATABASE_TYPE="SQLITE" # Options: SQLITE or MARIADB
DATABASE_STRING_CONNECTION="/opt/SquidStats/squidstats.db" # For SQLite: directory path
# For MariaDB: connection string mysql+pymysql://user:clave@host:port/db
# For Postgresql: connection string postgresql+psycopg2://squidstats:squidstats@127.0.0.1:5432/squidstats
# Flask Application Settings
FLASK_DEBUG="False" # Set to True only for development
LISTEN_HOST="0.0.0.0"
LISTEN_PORT="5000"
REFRESH_INTERVAL="60"
# Authentication & Security
FIRST_PASSWORD="mipassword" # Initial admin password (change after first login)
JWT_EXPIRY_HOURS="24"
MAX_LOGIN_ATTEMPTS="5"
LOCKOUT_DURATION_MINUTES="15"
# Blacklist Configuration
BLACKLIST_DOMAINS="facebook.com,twitter.com,instagram.com,tiktok.com,youtube.com,netflix.com"
# Telegram Notifications (Optional)
TELEGRAM_ENABLED="false" # Set to "true" to enable Telegram notifications
TELEGRAM_API_ID="" # Get from https://my.telegram.org
TELEGRAM_API_HASH="" # Get from https://my.telegram.org
TELEGRAM_BOT_TOKEN="" # Get from @BotFather (optional, for bot mode)
TELEGRAM_PHONE="" # Your phone number (optional, for user mode)
TELEGRAM_SESSION_NAME="squidstats_bot"
TELEGRAM_RECIPIENTS="" # Comma-separated list of recipients (usernames, phone numbers, or chat IDs)
# Proxy Configuration (Optional)
HTTP_PROXY="" # Example: http://proxy.example.com:8080
HTTPS_PROXY="" # Example: https://proxy.example.com:8443
NO_PROXY="" # Comma-separated list of hosts to bypass proxy
```
### Forwarding Squid logs from a remote Squid host (important)
If you install SquidStats on a different machine than the Squid proxy (i.e. Squid is not local
on the SquidStats server), you must ensure that the Squid access log (/var/log/squid/access.log)
is available on the SquidStats server. The recommended and reliable way to do this is to forward
Squid's log entries via syslog (rsyslog or syslog-ng) from the proxy host to the SquidStats host.
Below are example configurations for both sending (on the Squid proxy host) and receiving
(on the SquidStats server). Adjust IP addresses, ports and file paths to your environment.
NOTE: forwarding logs avoids copying files and ensures live updates for the dashboard.
- Using rsyslog (proxy = 192.168.1.10, squidstats = 192.168.1.20)
On the Squid proxy (send): edit `/etc/rsyslog.d/30-squid.conf` and add:
```conf
# rsyslog - forward squid access log lines to remote host
# create a local file watch (imfile) to read Squid access.log
module(load="imfile" PollingInterval="10")
input(type="imfile"
File="/var/log/squid/access.log"
Tag="squid_access:"
Severity="info"
Facility="local0")
# forward to remote syslog collector
*.* @@192.168.1.20:514
```
On the SquidStats server (receive): enable UDP/TCP syslog reception and store to file.
Example `/etc/rsyslog.d/10-remote.conf`:
```conf
# rsyslog - accept remote logs
module(load="imudp")
input(type="imudp" port="514")
# store squid forwarded logs
if $programname == 'squid_access' or $syslogtag contains 'squid_access' then {
/var/log/remote/squid/access.log
stop
}
```
Create the directory and set permissions:
```bash
sudo mkdir -p /var/log/remote/squid
sudo chown syslog:adm /var/log/remote/squid
sudo systemctl restart rsyslog
```
- Using syslog-ng (proxy send):
Edit `/etc/syslog-ng/conf.d/squid-forward.conf` on the proxy host:
```conf
source s_squid { file("/var/log/squid/access.log" follow-freq(1)); };
destination d_remote { tcp("192.168.1.20" port(514)); };
log { source(s_squid); destination(d_remote); };
```
On the SquidStats server (receive) with syslog-ng, accept and write to disk:
```conf
source s_network { tcp(port(514)); };
destination d_squid { file("/var/log/remote/squid/access.log"); };
filter f_squid { program("squid_access") or match("^\d+\.\d+\.\d+\.\d+ .*squid" type("regexp")); };
log { source(s_network); filter(f_squid); destination(d_squid); };
```
- Firewall and permissions
- Open port 514 (or the port you choose) on the SquidStats server and allow the proxy host to connect.
- Use TCP if you care about delivery guarantees; UDP is faster but lossy.
- Ensure the syslog daemon user can write to the destination directory (`/var/log/remote/squid`).
- Update `SQUID_HOST` in `.env`
- If you forward logs, set `SQUID_HOST` in the SquidStats `.env` to the IP of the original Squid host
or keep it as `127.0.0.1` if SquidStats will process them as local files (i.e., they are written
under `/var/log/remote/squid/access.log` locally).
Examples & notes
- This approach is preferred over mounting remote filesystems or using scp/rsync cron jobs because
it provides near real-time updates and is resilient to log rotation when configured correctly.
5. Run App with python or python3 🚀:
```bash
python3 app.py
```
6. With your preferred browser, visit the installation URL:
```bash
http://ip/hostname:5000
```
##
## 🔀 Multi-Proxy Mode (Load Balancing)
SquidStats can monitor **multiple Squid proxies simultaneously**, aggregating their active connections into a single unified dashboard view.
### How It Works
When `SQUID_HOSTS` is set, SquidStats queries all listed proxies **in parallel** on every refresh. It then:
- Merges the active connections from all nodes into one view.
- Shows a **status bar** at the top of the dashboard indicating whether each proxy is reachable (green) or not (red).
- Adds **filter buttons** so you can isolate connections by proxy node.
- Tags each user/connection row with the originating proxy.
If `SQUID_HOSTS` is not set, SquidStats falls back to the single `SQUID_HOST` / `SQUID_PORT` values (fully backward-compatible).
### Configuration
Edit your `.env` file and set `SQUID_HOSTS` as a comma-separated list of `host:port` entries:
```bash
# Single proxy (default behaviour — keep using these)
SQUID_HOST="192.168.1.10"
SQUID_PORT="3128"
# Multi-proxy: uncomment and list all your Squid nodes.
# This overrides SQUID_HOST / SQUID_PORT for the connections page.
# Supports plain IPv4, hostnames, and IPv6 literals ([::1]:3128).
SQUID_HOSTS="192.168.1.10:3128,192.168.1.11:3128,192.168.1.12:3128"
```
> **Note:** Each Squid node must be configured to allow Cache Manager access from the SquidStats server IP. See the [Cache Manager Configuration](#-cache-manager-configuration-critical-for-squidstats) section above.
### Dashboard in Multi-Proxy Mode
| Feature | Description |
|---|---|
| **Proxy status bar** | At the top of the connections page, each proxy shows a green ✅ or red ❌ badge. |
| **Filter tabs** | Click a proxy label to show only the connections coming from that node. |
| **Proxy badge per user** | Each user accordion shows which proxy their connections were fetched from. |
| **Proxy column in table** | Each individual connection row has a "Proxy" column identifying its source node. |
| **Squid status card** | Replaced by the status bar in multi-proxy mode to avoid redundancy. |
## Accessing the Admin Panel
To access the admin panel, you need to configure the initial password and restart the service.
1. Edit the `.env` file using your preferred editor (vi, vim, or nano). Here's an example using nano:
```bash
nano .env
```
Add or modify the following line in the `.env` file:
```bash
FIRST_PASSWORD="mipassword"
```
Save the file and exit the editor (in nano, press Ctrl+X, then Y, then Enter).
2. Restart the SquidStats service:
```bash
sudo systemctl restart squidstats.service
```
3. Access the admin panel by visiting `http://your-ip:your-port/admin` in your browser.
4. Log in with the username `admin` and the password you set in `FIRST_PASSWORD` (in this example, "mipassword").
##
## 📱 Telegram Notifications Setup (Optional)
SquidStats supports sending notifications via Telegram. This feature allows you to receive real-time alerts about security events, system status, and important activities directly on your Telegram account or groups.
### Prerequisites
- A Telegram account
- Telegram API credentials (from [my.telegram.org](https://my.telegram.org))
- Optional: A Telegram Bot Token (from [@BotFather](https://t.me/botfather))
### Getting Telegram API Credentials
1. Visit [https://my.telegram.org](https://my.telegram.org)
2. Log in with your phone number
3. Go to **API development tools**
4. Create a new application
5. Copy your `api_id` and `api_hash`
### Configuration
Edit your `.env` file and configure the Telegram variables:
```bash
# Enable Telegram notifications
TELEGRAM_ENABLED="true"
# API Credentials from my.telegram.org
TELEGRAM_API_ID="your_api_id"
TELEGRAM_API_HASH="your_api_hash"
# Optional: Bot Token from @BotFather (recommended for production)
TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
# Optional: Your phone number (format: +1234567890)
TELEGRAM_PHONE="+1234567890"
# Session name for storing Telegram connection
TELEGRAM_SESSION_NAME="squidstats_bot"
# Recipients (comma-separated)
# Can be: usernames (@username), phone numbers (+1234567890), or chat IDs (-1001234567890)
TELEGRAM_RECIPIENTS="@your_username,-1001234567890"
```
### Finding Chat IDs
To send notifications to groups or channels, you need their chat ID:
1. Add your bot to the group/channel
2. Send a message in the group
3. Visit: `https://api.telegram.org/bot/getUpdates`
4. Look for `"chat":{"id":-1001234567890}` in the response
### Proxy Support
If SquidStats runs behind a proxy, configure the proxy settings:
```bash
HTTP_PROXY="http://proxy.example.com:8080"
HTTPS_PROXY="https://proxy.example.com:8443"
NO_PROXY="localhost,127.0.0.1"
```
##
### Resetting forgotten password (localhost only)
If you lose the admin password, you can reset it from the server where SquidStats runs (localhost only):
1) Make sure the app is running (default listens on `127.0.0.1:5000`, or the `LISTEN_PORT` you set in `.env`).
2) Run this from the SquidStats host:
```bash
curl -X POST http://127.0.0.1:5000/auth/reset-password \
-H "Content-Type: application/json" \
-d '{"username": "admin", "new_password": "NewSecurePass123"}'
```
Notes:
- Must be executed on localhost; remote calls are rejected.
- `new_password` must be at least 8 characters.
- You can also send form data if preferred:
```bash
curl -X POST http://127.0.0.1:5000/auth/reset-password \
-d "username=admin" \
-d "new_password=NewSecurePass123"
```
### ⚠️ First Execution Alert ⚠️
Warning: 🚨 The first execution may cause high CPU usage.
### Update project(web) with Script
1. Get Script With curl o wget:
```bash
wget https://github.com/kaelthasmanu/SquidStats/releases/download/2.3.1/install.sh
```
2. Add permission execution:
```bash
sudo chmod +x install.sh
```
3. Execute the script with parameters update:
```bash
sudo ./install.sh --update
```
🕒 Run on System Startup
To ensure the application starts automatically when the system boot :
1. Copy file service:
```bash
cp ./utils/squidstats.service /etc/systemd/system/squidstats.service
```
2. Restart daemons:
```bash
systemctl daemon-reload
```
3. Enable service:
```bash
systemctl enable squidstats.service
```
3. Start service:
```bash
systemctl start squidstats.service
```
##
## Testing Information
This software has been thoroughly tested and is compatible with Squid version 6.12+ in the following distributions:
- **Ubuntu**: 24.04 LTS and 26.04 LTS
- **Debian**: 12 and 13
- **Alpine Linux**: 3.23.3
Please ensure your Squid installation matches this version or newer for optimal performance. For Docker container environments, Alpine Linux 3.23.3 is recommended due to its small size and compatibility.
## Uninstall SquidStats
The installation script now includes a complete uninstall option that cleans all system components:
### Using the Uninstall Script
1. Get the installation script (if you don't have it):
```bash
wget https://github.com/kaelthasmanu/SquidStats/releases/download/1.0/install.sh
chmod +x install.sh
```
2. Run the uninstallation:
```bash
sudo ./install.sh --uninstall
```
### What Does the Uninstall Do?
The **COMPLETE** uninstallation performs the following actions:
- **🛑 Stops and disables** the systemd service `squidstats.service`
- **🗑️ Removes files** from the `/opt/squidstats` directory
- **⚠️ Requires confirmation** from user before proceeding
### Manual Uninstallation
If you prefer to uninstall manually:
```bash
# Stop and disable service
sudo systemctl stop squidstats.service
sudo systemctl disable squidstats.service
sudo rm -f /etc/systemd/system/squidstats.service
sudo systemctl daemon-reload
# Remove project files
sudo rm -rf /opt/squidstats
```
### ⚠️ Important Note about Uninstallation
- Uninstallation will **permanently delete** all SquidStats data and configurations
- It's recommended to **backup** any custom configurations before uninstalling
### Upcoming Features
- **Interface Improvements** 🎨
- ~~Report export (PDF, Excel)~~ ✅ **Implemented**
- **Optimization and Performance** ⚡
- Enhanced data caching
- Historical log compression
- ~~Multi-proxy support~~ ✅ **Implemented** — see [Multi-Proxy Mode](#-multi-proxy-mode-load-balancing)
## Contributing
1. Fork the repository:
```bash
git checkout -b feature-name
```
2.Create a new branch for your feature or fix:
```bash
git checkout -b feature-name
```
3.Commit your changes and push the branch:
```bash
git push origin feature-name
```
4.Open a pull request.
## License
_The SquidStats project is released under the MIT license._
## Contact
> **_Need help?_**
> **_Feel free to contact me 📨 [manuelalberto.gorrin@gmail.com](mailto:manuelalberto.gorrin@gmail.com?Subject=SquidStats_issues)_**
Related project: ([CuCuota](https://github.com/kaelthasmanu/cucuota))
## Technologies Used
Backend: Python, Flask
Frontend: HTML, CSS, JavaScript
## Special thanks
- _To the Cuban Sysadmins community._
- _To everyone who gave me his help when I had doubts._
##