prometheus-community / pro-bing

A library for creating continuous probers
MIT License
326 stars 55 forks source link

Add HTTP probing support #89

Closed anton-kuklin closed 7 months ago

anton-kuklin commented 8 months ago

This PR adds support for HTTP probing. It provides an API based on httptrace callbacks.

Current list of configurable options:

Available callbacks:

Misc config:

Basic usage example

httpCaller := probing.NewHttpCaller("https://www.google.com",
    probing.WithHTTPCallerCallFrequency(time.Second),
    probing.WithHTTPCallerOnResp(func(suite *probing.TraceSuite, info *probing.HTTPCallInfo) {
        fmt.Printf("got resp, status code: %d, latency: %s\n",
            info.StatusCode,
            suite.GetGeneralEnd().Sub(suite.GetGeneralStart()),
        )
    }),
)

// Listen for Ctrl-C.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
    <-c
    httpCaller.Stop()
}()
httpCaller.Run()

Based on issue: https://github.com/prometheus-community/pro-bing/issues/88

anton-kuklin commented 8 months ago

CC: @davinci26