All Projects → gritzkoo → golang-health-checker

gritzkoo / golang-health-checker

Licence: MIT license
A simple package to allow you to track your application healthy

Programming Languages

go
31211 projects - #10 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to golang-health-checker

nodejs-health-checker
This is a Node package that allows you to track the health of your application providing readiness and liveness functionalities.
Stars: ✭ 34 (+183.33%)
Mutual labels:  healthcheck, health-check, k8s, liveness-probe, readiness-probe, hacktoberfest2020
ngx stream upstream check module
nginx health checker (tcp/udp/http) for stream upstream servers.
Stars: ✭ 18 (+50%)
Mutual labels:  healthcheck, health-check
aarogya seva
A beautiful 😍 covid-19 app with self - assessment and more.
Stars: ✭ 118 (+883.33%)
Mutual labels:  healthcheck, health-check
Reloader
Reloader is maintained by Stakater. Like it? Please let us know at [email protected]
Stars: ✭ 2,930 (+24316.67%)
Mutual labels:  k8s, pods
microservice-graph-explorer
Navigate and explore all of the microservices in your application in real time using the real application connections.
Stars: ✭ 71 (+491.67%)
Mutual labels:  healthcheck, health-check
ml-resources-react
A simple react app displaying resources to learn Machine learning.
Stars: ✭ 15 (+25%)
Mutual labels:  hacktoberfest2020
active-monitor
Provides deep monitoring and self-healing of Kubernetes clusters
Stars: ✭ 135 (+1025%)
Mutual labels:  healthcheck
app-idea-generator
💡 Generate app ideas to take inspiration from, or to have a laugh
Stars: ✭ 13 (+8.33%)
Mutual labels:  hacktoberfest2020
CP-DSA-Cpp-C
🕺 Give me data and I will structure it! 🔥
Stars: ✭ 27 (+125%)
Mutual labels:  hacktoberfest2020
Hacktoberfest-Nepal-2020
A beginner-friendly open source repository to create your first pull request.
Stars: ✭ 15 (+25%)
Mutual labels:  hacktoberfest2020
crate-sample-apps
A JavaScript guestbook app with a number of different backend implementations, each using a different client library to communicate with CrateDB.
Stars: ✭ 57 (+375%)
Mutual labels:  hacktoberfest2020
Hacktoberfest
This repository is basically about adding the name, position, Github username link, LinkedIn profile as well as the country by creating a commit.
Stars: ✭ 33 (+175%)
Mutual labels:  hacktoberfest2020
CookeyLang
The official CookeyLang
Stars: ✭ 16 (+33.33%)
Mutual labels:  hacktoberfest2020
aws-cloud-map-mcs-controller-for-k8s
K8s controller implementing Multi-Cluster Services API based on AWS Cloud Map.
Stars: ✭ 61 (+408.33%)
Mutual labels:  k8s
good-first-issues
Find good first issues right from your CLI! 🚀
Stars: ✭ 64 (+433.33%)
Mutual labels:  hacktoberfest2020
redisplanet
Redisplanet - An Ultimate Hands-on Labs on Redis
Stars: ✭ 24 (+100%)
Mutual labels:  hacktoberfest2020
kubectl-janitor
List Kubernetes objects in a problematic state
Stars: ✭ 48 (+300%)
Mutual labels:  k8s
CKA-Exercises
A set of curated exercises to help prepare you for the Certified Kubernetes Administrator Exam by the Cloud Native Computing Foundation
Stars: ✭ 51 (+325%)
Mutual labels:  k8s
Algorithms
Short explanations and implementations of different algorithms in multiple languages
Stars: ✭ 37 (+208.33%)
Mutual labels:  hacktoberfest2020
ProductsStoreOnKubernetes
Demoing deployment of Docker containers into Kubernetes for both minikube and Azure AKS.
Stars: ✭ 90 (+650%)
Mutual labels:  k8s

golang-health-checker

test Build Status Coverage Status views views per week clones clones per week Go Reference GitHub go.mod Go version GitHub repo size GitHub GitHub issues Go Report Card

A simple package to allow you to track your application healthy providing two ways of checking:

Simple: will return a "fully functional" string and with this, you can check if your application is online and responding without any integration check

Detailed: will return a detailed status for any integration configuration informed on the integrations, just like in the examples below

How to install

If you are just starting a Go projetct you must start a go.mod file like below

go mod init github.com/my/repo

Or else, you already has a started project, just run the command below

go get github.com/gritzkoo/golang-health-checker

How to use

In this example, we will use the Echo web server to show how to import and use Simple and Detailed calls.

If you want check the full options in configurations, look this IntegrationConfig struct

Available integrations

  • Redis
  • Memcached
  • Web integration (https)
package main

import (
 "net/http"

 "github.com/gin-gonic/gin"
 "github.com/gritzkoo/golang-health-checker/pkg/healthcheck"
)

func main() {
 // all the content below is just an example
 // Gin instance
 e := gin.Default()

 // example of simple call
 e.GET("/health-check/liveness", func(c *gin.Context) {
  c.JSON(http.StatusOK, healthcheck.HealthCheckerSimple())
 })
 // example of detailed call
 e.GET("/health-check/readiness", func(c *gin.Context) {
  // define all integrations of your application with type healthcheck.ApplicationConfig
  myApplicationConfig := healthcheck.ApplicationConfig{ // check the full list of available props in structs.go
   Name:    "You APP Name", // optional prop
   Version: "V1.0.0",       // optional prop
   Integrations: []healthcheck.IntegrationConfig{ // mandatory prop
    {
     Type: healthcheck.Redis, // this prop will determine the kind of check, the list of types available in structs.go
     Name: "redis-user-db",   // the name of you integration to display in response
     Host: "redis",       // you can pass host:port and omit Port attribute
     Port: "6379",
     DB:   0, // default value is 0
    }, {
     Type: healthcheck.Memcached, // this prop will determine the kind of check, the list of types available in structs.go
     Name: "Memcached server",    // the name of you integration to display in response
     Host: "memcache",           // you can pass host:port and omit Port attribute
     Port: "11211",
    }, {
     Type:    healthcheck.Web,             // this prop will determine the kind of check, the list of types available in structs.go
     Name:    "Github Integration",        // the name of you integration to display in response
     Host:    "https://github.com/status", // you can pass host:port and omit Port attribute
     TimeOut: 5,                           // default value to web call is 10s
     Headers: []healthcheck.HTTPHeader{ // to customize headers to perform a GET request
      {
       Key:   "Accept",
       Value: "application/json",
      },
     },
    }, {
     Type:    "unknown",                   // this prop will determine the kind of check, the list of types available in structs.go
     Name:    "Github Integration",        // the name of you integration to display in response
     Host:    "https://github.com/status", // you can pass host:port and omit Port attribute
     TimeOut: 5,                           // default value to web call is 10s
     Headers: []healthcheck.HTTPHeader{ // to customize headers to perform a GET request
      {
       Key:   "Accept",
       Value: "application/json",
      },
     },
    },
   },
  }
  c.JSON(http.StatusOK, healthcheck.HealthCheckerDetailed(myApplicationConfig))
 })
 // Start server
 e.Run(":8888")
}

This simple call will return a JSON as below

{
  "status": "fully functional"
}

And detailed call will return a JSON as below

{
  "name": "You APP Name",
  "status": false, # here is the main status of your application when one of the integrations fails.. false will return
  "version": "V1.0.0",
  "date": "2021-08-27 08:18:06.762044096 -0300 -03 m=+24.943851850",
  "duration": 0.283596049,
  "integrations": [
    {
      "name": "Github Integration",
      "kind": "unknown",
      "status": false,
      "response_time": 0,
      "url": "https://github.com/status",
      "errors": "unsuported type of:unknown"
    },
    {
      "name": "Memcached server",
      "kind": "Memcached DB",
      "status": true,
      "response_time": 0.000419116,
      "url": "localhost:11211"
    },
    {
      "name": "redis-user-db",
      "kind": "Redis DB",
      "status": true,
      "response_time": 0.000845594,
      "url": "localhost:6379"
    },
    {
      "name": "Github Integration",
      "kind": "Web service API",
      "status": true,
      "response_time": 0.283513713,
      "url": "https://github.com/status"
    }
  ]
}

Kubernetes liveness and readiness probing

And then, you could call this endpoints manually to see your application health, but, if you are using modern kubernetes deployment, you can config your chart to check your application with the setup below:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: 'go' #your application image
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /health-check/liveness
        port: 80
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3
  - name: readiness
    image: 'go' #your application image
    args:
    - /server
    readinessProbe:
      httpGet:
        path: /health-check/readiness
        port: 80
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].