A CLI service for connectivity monitoring with metrics storage in ClickHouse.
- β IPv4 and IPv6 ping support
- β JSON configuration
- β ClickHouse storage
- β Descriptive names for each target
- β Configurable ping interval
- β Graceful shutdown
- β Environment variables support
- Go 1.18+
- ClickHouse (optional for development)
go build -o pinger .CGO_ENABLED=1 go build -o pingo .GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o pingo-linux .GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags="-s -w" -o pingo-linux .Create a config.json file based on the example:
cp config.example.json config.jsonEdit config.json with your targets:
{
"ping_interval": 30,
"items": [
{
"name": "Cloudflare DNS IPv4",
"tool": "pingv4",
"target": "1.1.1.1",
"timeout": 5000
},
{
"name": "Google DNS IPv6",
"tool": "pingv6",
"target": "2606:4700:4700::1111",
"timeout": 5000
}
]
}Create a .env file to configure ClickHouse:
cp .env.example .envEdit .env with your settings:
CLICKHOUSE_DSN=localhost:9000
CLICKHOUSE_DATABASE=default
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=yourpassword
PING_INTERVAL=30s# Run the service
./pinger start config.json
# Or with CGO enabled
CGO_ENABLED=1 ./pinger start config.jsonUse Ctrl+C for graceful shutdown.
CREATE TABLE ping_metrics (
name String,
target String,
success UInt8,
duration_ms Float64,
error String,
timestamp DateTime
) ENGINE = MergeTree()
ORDER BY timestampname: Descriptive target nametarget: IP or hostnamesuccess: 1 for success, 0 for failureduration_ms: Response time in millisecondserror: Error message if failure occurredtimestamp: Measurement date and time
| Variable | Default | Description |
|---|---|---|
CLICKHOUSE_DSN |
localhost:9000 |
ClickHouse address |
CLICKHOUSE_DATABASE |
default |
Database name |
CLICKHOUSE_USERNAME |
default |
Username |
CLICKHOUSE_PASSWORD |
`` | Password |
PING_INTERVAL |
30s |
Ping interval |
docker run -d \
--name clickhouse \
-p 9000:9000 \
-p 8123:8123 \
-v clickhouse_data:/var/lib/clickhouse \
clickhouse/clickhouse-serverFROM golang:1.21-alpine AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=1 GOOS=linux go build -o pinger .
FROM alpine:latest
COPY --from=builder /app/pinger /app/pinger
ENTRYPOINT ["/app/pinger"]# Normal build
go build -o pinger .
# Build with CGO
CGO_ENABLED=1 go build -o pinger .# Build for Linux
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o pinger-linux .
# Optimized build for Linux
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags="-s -w" -o pinger-linux .GOOS=windows GOARCH=amd64 go build -o pinger.exe .# Linux: run with sudo or set capabilities
sudo setcap cap_net_raw+ep ./pinger
# Or run with sudo
sudo ./pinger start config.jsonInstall development dependencies:
# Ubuntu/Debian
sudo apt-get install build-essential
# CentOS/RHEL
sudo yum groupinstall "Development Tools"
# macOS (with Homebrew)
brew install gccMIT License - see LICENSE file for details.
- Fork the project
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request