๐Ÿฅ Barebones, detailed health check library for Go

go-health

๐Ÿฅ Barebones, detailed health check library for Go

Build Go Reference

go-health does away with the kitchen sink mentality of other health check libraries. You aren't getting a default HTTP handler out of the box that is router dependent or has opinions about the shape or format of the health data being published. You aren't getting pre-built health checks. But you do get a simple system for checking the health of resources asynchronously with built-in caching and timeouts. Only what you absolutely need, and nothing else.

Quickstart

Install the package:

go get github.com/jaredpetersen/go-health/health

Example:

// Create the health monitor that will be polling the resources.
healthMonitor := health.New()

// Prepare the context -- this can be used to stop async monitoring.
ctx := context.Background()

// Create your health checks.
fooHealthCheckFunc := func(ctx context.Context) health.Status {
    return health.Status{State: health.StateDown}
}
fooHealthCheck := health.NewCheck("foo", fooHealthCheckFunc)
fooHealthCheck.Timeout = time.Second * 2
healthMonitor.Monitor(ctx, fooHealthCheck)

barHealthCheckFunc := func(ctx context.Context) health.Status {
    return health.Status{State: health.StateUp}
}
barHealthCheck := health.NewCheck("bar", barHealthCheckFunc)
barHealthCheck.Timeout = time.Second * 2
healthMonitor.Monitor(ctx, barHealthCheck)

// Wait for goroutines to kick off
time.Sleep(time.Millisecond * 100)

// Retrieve the most recent cached result for all of the checks.
healthMonitor.Check()

Asynchronous Checking and Caching

Health checks in this package are only asynchronous for security purposes. Health endpoints in HTTP services can be a lucrative target for bad actors looking to execute a Denial of Service (DOS) attack. Some checks that your application performs to determine health may be somewhat expensive and a health endpoint centralizes all of those checks in a single convenient location for an attacker. This attacker can conveniently direct significant amount of traffic to your health check endpoints in an attempt to abuse and take down multiple systems in one go.

The best defense against this is to perform those checks on your schedule asynchronously, not the caller's schedule. Results from those checks should be cached and returned upon request.

This package spins up a goroutine for each configured health check that polls the check function. Each check has its own, individually configurable Time To Live (TTL) that dictates the duration between those polls. For example, if you specify a check with a TTL of two seconds, the check will execute, wait two seconds, and then execute again. This will go on forever until the context is closed.

By default, all checks created via health.NewCheck() are configured with a default TTL of one second.

Timeouts

You can optionally configure a timeout for each check. If set, the context provided to the check function will have a deadline set. When the deadline expires, the context will close the Done channel, just like the normal context behavior. go-health does not kill the check function execution, it only leverages the context to communicate that the configured timeout deadline has been exceeded. It is your responsibility to handle the context appropriately. For more information on context with deadline, see the context documentation.

Additional Information

The return type of the health check function supports adding arbitrary information to the status. This could be information like active database connections, response time for an HTTP request, etc.

type HTTPHealthCheckDetails struct {
    ResponseTime time.Duration
}
return health.Status{
    State:   health.StateUp,
    Details: HTTPHealthCheckDetails{ResponseTime: responseTime},
}
Similar Resources

Check DNS and optionally Consul and serve the status from a Web page

dns-checker Table of contents Preamble Compiling the program Keepalived and LVS Available options Setting up systemd Preamble This application checks

Nov 7, 2021

Get subdomain list and check whether they are active or not by each response code. Using API by c99.nl

Get subdomain list and check whether they are active or not by each response code. Using API by c99.nl

getsubdomain Get subdomain list and check whether they are active or not by each response code. Using API by c99.nl Installation โ–ถ go install github.c

Oct 24, 2022

Application wirtten in GO to check if the port on the remote host is open

portcheck A simple Pod that get API POST request with port type and number with a target's IP address and checks if the destination port is available

Nov 26, 2021

check if an {id, username, phonenumber, email} is associated with a facebook account

check if an {id, username, phonenumber, email} is associated with a facebook account

FacebookChecker FacebookChecker checks if an {id, username, phonenumber, email} is associated with a facebook account and get some information about t

Dec 2, 2022

This is a tool that allows you to check minecraft names availability, this tool can do around 3000~ names a minute or more!

Checker This is a tool that allows you to check minecraft names availability, this tool can do around 3000~ names a minute or more! Tutorial To instal

Feb 13, 2022

Simple dashboard to check if hosts are up (via ICMP)

About ping-dashboard is a simple dashboard to quickly check if a large amount of hosts are up (via ICMP). Building $ cd /path/to/build/directory $ GOB

Jan 14, 2022

A go module supply Java-Like generic stream programming (while do type check at runtime)

gostream A go module supplying Java-Like generic stream programming (while do type check at runtime) Using Get a Stream To get a Stream, using SliceSt

Jan 16, 2022

Multi-Threaded PURGE Request Method Check Tool

purgex Multi-Threaded PURGE Request Method Check Tool REQUIREMENTS AND INSTALLATION Build purgex: git clone https://github.com/jayateertha043/purgex.g

Jan 18, 2022

Dhrate - Quickly check Dockerhub rate (limit) as an unauthenticated user

Dhrate - Quickly check Dockerhub rate (limit) as an unauthenticated user

Dockerhub Rate A small Go program that returns the Dockerhub rate of an unauthen

Feb 7, 2022
Related tags
Cross check makes health checks on PostgreSQL and MySQL database servers

Cross Check Cross check makes health checks on PostgreSQL and MySQL database servers, it also performs master & slave control for clusters in H/A Acti

Jan 14, 2022
This repo contains a sample app exposing a gRPC health endpoint to demo Kubernetes gRPC probes.

This repo contains a sample app exposing a health endpoint by implementing grpc_health_v1. Usecase is to demo the gRPC readiness and liveness probes introduced in Kubernetes 1.23.

Feb 9, 2022
A simple, standalone, and lightWeight tool that can do health/status checking, written in Go.
A simple, standalone, and lightWeight tool that can do health/status checking, written in Go.

EaseProbe EaseProbe is a simple, standalone, and lightWeight tool that can do health/status checking, written in Go. Table of Contents EaseProbe 1. Ov

Dec 24, 2022
Use ICMP requests to check the alive subnet.

Doge-AliveCheck Use ICMP requests to check the alive subnet. Build go build -ldflags "-s -w" -trimpath Usage Doge-AliveCheck.exe

Nov 11, 2022
DNS Ping: to check packet loss and latency issues with DNS servers

DNSping DNS Ping checks packet loss and latency issues with DNS servers Installation If you have golang, easiest install is go get -u fortio.org/dnspi

Nov 18, 2022
Tool for monitoring network devices (mainly using SNMP) - monitoring check plugin
Tool for monitoring network devices (mainly using SNMP) - monitoring check plugin

Thola Description A tool for monitoring network devices written in Go. It features a check mode which complies with the monitoring plugins development

Dec 29, 2022
port close check scanner. detects open ports, sends alert with slack.

aite9 (port close check scanner) ใ‚ตใƒผใƒใฎใƒใƒผใƒˆใŒ็ฉบใ„ใฆใชใ„ใ“ใจใ‚’็ขบ่ชใ™ใ‚‹ใƒใƒผใƒˆใ‚นใ‚ญใƒฃใƒŠใƒผ ใŸใใ•ใ‚“ใฎใ‚ตใƒผใƒใ‚’็ฎก็†ใ—ใฆใ„ใ‚‹ใจ่จญๅฎšใƒŸใ‚นใงๅ†…้ƒจๅˆฉ็”จใƒใƒผใƒˆใŒๅค–้ƒจใซๅ…ฌ้–‹ใ•ใ‚Œใฆใ—ใพใฃใฆใ„ใ‚‹ๅฏ่ƒฝๆ€งใŒใ‚ใ‚Šใ€ใใ‚Œใซๆ—ฉใๆฐ—ไป˜ใใŸใ‚ใฎใƒใ‚งใƒƒใ‚ฏใƒ„ใƒผใƒซใงใ™ใ€‚ ใ‚ตใƒผใƒใฎใƒชใ‚นใƒˆใ‚’ๆจ™ๆบ–ๅ…ฅๅŠ›ใงๆธกใ™ใจ

Feb 3, 2022
golang script to check server & port status

netcheck Simple script to check if host alive by sending ICMP messages & TCP Port checks. ICMP messages not working without sudo privileges. usage net

Sep 2, 2022
go-ip-fraud-check has a feature to detect fraud from ip addresss.

go-ip-fraud-check go-ip-fraud-check has a feature to detect fraud from ip addresss. go-ip-fraud-check provides both of cli binary and golang API. Supp

Dec 16, 2022
A simple project which enables you to check wheather the website is up
A simple project which enables you to check wheather the website is up

Website Status Checker A simple project which enables you to check wheather the website is up and working fine or is the website has been crashed. Abo

Nov 8, 2021