faabiosr / htz

Go healthcheck for your apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Htz

Build Status Codecov branch GoDoc Go Report Card License

Go healthcheck for your apps

Instalation

Htz requires Go 1.10 or later.

go get github.com/faabiosr/htz

If you want to get an specific version, please use the example below:

go get gopkg.in/faabiosr/htz.v0

Usage

Simple usage

package main

import (
	"encoding/json"
	"fmt"
	"github.com/faabiosr/htz"
	"time"
)

func main() {
	checkers := []htz.Checker{
		func() *htz.Check {
			return &htz.Check{
				Name:         "some-api",
				Type:         "internal-service",
				Status:       false,
				ResponseTime: 6 * time.Second,
				Optional:     false,
				Details: map[string]interface{}{
					"url": "internal-service.api",
				},
			}
		},
	}

	h := htz.New("my-app", "0.0.1", checkers...)
	res, _ := json.MarshalIndent(h.Check(), "", "  ")

	fmt.Println(string(res))
}

HTTP Check

package main

import (
	"github.com/faabiosr/htz"
	"net/http"
	"time"
)

func main() {
	checkers := []htz.Checker{
		func() *htz.Check {
			return &htz.Check{
				Name:         "some-api",
				Type:         "internal-service",
				Status:       false,
				ResponseTime: 6 * time.Second,
				Optional:     false,
				Details: map[string]interface{}{
					"url": "internal-service.api",
				},
			}
		},
	}

	h := htz.New("my-app", "0.0.1", checkers...)

	http.Handle("/htz", h)

	http.ListenAndServe(":8080", nil)
}

Available checkers

DB

package main

import (
	"database/sql"
	"encoding/json"
	"fmt"
	"github.com/faabiosr/htz"
	"github.com/faabiosr/htz/checker"
	_"github.com/lib/pq"
)

func main() {
	db, _ := sql.Open("postgres", "user=htz dbname=htz")

	h := htz.New("my-app", "0.0.1", checker.DB(db, true))
	res, _ := json.MarshalIndent(h.Check(), "", "  ")

	fmt.Println(string(res))
}

Redis

package main

import (
	"encoding/json"
	"fmt"
	"github.com/faabiosr/htz"
	"github.com/faabiosr/htz/checker"
    "github.com/go-redis/redis"
)

func main() {
    client := redis.NewClient(&redis.Options{
        Addr: "localhost:6379",
    })

	h := htz.New("my-app", "0.0.1", checker.Redis(client, true))
	res, _ := json.MarshalIndent(h.Check(), "", "  ")

	fmt.Println(string(res))
}

Runtime

package main

import (
	"fmt"
	"github.com/faabiosr/htz"
	"github.com/faabiosr/htz/checker"
)

func main() {
	h := htz.New("my-app", "0.0.1", checker.Runtime(false))
	res, _ := json.MarshalIndent(h.Check(), "", "  ")

	fmt.Println(string(res))
}

Development

Requirements

Makefile

// Clean up
$ make clean

// Creates folders and download dependencies
$ make configure

// Run tests and generates html coverage file
make cover

// Download project dependencies
make depend

// Format all go files
make fmt

// Run linters
make lint

// Run tests
make test

License

This project is released under the MIT licence. See LICENSE for more details.

About

Go healthcheck for your apps

License:MIT License


Languages

Language:Go 92.1%Language:Makefile 7.9%