77 lines
1.8 KiB
Markdown
77 lines
1.8 KiB
Markdown
# uptimetracker
|
|
|
|
A lightweight HTTP uptime monitor written in Go. Checks a list of URLs at a configurable interval, logs results, and sends Discord alerts on state changes.
|
|
|
|
## Features
|
|
|
|
- Checks multiple targets concurrently
|
|
- Alerts on DOWN and recovery via Discord webhook (fires once per state change, no spam)
|
|
- Logs to file and stdout simultaneously
|
|
|
|
## Configuration
|
|
|
|
Copy `config.json.example` as `config.json` and edit it:
|
|
|
|
```json
|
|
{
|
|
"interval_seconds": 30,
|
|
"discord_webhook": "https://discord.com/api/webhooks/...",
|
|
"log_file": "uptimetracker.log",
|
|
"targets": [
|
|
{ "name": "My Site", "url": "https://example.com" }
|
|
]
|
|
}
|
|
```
|
|
|
|
| Field | Required | Description |
|
|
|---|---|---|
|
|
| `targets` | yes | List of sites to monitor |
|
|
| `interval_seconds` | no | Check frequency, defaults to 60 |
|
|
| `discord_webhook` | no | Discord webhook URL for alerts |
|
|
| `log_file` | no | Log file path, defaults to `uptimetracker.log` |
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
go build -o uptimetracker .
|
|
./uptimetracker # uses config.json in current directory
|
|
./uptimetracker /path/to/config.json
|
|
```
|
|
|
|
Output:
|
|
|
|
```
|
|
2026-02-25 18:00:00 started monitoring 1 target(s) every 30s
|
|
2026-02-25 18:00:00 My Site UP 200 45ms
|
|
2026-02-25 18:00:30 My Site DOWN 503 120ms
|
|
2026-02-25 18:00:30 alert sent: My Site is DOWN
|
|
```
|
|
|
|
## Deploy with systemd
|
|
|
|
Build a Linux binary:
|
|
|
|
```bash
|
|
GOOS=linux GOARCH=amd64 go build -o uptimetracker .
|
|
```
|
|
|
|
Copy to your server:
|
|
|
|
```bash
|
|
scp uptimetracker config.json uptimetracker.service user@your-vps:~/uptimetracker/
|
|
```
|
|
|
|
Install and start the service:
|
|
|
|
```bash
|
|
# Update User= and paths in the service file to match your username
|
|
sudo cp ~/uptimetracker/uptimetracker.service /etc/systemd/system/
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable --now uptimetracker
|
|
```
|
|
|
|
View logs:
|
|
|
|
```bash
|
|
sudo journalctl -fu uptimetracker
|
|
```
|