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:
36
inbucket.go
36
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] <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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user