The Go-Server-Stats package can be used to count statistics for a web service written in Go.
┌─┐┌─┐ ┌─┐┌─┐┬─┐┬ ┬┌─┐┬─┐ ┌─┐┌┬┐┌─┐┌┬┐┌─┐
│ ┬│ │───└─┐├┤ ├┬┘└┐┌┘├┤ ├┬┘───└─┐ │ ├─┤ │ └─┐
└─┘└─┘ └─┘└─┘┴└─ └┘ └─┘┴└─ └─┘ ┴ ┴ ┴ ┴ └─┘
To install the package, use the go
command
> go get github.com/andrewlader/go-server-stats
Requires Go >= v1.2
Add stats.Stats
to the web service. For example:
// the HTTP handler instance
type httpServer struct {
stats *stats.Stats
mux map[string]apiHandler
}
Then when an API is called, use the Update()
method to increment the counters:
server.stats.Update(wasSuccessful, uint64(request.ContentLength), numberOfBytesWritten)