Skip to content

Instantly share code, notes, and snippets.

@netgusto
Last active November 11, 2022 10:02
Show Gist options
  • Save netgusto/6b107ea050c7de07dc02372dbc7c2180 to your computer and use it in GitHub Desktop.
Save netgusto/6b107ea050c7de07dc02372dbc7c2180 to your computer and use it in GitHub Desktop.
SIGINFO (Ctrl+t) to dump live metrics in go
// Send SIGINFO (Ctrl+t on the shell, or kill -info <pid>)
// To dump live metrics
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINFO)
for range sigs {
duration := time.Since(start)
// obviously adapt this next line to your need :)
logger.Info(fmt.Sprintf("Processed %d jobs in %s; Throughput=%.4f/s\n", nbprocessed, duration.String(), float64(nbprocessed)/duration.Seconds()))
// The list of existing goroutines (running or blocked)
// and their location in the code
fmt.Printf("Goroutines: %d\n", runtime.NumGoroutine())
_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 2)
// anything else!
// ...
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment