Skip to content

kazhuravlev/healthcheck

Repository files navigation

Healthcheck for go applications

Go Reference License Build Status Go Report Card CodeCov Mentioned in Awesome Go

This tool allows you to unlock the kubernetes feature Liveness and Readiness.

Features

  • Logger to log failed probes
  • Automatic, manual and background checks
  • Respond with all healthchecks status in JSON format
  • Callback for integrate with metrics or other systems
  • Integrated web server

Quickstart

go get -u github.com/kazhuravlev/healthcheck

Check an examples.

package main

import (
	"context"
	"errors"
	"math/rand"
	"time"

	"github.com/kazhuravlev/healthcheck"
)

func main() {
	ctx := context.TODO()

	// 1. Init healthcheck instance. It will store all our checks.
	hc, _ := healthcheck.New()

	// 2. Register checks that will random respond with an error.
	hc.Register(ctx, healthcheck.NewBasic("redis", time.Second, func(ctx context.Context) error {
		if rand.Float64() > 0.5 {
			return errors.New("service is not available")
		}

		return nil
	}))

	// 3. Init and run a webserver for integration with Kubernetes.
	sysServer, _ := healthcheck.NewServer(hc, healthcheck.WithPort(8080))
	_ = sysServer.Run(ctx)

	// 4. Open http://localhost:8080/ready to check the status of your system
	select {}
}

Packages

No packages published

Languages