Monitor users traffic from Remnawave (https://docs.rw), detect anomalies, and send Telegram alerts.
1.8K
English | Русский
Monitor users traffic from Remnawave, detect anomalies, and send Telegram alerts.
Before you begin, ensure you have the following:
Copy .env.example to .env and fill in your values:
# Remnawave panel URL and API key
REMNAWAVE_API_URL=https://panel.example.com
REMNAWAVE_API_KEY=remnawave_api_key
# Telegram bot token from @BotFather
TELEGRAM_BOT_TOKEN=your_bot_token_here
# Chat ID (get from @username_to_id_bot)
TELEGRAM_CHAT_ID=123456789
# Forum topic ID (leave empty for regular chats)
TELEGRAM_TOPIC_ID=
INTERVAL_CHECK_ENABLED=true
# How often to check traffic (minutes)
CHECK_INTERVAL_MINUTES=10
# Alert if user exceeds this in one interval (GB)
INTERVAL_THRESHOLD_GB=20
TOTAL_CHECK_ENABLED=true
# Rolling window for total check (hours)
TOTAL_CHECK_HOURS=24
# Alert if user exceeds this over the window (GB)
TOTAL_THRESHOLD_GB=100
HOURLY_STATS_ENABLED=true
# Supported languages: en, ru
LANGUAGE=en
# Timezone (e.g. UTC, Europe/Moscow, America/New_York)
TIMEZONE=Europe/Moscow
# Time format: %d-day, %m-month, %Y-year, %H-hour, %M-min, %S-sec
TIME_FORMAT="%d.%m.%Y %H:%M:%S"
# Ignore traffic diffs below this value (GB)
MIN_TRAFFIC_GB=0.5
# Max nodes shown per alert
TOP_NODES_LIMIT=5
# Users per API page (max 1000)
API_PAGE_SIZE=1000
# Redis URL (data is persisted via Redis AOF)
REDIS_URL=redis://redis:6379/0
| Variable | Description | Default | Required |
|---|---|---|---|
REMNAWAVE_API_URL | Remnawave API endpoint | - | Yes |
REMNAWAVE_API_KEY | Remnawave API token | - | Yes |
TELEGRAM_BOT_TOKEN | Telegram bot token from @BotFather | - | Yes |
TELEGRAM_CHAT_ID | Chat ID for notifications | - | Yes |
TELEGRAM_TOPIC_ID | Forum topic ID (for supergroups with topics) | - | No |
INTERVAL_CHECK_ENABLED | Enable per-interval spike detection | true | No |
CHECK_INTERVAL_MINUTES | Traffic check interval in minutes | 10 | No |
INTERVAL_THRESHOLD_GB | Spike alert threshold per interval (GB) | 20 | No |
TOTAL_CHECK_ENABLED | Enable rolling total limit detection | true | No |
TOTAL_CHECK_HOURS | Rolling window for total check (hours) | 24 | No |
TOTAL_THRESHOLD_GB | Total traffic alert threshold (GB) | 100 | No |
HOURLY_STATS_ENABLED | Enable hourly stats reports | true | No |
LANGUAGE | Notification language (en, ru) | en | No |
TIMEZONE | Timezone for timestamps | Europe/Moscow | No |
TIME_FORMAT | Time format for timestamps | %d.%m.%Y %H:%M:%S | No |
MIN_TRAFFIC_GB | Ignore traffic diffs below this value (GB) | 0.5 | No |
TOP_NODES_LIMIT | Max nodes shown per alert | 5 | No |
API_PAGE_SIZE | Users per API page (max 1000) | 1000 | No |
REDIS_URL | Redis connection URL | redis://redis:6379/0 | No |
docker-compose.yml:services:
remnawave-traffic-guard:
image: hteppl/remnawave-traffic-guard:latest
container_name: remnawave-traffic-guard
restart: unless-stopped
env_file:
- .env
depends_on:
redis:
condition: service_healthy
redis:
image: redis:8-alpine
restart: unless-stopped
command: redis-server --appendonly yes
volumes:
- traffic-guard-redis-data:/data
healthcheck:
test: [ 'CMD', 'redis-cli', 'ping' ]
interval: 5s
timeout: 3s
retries: 5
volumes:
traffic-guard-redis-data:
cp .env.example .env
nano .env # or use your preferred editor
docker compose up -d && docker compose logs -f
git clone https://github.com/hteppl/remnawave-traffic-guard.git
cd remnawave-traffic-guard
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# or
.venv\Scripts\activate # Windows
pip install -r requirements.txt
cp .env.example .env
REDIS_URL points to it, then run:python -m src
Startup — Connects to Redis, sends a startup notification to Telegram with current thresholds
Periodic Check — Every CHECK_INTERVAL_MINUTES minutes, fetches all users from the Remnawave API and compares
current traffic against previous snapshots stored in Redis
Spike Detection — If a user's traffic increase within a single interval exceeds INTERVAL_THRESHOLD_GB, sends an
alert with per-node traffic breakdown
Total Limit Detection — If a user's cumulative traffic over TOTAL_CHECK_HOURS hours exceeds
TOTAL_THRESHOLD_GB, sends an alert
Snapshot Update — After each check, all user snapshots are written to Redis for the next cycle
Hourly Reports — On each hour boundary, sends a summary with total/active users, traffic consumed, top user, and alert count
TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID in .env| Event | Description |
|---|---|
| Traffic Spike | User exceeded interval threshold |
| Total Limit | User exceeded rolling total threshold |
| Hourly Stats | Periodic report with traffic summary |
| Service Start | Monitoring started with current configuration |
Monitor logs to diagnose issues:
docker compose logs -f
This project is licensed under the GNU General Public License v3.0.
Content type
Image
Digest
sha256:f425ccfe2…
Size
70.1 MB
Last updated
6 months ago
docker pull hteppl/remnawave-traffic-guard