Last active
November 11, 2022 10:02
-
-
Save netgusto/6b107ea050c7de07dc02372dbc7c2180 to your computer and use it in GitHub Desktop.
SIGINFO (Ctrl+t) to dump live metrics in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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