Closed drsect0r closed 8 years ago
Thanks @drsect0r
I was aware of the issue, just haven't been able to find time to fix it. I have to vendor a dependant library that has since been updated from which that struct cpu
is from.
SIDE NOTE: Everyone says not to vendor your library's dependancies, but this is exactly why you have to...
I tried finding the dependency myself but my google-fu failed me. Thanks anyway :+1:
the dependancy is here https://github.com/shirou/gopsutil if you wanted to/are able to help :)
I also have to add an attribution as I believe the library now uses a BSD license.
Oh crap, something else failed as I saw/found this dependency. I will try to make a merge :)
Thanks!
@joeybloggs I haven't been able to allocate any time on this issue. Do you see any opportunity?
Hey @drsect0r
went at it this morning and believe the build issue should be fixed, please let me know if the fix works for you also.
Are the examples still adequate? I have server.go
running, when I run client.go
neither of the two generate any output or seem to be doing anything at all.
@drsect0r client.go is exiting before sending any output, I'll adjust the example oh and you have to change the domain of the client...
anyways here is a working client for you, I will update the client .go to be exactly this:
package main
import (
"fmt"
"net/http"
"runtime"
"gopkg.in/go-playground/stats.v1"
)
var statsClient *stats.ClientStats
func main() {
serverConfig := &stats.ServerConfig{
Domain: "localhost",
Port: 3008,
Debug: false,
}
clientConfig := &stats.ClientConfig{
Domain: "",
Port: 3009,
PollInterval: 1000,
Debug: false,
LogHostInfo: true,
LogCPUInfo: true,
LogTotalCPUTimes: true,
LogPerCPUTimes: true,
LogMemory: true,
LogGoMemory: true,
}
client, err := stats.NewClient(clientConfig, serverConfig)
if err != nil {
panic(err)
}
go client.Run()
// if you want to capture HTTP requests in a middleware you'll have
// to have access to the client.
// see below for middleware example
statsClient = client
<-make(chan struct{})
}
// LoggingRecoveryHandler ...
//
//
// Middleware example for capturing HTTP Request info
// NOTE: this is standard go middlware, but could be adapted to other types/styles easily
//
func LoggingRecoveryHandler(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
// log incoming request
logReq := statsClient.NewHTTPRequest(w, r)
defer func() {
if err := recover(); err != nil {
trace := make([]byte, 1<<16)
n := runtime.Stack(trace, true)
// log failure
logReq.Failure(fmt.Sprintf("%s\n%s", err, trace[:n]))
http.Error(w, "Friendly error message", 500)
return
}
}()
next.ServeHTTP(logReq.Writer(), r)
// log completion
logReq.Complete()
}
return http.HandlerFunc(fn)
}
ok example updated.
Oh, I definitely need my coffee ... Thank you! :+1: