1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +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
}

View File

@@ -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);
}

View File

@@ -107,6 +107,12 @@ $(document).ready(
<div class="col-sm-4"><span id="s-memstatsHeapObjects">.</span></div>
<div class="col-sm-2 hidden-xs">(10min)</div>
</div>
<div class="row">
<div class="col-sm-3 col-xs-7"><b>Goroutines:</b></div>
<div class="col-sm-3 col-xs-5"><span id="m-goroutinesCurrent">.</span></div>
<div class="col-sm-4"><span id="s-goroutinesCurrent">.</span></div>
<div class="col-sm-2 hidden-xs">(10min)</div>
</div>
<div class="row">
<div class="col-sm-3 col-xs-7"><b>Open WebSockets:</b></div>
<div class="col-sm-3 col-xs-5"><span id="m-httpWebSocketConnectsCurrent">.</span></div>