httphealth

package
v0.0.0-...-a54a33a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: AGPL-3.0 Imports: 10 Imported by: 1

Documentation

Overview

Package httphealth provides a simple component that offers an http interface for health checking, monitoring (using Prometheus) and profiling.

This package is a work in progress and makes no API stability promises.

Example

Creates a health server that checks a service and exposes metrics

package main

import (
	"errors"
	"log"
	"math/rand"
	"net"

	"github.com/luids-io/core/httphealth"
)

// service is a supervised object
type service struct{}

// Ping implements httphealth.Pingable interface
func (s service) Ping() error {
	if rand.Intn(10) > 8 {
		return errors.New("error in supervised")
	}
	return nil
}

// Creates a health server that checks a service and exposes metrics
func main() {
	lis, err := net.Listen("tcp", "127.0.0.1:8081")
	if err != nil {
		log.Fatalf("listening: %v", err)
	}
	health := httphealth.New(&service{}, httphealth.Metrics(true))
	health.Serve(lis)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option encapsules server options.

func Metrics

func Metrics(b bool) Option

Metrics option exposes prometheus metrics.

func Profile

func Profile(b bool) Option

Profile option exposes pprof profiling information.

func SetIPFilter

func SetIPFilter(f ipfilter.Filter) Option

SetIPFilter option sets an ip filter.

func SetLogger

func SetLogger(l yalogi.Logger) Option

SetLogger option sets a logger for the component.

type Pingable

type Pingable interface {
	Ping() error
}

Pingable must be implemented by the service to be monitored.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an http server that provides health services. It must be constructed using New.

func New

func New(supervised Pingable, opt ...Option) *Server

New constructs a new server that supervises the 'Pingable' object.

func (*Server) Close

func (s *Server) Close() error

Close immediately server. See http.Server doc.

func (*Server) Serve

func (s *Server) Serve(lis net.Listener) error

Serve http.

func (*Server) ServeTLS

func (s *Server) ServeTLS(lis net.Listener, certFile string, keyFile string) error

ServeTLS https.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown waits all pending operations to shutdown. See http.Server doc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL