mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-01-27 05:25:58 +00:00
Add expvar JSON @ /debug/vars
Counters include: - Uptime - SMTP connections - SMTP connections (current) - SMTP messages delivered
This commit is contained in:
@@ -88,7 +88,9 @@ func (ss *Session) String() string {
|
||||
*/
|
||||
func (s *Server) startSession(id int, conn net.Conn) {
|
||||
log.Info("Connection from %v, starting session <%v>", conn.RemoteAddr(), id)
|
||||
expConnectsCurrent.Add(1)
|
||||
defer conn.Close()
|
||||
defer expConnectsCurrent.Add(-1)
|
||||
|
||||
ss := NewSession(s, id, conn)
|
||||
ss.greet()
|
||||
@@ -316,6 +318,7 @@ func (ss *Session) dataHandler() {
|
||||
// Mail data complete
|
||||
for _, m := range messages {
|
||||
m.Close()
|
||||
expDeliveredTotal.Add(1)
|
||||
}
|
||||
ss.send("250 Mail accepted for delivery")
|
||||
ss.info("Message size %v bytes", msgSize)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package smtpd
|
||||
|
||||
import (
|
||||
"expvar"
|
||||
"fmt"
|
||||
"github.com/jhillyerd/inbucket/config"
|
||||
"github.com/jhillyerd/inbucket/log"
|
||||
@@ -16,6 +17,10 @@ type Server struct {
|
||||
dataStore *DataStore
|
||||
}
|
||||
|
||||
var expConnectsTotal = new(expvar.Int)
|
||||
var expConnectsCurrent = new(expvar.Int)
|
||||
var expDeliveredTotal = new(expvar.Int)
|
||||
|
||||
// Init a new Server object
|
||||
func New() *Server {
|
||||
ds := NewDataStore()
|
||||
@@ -49,7 +54,15 @@ func (s *Server) Start() {
|
||||
// or maybe attempt to restart smtpd
|
||||
panic(err)
|
||||
} else {
|
||||
expConnectsTotal.Add(1)
|
||||
go s.startSession(sid, conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
m := expvar.NewMap("smtp")
|
||||
m.Set("connectsTotal", expConnectsTotal)
|
||||
m.Set("connectsCurrent", expConnectsCurrent)
|
||||
m.Set("deliveredTotal", expDeliveredTotal)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user