https://github.com/chickenzord/go-health-prometheus
Go library for integrating alexliesenfeld/health with Prometheus
https://github.com/chickenzord/go-health-prometheus
go healthcheck metrics prometheus
Last synced: 30 days ago
JSON representation
Go library for integrating alexliesenfeld/health with Prometheus
- Host: GitHub
- URL: https://github.com/chickenzord/go-health-prometheus
- Owner: chickenzord
- License: mit
- Created: 2022-10-29T10:31:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-29T12:53:45.000Z (almost 3 years ago)
- Last Synced: 2025-02-02T01:42:26.961Z (9 months ago)
- Topics: go, healthcheck, metrics, prometheus
- Language: Go
- Homepage: https://pkg.go.dev/github.com/chickenzord/go-health-prometheus
- Size: 27.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-health-prometheus
Go library for integrating [alexliesenfeld/health](https://github.com/alexliesenfeld/health) with Prometheus.
Implements both Health Interceptor and Prometheus Collector.[](https://pkg.go.dev/github.com/chickenzord/go-health-prometheus)
[](https://goreportcard.com/report/github.com/chickenzord/go-health-prometheus)## Module installation
```sh
go get github.com/chickenzord/go-health-prometheus
```## Example usage
```go
package mainimport (
"fmt"
"net/http""github.com/alexliesenfeld/health"
healthprometheus "github.com/chickenzord/go-health-prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)func main() {
healthProm := healthprometheus.NewDefault("", "myapp")// Setup health checker
healthChecker := health.NewChecker(
health.WithInterceptors(healthProm.Interceptor), // Use the interceptor to record health metrics
// ... checks omitted for brevity
)// Setup Prometheus
registry := prometheus.NewRegistry()
registry.MustRegister(healthProm.Collectors()...) // Register the health metric collectors
// ... you can register another collectors here (e.g. Go process collector)// Setup HTTP server
mux := http.NewServeMux()
mux.Handle("/health", health.NewHandler(healthChecker))
mux.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))fmt.Println("Listening on :9000")
if err := http.ListenAndServe(":9000", mux); err != nil {
panic(err)
}
}
```See `example` folder for more info on how to use this library.
## Example metrics
```
# database is UP
myapp_health{name="database" status="up"} 1
myapp_health{name="database" status="down"} 0
myapp_health{name="database" status="unknown"} 0# redis is DOWN
myapp_health{name="redis" status="up"} 0
myapp_health{name="redis" status="down"} 1
myapp_health{name="redis" status="unknown"} 0
```