@@ -22,6 +22,7 @@ import (
2222 "os"
2323 "sort"
2424 "strconv"
25+ "sync"
2526 "time"
2627
2728 "github.com/choria-io/fisk"
@@ -98,6 +99,8 @@ func (c *microCmd) echoHandler(req micro.Request) {
9899
99100func (c * microCmd ) serveAction (_ * fisk.ParseContext ) error {
100101 var err error
102+ var combinedPayload int
103+ var mu sync.Mutex
101104
102105 c .nc , _ , err = prepareHelper ("" , natsOpts ()... )
103106 if err != nil {
@@ -112,13 +115,27 @@ func (c *microCmd) serveAction(_ *fisk.ParseContext) error {
112115 "_nats.client.created.library" : "natscli" ,
113116 "_nats.client.created.version" : Version ,
114117 },
118+ StatsHandler : func (endpoint * micro.Endpoint ) any {
119+ mu .Lock ()
120+ defer mu .Unlock ()
121+
122+ return map [string ]any {
123+ "total_payload" : combinedPayload ,
124+ }
125+ },
115126 })
116127 if err != nil {
117128 return err
118129 }
119130
120131 grp := srv .AddGroup (c .name )
121- err = grp .AddEndpoint ("echo" , micro .HandlerFunc (c .echoHandler ))
132+ err = grp .AddEndpoint ("echo" , micro .HandlerFunc (func (request micro.Request ) {
133+ mu .Lock ()
134+ combinedPayload += len (request .Data ())
135+ mu .Unlock ()
136+
137+ c .echoHandler (request )
138+ }))
122139 if err != nil {
123140 return err
124141 }
@@ -403,7 +420,7 @@ func (c *microCmd) infoAction(_ *fisk.ParseContext) error {
403420 cols .Indent (2 )
404421
405422 cols .AddSectionTitle ("%s Endpoint Statistics" , e .Name )
406- cols .AddRowf ("Requests" , "%s in group %s " , f (e .NumRequests ), e .QueueGroup )
423+ cols .AddRowf ("Requests" , "%s in group %q " , f (e .NumRequests ), e .QueueGroup )
407424 cols .AddRowf ("Processing Time" , "%s (average %s)" , f (e .ProcessingTime ), f (e .AverageProcessingTime ))
408425 cols .AddRowf ("Started:" , "%s (%s ago)" , f (stats .Started ), f (time .Since (stats .Started )))
409426 cols .AddRow ("Errors" , e .NumErrors )
@@ -413,7 +430,7 @@ func (c *microCmd) infoAction(_ *fisk.ParseContext) error {
413430 cols .AddSectionTitle ("Endpoint Specific Statistics" )
414431 out := bytes .NewBuffer ([]byte {})
415432 json .Indent (out , e .Data , " " , " " )
416- cols .Println (" " + out .String ())
433+ cols .Println (" " + out .String ())
417434 }
418435
419436 cols .Indent (0 )
0 commit comments