An open API service indexing awesome lists of open source software.

https://github.com/cdzombak/heartbeat

Simple HTTP heartbeat implementation for Golang
https://github.com/cdzombak/heartbeat

heartbeat uptime-kuma

Last synced: 4 months ago
JSON representation

Simple HTTP heartbeat implementation for Golang

Awesome Lists containing this project

README

        

# `github.com/cdzombak/heartbeat`

[![Go Reference](https://pkg.go.dev/badge/github.com/cdzombak/heartbeat.svg)](https://pkg.go.dev/github.com/cdzombak/heartbeat)

Simple HTTP heartbeat & health server implementation for Golang. This implementation works particularly well with [Uptime Kuma](https://github.com/louislam/uptime-kuma)'s push monitors.

## Installation

```shell
go get github.com/cdzombak/heartbeat
```

## Usage

Create and start a Heartbeat client:

```go
hb, err = NewHeartbeat(&HeartbeatConfig{
HeartbeatInterval: 30 * time.Second,
LivenessThreshold: 60 * time.Second,
HeartbeatURL: "https://uptimekuma.example.com:9001/api/push/1234abcd?status=up&msg=OK&ping=",
Port: 8888,
OnError: func(err error) {
log.Printf("heartbeat error: %s", err)
},
})
if err != nil {
panic(err)
}

// other program setup might go here

hb.Start()
```

Then, in your program's main loop/ticker/event handler, call `Alive` periodically to indicate that everything's working:

```go
hb.Alive(time.Now())
```

## License

MIT; see `LICENSE` in this repository.

## Author

- Chris Dzombak ([dzombak.com](https://www.dzombak.com))
- [GitHub @cdzombak](https://www.github.com/cdzombak)