probing

package
v2.3.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2016 License: MIT, Apache-2.0 Imports: 5 Imported by: 0

README

Getting Started

Install the handler

We first need to serve the probing HTTP handler.

    http.HandleFunc("/health", probing.NewHandler())
    err := http.ListenAndServe(":12345", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}

Start to probe

Now we can start to probe the endpoint.

    id := "example"
    probingInterval = 5 * time.Second
    url := "http://example.com:12345/health"
    p.AddHTTP(id, probingInterval, url)

	time.Sleep(13 * time.Second)
	status, err := p.Status(id)
 	fmt.Printf("Total Probing: %d, Total Loss: %d, Estimated RTT: %v, Estimated Clock Difference: %v\n",
		status.Total(), status.Loss(), status.SRTT(), status.ClockDiff())
	// Total Probing: 2, Total Loss: 0, Estimated RTT: 320.771µs, Estimated Clock Difference: -35.869µs

TODOs:

  • TCP probing
  • UDP probing
  • Gossip based probing
  • More accurate RTT estimation
  • More accurate Clock difference estimation
  • Use a clock interface rather than the real clock

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("probing: id not found")
	ErrExist    = errors.New("probing: id exists")
)

Functions

func NewHandler

func NewHandler() http.Handler

Types

type Health

type Health struct {
	OK  bool
	Now time.Time
}

type Prober

type Prober interface {
	AddHTTP(id string, probingInterval time.Duration, endpoints []string) error
	Remove(id string) error
	RemoveAll()
	Reset(id string) error
	Status(id string) (Status, error)
}

func NewProber

func NewProber(tr http.RoundTripper) Prober

type Status

type Status interface {
	Total() int64
	Loss() int64
	Health() bool
	// Estimated smoothed round trip time
	SRTT() time.Duration
	// Estimated clock difference
	ClockDiff() time.Duration
	StopNotify() <-chan struct{}
}

Jump to

Keyboard shortcuts

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