Monitor your VPS in 10 minutes: Prometheus, Grafana and Telegram alerts (free kit)
Most people start thinking about monitoring after the first incident: the disk fills up with logs, the database dies from lack of memory, and you learn about it from your users. Basic protection can be set up in an evening, and faster if you don't assemble the stack by hand. Here is the minimal setup that is enough for one VPS. Prometheus collects metrics, Grafana shows them, and Alertmanager…
Monitoring a virtual private server (VPS) can be achieved quickly and efficiently using a combination of Prometheus, Grafana, Alertmanager, and Telegram. This setup monitors system resources, such as CPU, memory, disk usage, network traffic, and uptime, and alerts users via Telegram when certain conditions are met. The entire process can be completed in about 10 minutes using a free kit called "Monitoring Lite."
First, users must set up a Telegram bot by interacting with the @botfather and obtaining a token. This token is used to configure the Alertmanager to send notifications to Telegram. Next, users need to install Docker and Docker Compose, then download the Monitoring Lite kit and run the installer. The installer sets up four containers – Prometheus, node-exporter, Alertmanager, and Grafana – and creates the necessary configuration files.
Prometheus collects metrics from the host's /proc and /sys directories, scrapes the metrics every 15 seconds, and stores them. Alertmanager then evaluates predefined alert rules, which trigger notifications when certain thresholds are exceeded. Grafana visually displays the gathered data in a simple and user-friendly dashboard.
To access the Grafana dashboard, users should run an SSH tunnel on their local machine and open http://localhost:3000. They can then log in using the generated Grafana admin password, which is stored in the .env file. The dashboard "Host Overview" provides real-time insights into the VPS's performance and resource utilization.
The monitoring kit includes five Telegram alerts: host down, high CPU usage, high memory usage, disk space almost full, and host rebooted. These alerts are sent to the user's Telegram chat, allowing them to quickly respond to any issues. The alert rules are defined in the config/prometheus/alert_rules.yml file, and users can modify the thresholds as needed.
Running the setup is as simple as executing the ./install.sh script, which creates the required configuration files and starts the containers. The installer is idempotent, meaning it can be run multiple times without overwriting existing configuration files. Users should keep the exposed ports (9090, 9093, and 9100) closed to the internet, using SSH tunnels instead to ensure security and prevent unauthorized access to the VPS.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.