Code Monkey home page Code Monkey logo

go-httpstat's Introduction

go-httpstat Go Documentation Build Status MIT License

go-httpstat is a golang package to trace golang HTTP request latency (DNSLookup, TCP Connection and so on). Because it uses httptrace internally, just creating go-httpstat powered context and giving it your http.Request kicks tracing (no big code modification is required). The original idea came from httpstat command ( and Dave Cheney's golang implementation) 👏. This package now traces same latency infomation as them.

See usage and example on GoDoc.

NOTE: Since httptrace was introduced after go1.7, this package may not work with old HTTP client. Especially, if you don't use net.DialContext it can not trace DNS and connection.

Install

Use go get,

$ go get github.com/tcnksm/go-httpstat

Author

Taichi Nakashima

go-httpstat's People

Contributors

adomokos avatar avetisk avatar haya14busa avatar songmu avatar tcnksm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-httpstat's Issues

result.ContentTransfer freezed value since update Go1.8

Hello,

Thanks again for the update in 1.8

I have a small issue since the update. I'm not sure it's linked to the update, but i don't understand.

i always have the same fix value for ContentTransfert:

with:

end := time.Now()
fmt.Println("result.ContentTransfer(end) ", result.ContentTransfer(end))

The result is always:
result.ContentTransfer(end) 2562047h47m16.854775807s

Thanks for your help,

Benoît

Same total request time when using a Transport

This is similar to #2 and results in the same (9223372036854).

I'm trying to test the request time of a bunch of proxies by calling https://ipinfo.io/json with a proxy in the transport of the client.

When I'm running that code the request always has the exact same total time even though its proxies in other continents. Anything I'm missing? Code is basically the same as this one: https://github.com/tcnksm/go-httpstat/blob/master/_example/main.go except that I'm using a transport. I also added the output of the code from GoDoc which looks as expected

https://play.golang.org/p/RxhH0r236p

race conditions writing to Result

First off, thanks for writing this cool utility. Love how easy it is to add just a few lines and get nicely formatted statistics for a request.

Unfortunately I'm unable to use this in a production project that runs the test suite with the -race flag enabled. I'd like it if go-httpstat could avoid race conditions.

Results marshalling to json

Not really an issue but may be feature. I am struggling to get the results converted to json because marshalling does skip the last lines of both the results (individual and total). Also, it is giving me in nano secs. Can you help me with that ? Thanks.

Wrong sum if all values are zero

I think I found a small bug in the code that does the calculations for the total amount of time. If you set all values to 0 (for example if there's an outtage) the result is 9223372036854 instead of 0.

result := httpstat.Result{
        DNSLookup:        0.0,
	TCPConnection:    0.0,
	TLSHandshake:     0.0,
	ServerProcessing: 0.0,
	NameLookup:       0.0,
	Connect:          0.0,
	Pretransfer:      0.0,
	StartTransfer:    0.0,
}
result.End(time.Now())

If you print result:

TLSHandshake: 0 ms, Total: 9223372036854 ms, StartTransfer: 0 ms, DNSLookup: 0 ms, TCPConnection: 0 ms, ServerProcessing: 0 ms, ContentTransfer: 9223372036854 ms, NameLookup: 0 ms, Connect: 0 ms, Pretransfer: 0 ms

Goroutine support?

Just like as follows:
`package main

import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"time"

"github.com/tcnksm/go-httpstat"
"sync"
//"runtime"

)

func worker(host string, wg *sync.WaitGroup) {
req, err := http.NewRequest("GET", host, nil)
if err != nil {
wg.Done()
return
}

var result httpstat.Result
ctx := httpstat.WithHTTPStat(req.Context(), &result)
req = req.WithContext(ctx)

client := http.DefaultClient
client.Timeout = 5 * time.Second
res, err := client.Do(req)
if err != nil {
	wg.Done()
	return
}

if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
	wg.Done()
	return
}
res.Body.Close()
result.End(time.Now())

fmt.Println(result)
wg.Done()

}

func main() {
args := os.Args
if len(args) < 2 {
log.Fatalf("Usage: go run main.go URL")
}

//runtime.GOMAXPROCS(runtime.NumCPU())

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
	wg.Add(1)
	go worker(args[1], &wg)
}
wg.Wait()

}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.