httphealth
HTTPHealth provides a simple component that offers an http interface for health checking and monitoring using Prometheus.
Usage
package main
import (
"errors"
"log"
"math/rand"
"net"
"github.com/sirupsen/logrus"
"github.com/luisguillenc/httphealth"
"github.com/luisguillenc/ipfilter"
)
func main() {
lis, err := net.Listen("tcp", "0.0.0.0:8081")
if err != nil {
log.Fatalf("listening: %v", err)
}
wl := ipfilter.Whitelist(
[]string{"127.0.0.1", "192.168.1.0/24"},
)
logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
health := httphealth.New(
&service{},
httphealth.SetIPFilter(wl),
httphealth.SetLogger(logger),
httphealth.Metrics(true),
)
health.Serve(lis)
}
type service struct{}
func (s service) Ping() error {
if rand.Intn(10) > 8 {
return errors.New("error in supervised")
}
return nil
}