From cf7bdee9254635821d25a68057367faa0f8517f9 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 22 Jan 2017 12:45:53 -0800 Subject: [PATCH] Add goroutine count to metrics --- inbucket.go | 36 +++++++++++---------- themes/bootstrap/public/metrics.js | 2 +- themes/bootstrap/templates/root/status.html | 6 ++++ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/inbucket.go b/inbucket.go index d737e5d..e6a2852 100644 --- a/inbucket.go +++ b/inbucket.go @@ -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] :") + 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] :") - flag.PrintDefaults() - } - - expvar.Publish("uptime", expvar.Func(uptime)) -} - -// uptime() is published as an expvar -func uptime() interface{} { - return time.Since(startTime) / time.Second -} diff --git a/themes/bootstrap/public/metrics.js b/themes/bootstrap/public/metrics.js index c6512bc..f3fc0f1 100644 --- a/themes/bootstrap/public/metrics.js +++ b/themes/bootstrap/public/metrics.js @@ -104,6 +104,7 @@ function displayMetrics(data, textStatus, jqXHR) { metric('memstatsHeapSys', data.memstats.HeapSys, sizeFilter, true); metric('memstatsHeapObjects', data.memstats.HeapObjects, numberFilter, true); metric('smtpConnectsCurrent', data.smtp.ConnectsCurrent, numberFilter, true); + metric('goroutinesCurrent', data.goroutines, numberFilter, true); metric('httpWebSocketConnectsCurrent', data.http.WebSocketConnectsCurrent, numberFilter, true); // Server-side history @@ -125,4 +126,3 @@ function loadMetrics() { // jQuery.getJSON( url [, data] [, success(data, textStatus, jqXHR)] ) jQuery.getJSON('/debug/vars', null, displayMetrics); } - diff --git a/themes/bootstrap/templates/root/status.html b/themes/bootstrap/templates/root/status.html index d5845a6..0613e14 100644 --- a/themes/bootstrap/templates/root/status.html +++ b/themes/bootstrap/templates/root/status.html @@ -107,6 +107,12 @@ $(document).ready(
.
+
+
Goroutines:
+
.
+
.
+ +
Open WebSockets:
.