
About The Project
Monitoring the availability of network services is an important task for any project. At the same time, it is not always necessary to deploy universal solutions like Prometheus — a simpler solution often suffices. It is for such cases that this bot was created.
The bot monitors the availability of HTTP(S) and TCP services and notifies a Telegram channel or group about changes in their status. It also supports on-demand status queries via commands and periodic heartbeat summaries to confirm the bot is alive.
Key features:
- HTTP(S) and TCP service probing with configurable thresholds
- Flexible notification message templates (Go template syntax)
- Pluggable storage backends: YAML file or Redis
/status command for querying current service states
- Periodic heartbeat messages
- Telegram SOCKS5/SOCKS5h proxy support
- OpenAPI/Swagger documentation
- Prometheus metrics endpoint
(back to top)
Built With
(back to top)
Getting Started
Follow the instructions below to run the bot.
Prerequisites
Choose one of the following:
- Docker (recommended) — no other dependencies required
- Go 1.26+ — for building from source
Installation
- Register a new bot and get a token: https://core.telegram.org/bots/features#creating-a-new-bot
- Create a channel or group for notifications
- Add the bot as an administrator with permission to send messages
- Copy config.example.yml to your working directory as
config.yml
- Edit the configuration file:
- Set the bot token
- Set the channel/group ID (find it via
https://api.telegram.org/bot<token>/getUpdates?allowed_updates=[] after adding the bot — look for my_chat_member.chat.id)
- List the services to monitor (or configure a storage backend)
- Run the bot:
docker run -d \
-v "$(pwd)/config.yml:/app/config.yml:ro" \
--name tgbot \
ghcr.io/capcom6/service-monitor-tgbot:latest
Alternatively, copy .env.example to .env and set environment variables there.
From source:
make deps
make build
./bin/service-monitor-tgbot
Note: By default, the service list is read from the same YAML file (file storage backend). To use Redis or another backend, see the Storage Backends section and set the storage.dsn field or STORAGE__DSN environment variable.
(back to top)
Usage
Messages Template System
The bot uses a flexible template system for customizing notification messages. Templates support Go text/template syntax and a custom escape function for Telegram MarkdownV2 escaping. Templates can be customized in the configuration file under the telegram.messages key or via the TELEGRAM__MESSAGES environment variable (JSON object).
| Template |
Variables |
Description |
online |
Name - name of the service
ChangedAt - when the service entered this state
Duration - how long the service has been in this state |
message when a service goes "online" |
offline |
Name - name of the service
Error - error message
ChangedAt - when the service entered this state
Duration - how long the service has been in this state |
message when a service goes "offline" |
services_list |
list of all services, each with:
Name - name of the service
State - state of the service
Error - error message
ChangedAt - when the service entered this state
Duration - how long the service has been in this state |
message with a list of all services |
heartbeat |
TotalServices - total number of services
OnlineServices - number of online services
OfflineServices - number of offline services
CheckedAt - time of the heartbeat check |
periodic heartbeat status summary |
Commands
/status — Get the current status of all monitored services
Heartbeat
The heartbeat feature sends periodic status summaries to help distinguish between "everything is fine" and "the bot has crashed."
When enabled, the bot sends a summary message at a configurable interval regardless of service states. The summary shows how many monitored services are online and offline. By default, an offline count is appended when at least one service is offline.
Configure via environment variables or YAML:
HEARTBEAT__ENABLED=true
HEARTBEAT__INTERVAL=1h
HEARTBEAT__CHATID=-1001234567890 # optional, defaults to TELEGRAM__CHATID
Or in YAML:
heartbeat:
enabled: true
interval: 1h
chatId: -1001234567890 # optional, defaults to telegram.chatId
Default heartbeat message: 💓 Heartbeat: 5/5 services online (with the (1 offline) suffix when any service is offline). The message text can be customized via the heartbeat template.
API Documentation
When OpenAPI is enabled (default), Swagger documentation is available at:
http://localhost:3000/api/v1/docs
Disable it with HTTP__OPENAPI__ENABLED=false or the http.openapi.enabled: false config field.
(back to top)
Health Endpoints
Health probes are served on the HTTP server address (HTTP__ADDRESS, default 127.0.0.1:3000):
| Endpoint |
Checks |
/health, /health/live |
system:goroutines, system:memory, telegram:api |
/health/ready |
none — answers 200 OK for as long as the server runs |
/health/startup |
none — answers 200 OK for as long as the server runs |
telegram:api is the polling-loop watchdog. It reports the seconds since the last completed getUpdates long-poll request (-1 while none has completed) and turns the liveness endpoints red — HTTP 503 — once no poll has completed for 3 × TELEGRAM__TIMEOUT. Sends and other Bot API calls do not refresh it — the check watches the receive loop, not outbound traffic.
- That catches the failure mode nothing else reports: a polling loop wedged on a connection that never returns and never errors. Polls that fail fast — network outage, dead proxy, rejected credentials — still count as completed requests, so the check deliberately stays green while Telegram is unreachable; watch the logs for those.
curl -i http://127.0.0.1:3000/health/live
(back to top)
Examples
HTTP service monitoring example
services:
- name: Google
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
httpGet:
scheme: https
host: google.com
path: /
port: 443
httpHeaders:
- name: X-Header
value: value

TCP service monitoring example
services:
- name: MySQL
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
tcpSocket:
host: localhost
port: 3306

(back to top)
Configuration
Configuration is loaded in order: defaults < YAML file < .env file < environment variables. Set CONFIG_PATH to point to your YAML config file.
Environment Variables
| Variable |
Description |
Default |
Example |
CONFIG_PATH |
Path to main YAML configuration file |
— |
./configs/config.yml |
DEBUG |
Enable development logging (human-readable console output) |
false |
1 |
HTTP__ADDRESS |
HTTP server bind address (health/metrics) |
127.0.0.1:3000 |
0.0.0.0:3000 |
HTTP__PROXY_HEADER |
Trusted proxy header for real client IP |
X-Forwarded-For |
X-Real-IP |
HTTP__PROXIES |
Trusted proxy IPs/CIDRs (comma-separated) |
(empty) |
10.0.0.0/8,192.168.1.0/24 |
HTTP__OPENAPI__ENABLED |
Enable Swagger/OpenAPI docs endpoint |
true |
false |
HTTP__OPENAPI__PUBLIC_HOST |
Public hostname in OpenAPI spec |
(empty) |
api.example.com |
HTTP__OPENAPI__PUBLIC_PATH |
Path prefix for OpenAPI docs |
(empty) |
/docs |
TELEGRAM__TOKEN |
Telegram Bot API token (required) |
— |
123456:ABC-DEF... |
TELEGRAM__CHATID |
Target chat/group/channel ID (required; YAML wins if set) |
— |
-1001234567890 |
TELEGRAM__PROXY_URL |
SOCKS5 proxy for Telegram API (socks5:///socks5h://) |
(empty) |
socks5h://127.0.0.1:8888 |
TELEGRAM__TIMEOUT |
Telegram API request timeout (keep above the 8s long poll) |
1m |
30s |
TELEGRAM__MESSAGES |
Custom message templates (JSON object) |
(built-in defaults) |
{"online":"✅ {{.Name}}"} |
HEARTBEAT__ENABLED |
Enable periodic heartbeat messages |
false |
true |
HEARTBEAT__INTERVAL |
Heartbeat send interval |
6h |
1h |
HEARTBEAT__CHATID |
Target chat for heartbeat messages |
(uses TELEGRAM__CHATID) |
-1001234567890 |
STORAGE__DSN |
Storage backend DSN |
file://$CONFIG_PATH |
redis://localhost:6379/0 |
Note: Environment variable names use __ (double underscore) as the separator for nested config keys (e.g., TELEGRAM__TOKEN maps to telegram.token). A .env file in the working directory is loaded automatically. Two keys need care: the proxy is read only from TELEGRAM__PROXY_URL or the YAML key telegram.proxy_url (the camelCase proxyUrl is ignored), and a chatId present in the YAML wins over TELEGRAM__CHATID.
YAML Config Structure
telegram:
token: 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
chatId: -1234567890123
proxy_url: socks5h://127.0.0.1:8888 # optional, socks5:// or socks5h:// (proxyUrl is not read)
messages: {} # optional, overrides built-in templates
heartbeat:
enabled: true # optional, enables periodic heartbeat messages
interval: 1h # optional, default: 6h
chatId: 0 # optional, 0 = use telegram.chatId
storage:
dsn: file://./configs/services.yml # optional, default: file://$CONFIG_PATH
services: # optional inline list of services, see Examples and Service Definition Fields
Service Definition Fields
| Field |
Type |
Default |
Description |
name |
string |
(required) |
Human-readable service name |
initialDelaySeconds |
int16 |
0 |
Delay before first check; negative = random 0..periodSeconds |
periodSeconds |
uint16 |
10 |
Seconds between probes |
timeoutSeconds |
uint16 |
1 |
Probe timeout |
successThreshold |
uint8 |
1 |
Consecutive successes to mark "online" |
failureThreshold |
uint8 |
3 |
Consecutive failures to mark "offline" |
httpGet |
object |
|
HTTP probe (mutually exclusive with tcpSocket) |
httpGet.scheme |
string |
http |
http or https |
httpGet.host |
string |
(required) |
Hostname |
httpGet.path |
string |
/ |
URL path |
httpGet.port |
uint16 |
auto (80/443) |
Port (defaults based on scheme) |
httpGet.httpHeaders |
list |
|
Custom HTTP headers |
tcpSocket |
object |
|
TCP probe (mutually exclusive with httpGet) |
tcpSocket.host |
string |
(required) |
Hostname |
tcpSocket.port |
uint16 |
(required) |
Port |
Storage Backends
The bot supports pluggable storage backends for loading the list of monitored services. The backend is selected via DSN in the storage.dsn config field or STORAGE__DSN environment variable.
| Scheme |
Backend |
Use Case |
file |
YAML file (default) |
Simple setups, static configs |
redis |
Redis key |
Dynamic service lists, distributed management |
File DSN format: file:///path/to/services.yml
Redis DSN format: redis://[[user]:pass@]host:port[/db][?key=<key>&channel=<channel>]
Default key: service-monitor:services, default channel: service-monitor:reload.
(back to top)
Deployment
Docker
The recommended way to run the bot:
docker run -d \
-v "$(pwd)/config.yml:/app/config.yml:ro" \
--name tgbot \
ghcr.io/capcom6/service-monitor-tgbot:latest
The image ships a HEALTHCHECK against /health/live on port 3000 (it must match HTTP__ADDRESS), so an orchestrator marks the container unhealthy and restarts it once the Telegram polling loop has been silent for 3 × TELEGRAM__TIMEOUT — see Health Endpoints.
GoReleaser
The project uses GoReleaser for building and publishing releases. Binaries are built for Linux, macOS, and Windows. Docker images are published for linux/amd64 and linux/arm64.
make release
(back to top)
Development
Prerequisites
Make Targets
| Target |
Description |
make all |
Format + lint + test coverage |
make build |
Build binary to bin/ |
make test |
Run tests with race detection and coverage |
make coverage |
Generate coverage report (coverage.out + coverage.html) |
make lint |
Run golangci-lint |
make fmt |
Format code |
make air |
Development server with hot-reload |
make release |
GoReleaser snapshot build |
make docker-build |
Build Docker image |
make docker-up |
Start services via Docker Compose (requires a local docker-compose.yml) |
make docker-down |
Stop Docker Compose services |
make swagger |
Regenerate Swagger docs |
make clean |
Clean build artifacts |
make help |
Show available targets |
Quick Start
make deps # install Go dependencies
make air # start with hot-reload (requires Air)
Or build and run directly:
make build
CONFIG_PATH=configs/config.yml DEBUG=1 ./bin/service-monitor-tgbot
(back to top)
Roadmap
- Add Changelog
- Add the ability to change the text of messages
- Pluggable storage backends (file, Redis)
- Proxy support for Telegram client
- Request current state of services (
/status command)
- Periodic heartbeat messages
- Send notifications to multiple channels/groups
- Display event time in notifications
- Online/offline time count
- Active bot mode
- Separation of bot and monitoring service
- Dynamic list of services
- Service discovery
- Resource groups
See the open issues for a full list of proposed features (and known issues).
(back to top)
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
- Fork the Project
- 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
(back to top)
License
Distributed under the Apache-2.0 license. See LICENSE for more information.
(back to top)
API Support: i@capcom.me
Project Link: https://github.com/capcom6/service-monitor-tgbot
(back to top)
Acknowledgments
(back to top)