Minimalistic Go tool to periodically check the availability of a remote machine over TCP.
Intended use is for remote machines on a local network, and with systemd
's timers to do this loop on repeat.
$ ./heartbeep -ip=8.8.8.8 -port=53 && echo "success!" # returns status code 0 silently on success.
success!
$ ./heartbeep -ip=10.0.0.2 -port=22 && echo "success!" # returns status code 1. no success.
2023/09/20 20:41:24 Machine 10.0.0.2 on port 22 is down!
To integrate heartbeep
with systemd
for consistent periodic checks (this example uses 10.0.0.2
on port 22
):
- Create a
systemd
service file/etc/systemd/system/heartbeep-monitor.service
:
[Unit]
Description=Heartbeep Monitor for 10.0.0.2
[Service]
Type=oneshot
ExecStart=/path/to/heartbeep -ip=10.0.0.2 -port=22
- Create a timer file
/etc/systemd/system/heartbeep-monitor.timer
:
[Unit]
Description=Run Heartbeep monitoring every second
[Timer]
OnBootSec=10
OnUnitActiveSec=1
Unit=heartbeep-monitor.service
[Install]
WantedBy=timers.target
- Activate and start the timer:
sudo systemctl daemon-reload
sudo systemctl enable heartbeep-monitor.timer
sudo systemctl start heartbeep-monitor.timer
Requires Go.
- Clone the repository:
git clone https://github.com/hiAndrewQuinn/heartbeep.git
cd heartbeep
-
Build the binary.
-
To build the
heartbeep
binary normally:go build -o heartbeep heartbeep.go
-
If you want a fully static binary, aka something you can
sftp
up to a Unix server and just go:CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o heartbeep heartbeep.go
This ensures that the binary doesn't depend on any shared libraries on the system, making it highly portable.
-
This project is released under the Creative Commons Zero v1.0 Universal, allowing for maximum flexibility for end users.