1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

Add goroutine count to metrics

This commit is contained in:
James Hillyerd
2017-01-22 12:45:53 -08:00
parent 83b71334c2
commit cf7bdee925
3 changed files with 26 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"time"
@@ -33,9 +34,6 @@ var (
pidfile = flag.String("pidfile", "none", "Write our PID into the specified file")
logfile = flag.String("logfile", "stderr", "Write out log into the specified file")
// startTime is used to calculate uptime of Inbucket
startTime = time.Now()
// shutdownChan - close it to tell Inbucket to shut down cleanly
shutdownChan = make(chan bool)
@@ -44,6 +42,24 @@ var (
pop3Server *pop3d.Server
)
func init() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage of inbucket [options] <conf file>:")
flag.PrintDefaults()
}
// Server uptime for status page
startTime := time.Now()
expvar.Publish("uptime", expvar.Func(func() interface{} {
return time.Since(startTime) / time.Second
}))
// Goroutine count for status page
expvar.Publish("goroutines", expvar.Func(func() interface{} {
return runtime.NumGoroutine()
}))
}
func main() {
config.Version = VERSION
config.BuildDate = BUILDDATE
@@ -166,17 +182,3 @@ func timedExit() {
removePIDFile()
os.Exit(0)
}
func init() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage of inbucket [options] <conf file>:")
flag.PrintDefaults()
}
expvar.Publish("uptime", expvar.Func(uptime))
}
// uptime() is published as an expvar
func uptime() interface{} {
return time.Since(startTime) / time.Second
}