Telegram bot for monitoring Ubuntu servers. Monitor system resources and receive automated alerts - all from Telegram.
- CPU: Real-time usage, per-core breakdown, frequency, load average
- Memory: RAM and swap usage with detailed breakdown
- Disk: Root partition space usage
- Network: Interface statistics, traffic monitoring
- Processes: Top CPU-consuming processes
- Paginated container list (10 per page)
- Container detail view with CPU, memory, IP, ports
- Start, Stop, Restart containers directly from Telegram
- Container status with health indicators
- Graceful detection when Docker is not available
- Beautiful matplotlib charts for all metrics
- CPU usage per core
- Memory distribution pie charts
- Disk usage visualization
- Process resource graphs
- Configurable thresholds for CPU, RAM, and disk
- Automatic notifications when limits exceeded
- Smart cooldown to prevent spam
- Alert severity levels (info, warning, critical)
- User whitelist authentication
- Rate limiting per user
- Comprehensive logging
- Host PID namespace with restricted capabilities (read-only process access)
- Ubuntu server (18.04+)
- Docker and Docker Compose
- Telegram Bot Token (create one)
- Your Telegram User ID (get it)
- Clone the repository
git clone https://github.com/artcc/linux-server-admin-bot.git
cd linux-server-admin-bot- Configure environment
cp .env.example .env
nano .envEdit .env with your values:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_ALLOWED_USER_IDS=123456789,987654321
CPU_ALERT_THRESHOLD=80
MEMORY_ALERT_THRESHOLD=80
DISK_ALERT_THRESHOLD=90- Create logs directory with correct permissions
mkdir -p logs
sudo chown -R 1000:1000 logs
sudo chmod -R 775 logs- Build and run with Docker Compose
docker-compose up -d- Check logs
docker-compose logs -f- Start chatting with your bot on Telegram!
The bot features a beautiful interactive menu with inline keyboard buttons for easy navigation:
- Main Menu: Access all features with a single tap
- System Monitoring: CPU, Memory, Disk, Network, Processes
- Quick Navigation: Back buttons and menu shortcuts
Just type /start to see the interactive menu!
/start- Welcome message with interactive menu/help- Show all available commands/status- Overall system status summary
/cpu- Detailed CPU information with chart/memory- Memory usage with visualization/disk- Disk space usage/top- Top processes by CPU usage/network- Network interface statistics/temp- System temperature sensors/uptime- System uptime and logged users/services- Systemd services status
/docker- Docker container management menu
/alerts- View alert configuration and active alerts
/author- Bot author information
linux-server-admin-bot/
βββ bot/
β βββ handlers/ # Command handlers
β β βββ basic.py # Start, help, alerts
β β βββ system.py # System monitoring commands
β β βββ docker.py # Docker management commands
β β βββ callbacks.py # Inline keyboard callbacks
β βββ services/ # Business logic
β β βββ system_monitor.py # psutil wrapper
β β βββ alert_manager.py # Alert system
β β βββ docker_manager.py # Docker container management
β βββ monitors/ # Background tasks
β β βββ health_monitor.py # Periodic health checks
β βββ models/ # Data models
β β βββ metrics.py # Dataclasses for metrics
β βββ utils/ # Utilities
β βββ decorators.py # Auth, rate limiting, logging
β βββ formatters.py # Message formatting
β βββ keyboards.py # Inline keyboard layouts
β βββ charts.py # Chart generation
βββ config/ # Configuration
β βββ settings.py # Pydantic settings
β βββ constants.py # Constants and enums
β βββ logger.py # Logging setup
βββ tests/ # Unit tests
βββ docs/ # Documentation
βββ main.py # Application entry point
βββ Dockerfile # Multi-stage Docker build
βββ docker-compose.yml # Docker Compose config
βββ requirements.txt # Python dependencies
- Separation of Concerns: Clear separation between handlers, services, and utilities
- Type Safety: Full type hints and Pydantic validation
- Testability: Dependency injection and comprehensive tests
- Security: Authorization, rate limiting, and audit logging
- Observability: Structured logging and error handling
- Scalability: Async/await patterns for concurrent operations
| Variable | Description | Required | Default |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
Telegram Bot API token | β Yes | - |
TELEGRAM_ALLOWED_USER_IDS |
Comma-separated user IDs | β Yes | - |
CPU_ALERT_THRESHOLD |
CPU usage alert threshold (%) | β No | 80 |
MEMORY_ALERT_THRESHOLD |
Memory usage alert threshold (%) | β No | 80 |
DISK_ALERT_THRESHOLD |
Disk usage alert threshold (%) | β No | 90 |
ALERT_CHECK_INTERVAL |
Alert check interval (seconds) | β No | 300 |
ALERT_COOLDOWN |
Alert cooldown period (seconds) | β No | 600 |
RATE_LIMIT_CALLS |
Max calls per period | β No | 10 |
RATE_LIMIT_PERIOD |
Rate limit period (seconds) | β No | 60 |
LOG_LEVEL |
Logging level | β No | INFO |
The bot requires access to host system resources:
volumes:
- /proc:/host/proc:ro # System metrics
- /sys:/host/sys:ro # System information
- /var/run/docker.sock:/var/run/docker.sock:ro # Docker management (optional)Note: The Docker socket mount is optional. If not mounted, the Docker menu will show that Docker is not available.
You can use the official bot avatar for your own instance:
Download: linux-server-admin-bot.png
To set this image as your bot's profile picture:
- Download the image from the link above
- Open @BotFather on Telegram
- Send
/setuserpic - Select your bot
- Upload the downloaded image
- Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows- Install dependencies
pip install -r requirements.txt- Run locally
python main.py# Run all tests
pytest
# Run with coverage
pytest --cov=bot --cov-report=html
# Run specific test file
pytest tests/test_system_monitor.py# Format code
black .
# Lint code
ruff check .
# Type checking
mypy bot/ config/- Check logs:
docker-compose logs -f - Verify bot token is correct
- Ensure your user ID is in
TELEGRAM_ALLOWED_USER_IDS
- Adjust resource limits in
docker-compose.yml - Increase alert check interval
- Reduce chart DPI in settings
- Install
lm-sensors:sudo apt install lm-sensors - Run sensor detection:
sudo sensors-detect
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- python-telegram-bot - Telegram Bot framework
- psutil - System monitoring
- docker-py - Docker SDK for Python
- matplotlib - Visualization library
For support, open an issue on GitHub.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Made with β€οΈ for system administrators
100% built with GitHub Copilot (Claude Opus 4.5)
Arturo Carretero Calvo β 2026
