segmentio / stats

Go package for abstracting stats collection
https://godoc.org/github.com/segmentio/stats
MIT License
208 stars 32 forks source link

procstats kills process? #44

Closed matthewmueller closed 7 years ago

matthewmueller commented 7 years ago

Hey there. I'm running into procstats immediately killing the process on OSX. Here's the code I'm running

var prom = prometheus.DefaultHandler

func main() {
    log.SetHandler(text.New(os.Stderr))
    stats.Register(prom)

    c := procstats.StartCollector(procstats.NewGoMetrics())
    defer c.Close()

    router := httprouter.New()
    router.Handler("GET", "/", httpstats.NewHandler(http.HandlerFunc(index)))
    router.Handler("GET", "/metrics", http.HandlerFunc(prom.ServeHTTP))

    log.Infof("listening on http://localhost:9000")
    log.WithError(http.ListenAndServe(":9000", router)).Fatal("server died")
}

func index(w http.ResponseWriter, r *http.Request) {
    stats.Incr("visited index")
    defer stats.Time("timing you", time.Now()).Stop()
    w.Write([]byte("hi world!"))
}

And this is what I'm seeing:

go run stats.go
signal: killed

Is this intentional?

ivolo commented 7 years ago

hey @matthewmueller why are you up at 3am PST :)

achille-roussel commented 7 years ago

This is not intentional and it's the first time I'm getting this reported. The package doesn't send signals itself so this is weird. I'll try to repro later today.

In the mean time, if you can gather more info? Like trying to run the same code without the procstats.StartCollector call for example.

Also what version of Go are you running?

matthewmueller commented 7 years ago

@ivolo I'm in Asia 😆 I should be asking you guys that! Late night at the office?

@achille-roussel It's very odd, if I add anything related to procstats I hit it. Even if I do:

package main

import (
    "fmt"

    "github.com/segmentio/stats/procstats"
)

func main () {
  fmt.Println(procstats.CPUInfo{})
}

I get an immediate SIGKILL. But if I remove that call everything works wonderfully. Could this be related to cgo? I've tried reinstalling it via go get, but no luck there.

go version go1.8.3 darwin/amd64

UPDATE: Okay it's due to import "C". If I comment that out it doesn't immediately die. Maybe my cgo isn't setup properly.

matthewmueller commented 7 years ago

Okay sorry for the false alarm. It looks like it's due to this issue: https://github.com/golang/go/issues/19734