mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-16 19:14:41 -07:00
[ADDED] Monitoring: Routez's individual route has now more info
Added Start, LastActivity, Uptime and Idle that we normally have in a Connz for non route connections. This info can be useful to determine if a route is recent, etc.. Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
@@ -749,10 +749,14 @@ type RouteInfo struct {
|
||||
IsConfigured bool `json:"is_configured"`
|
||||
IP string `json:"ip"`
|
||||
Port int `json:"port"`
|
||||
Start time.Time `json:"start"`
|
||||
LastActivity time.Time `json:"last_activity"`
|
||||
RTT string `json:"rtt,omitempty"`
|
||||
Uptime string `json:"uptime"`
|
||||
Idle string `json:"idle"`
|
||||
Import *SubjectPermission `json:"import,omitempty"`
|
||||
Export *SubjectPermission `json:"export,omitempty"`
|
||||
Pending int `json:"pending_size"`
|
||||
RTT string `json:"rtt,omitempty"`
|
||||
InMsgs int64 `json:"in_msgs"`
|
||||
OutMsgs int64 `json:"out_msgs"`
|
||||
InBytes int64 `json:"in_bytes"`
|
||||
@@ -799,6 +803,10 @@ func (s *Server) Routez(routezOpts *RoutezOptions) (*Routez, error) {
|
||||
Import: r.opts.Import,
|
||||
Export: r.opts.Export,
|
||||
RTT: r.getRTT().String(),
|
||||
Start: r.start,
|
||||
LastActivity: r.last,
|
||||
Uptime: myUptime(rs.Now.Sub(r.start)),
|
||||
Idle: myUptime(rs.Now.Sub(r.last)),
|
||||
}
|
||||
|
||||
if len(r.subs) > 0 {
|
||||
|
||||
@@ -1313,6 +1313,7 @@ func TestConnzWithRoutes(t *testing.T) {
|
||||
routeURL, _ := url.Parse(fmt.Sprintf("nats-route://127.0.0.1:%d", s.ClusterAddr().Port))
|
||||
opts.Routes = []*url.URL{routeURL}
|
||||
|
||||
start := time.Now()
|
||||
sc := RunServer(opts)
|
||||
defer sc.Shutdown()
|
||||
|
||||
@@ -1324,10 +1325,10 @@ func TestConnzWithRoutes(t *testing.T) {
|
||||
// Test contents..
|
||||
// Make sure routes don't show up under connz, but do under routez
|
||||
if c.NumConns != 0 {
|
||||
t.Fatalf("Expected 0 connections, got %d\n", c.NumConns)
|
||||
t.Fatalf("Expected 0 connections, got %d", c.NumConns)
|
||||
}
|
||||
if c.Conns == nil || len(c.Conns) != 0 {
|
||||
t.Fatalf("Expected 0 connections in array, got %p\n", c.Conns)
|
||||
t.Fatalf("Expected 0 connections in array, got %p", c.Conns)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1345,17 +1346,32 @@ func TestConnzWithRoutes(t *testing.T) {
|
||||
rz := pollRoutez(t, s, mode, url+urlSuffix, &RoutezOptions{Subscriptions: subs == 1, SubscriptionsDetail: subs == 2})
|
||||
|
||||
if rz.NumRoutes != 1 {
|
||||
t.Fatalf("Expected 1 route, got %d\n", rz.NumRoutes)
|
||||
t.Fatalf("Expected 1 route, got %d", rz.NumRoutes)
|
||||
}
|
||||
|
||||
if len(rz.Routes) != 1 {
|
||||
t.Fatalf("Expected route array of 1, got %v\n", len(rz.Routes))
|
||||
t.Fatalf("Expected route array of 1, got %v", len(rz.Routes))
|
||||
}
|
||||
|
||||
route := rz.Routes[0]
|
||||
|
||||
if route.DidSolicit {
|
||||
t.Fatalf("Expected unsolicited route, got %v\n", route.DidSolicit)
|
||||
t.Fatalf("Expected unsolicited route, got %v", route.DidSolicit)
|
||||
}
|
||||
|
||||
if route.Start.IsZero() {
|
||||
t.Fatalf("Expected Start to be set, got %+v", route)
|
||||
} else if route.Start.Before(start) {
|
||||
t.Fatalf("Unexpected start time: route was started around %v, got %v", start, route.Start)
|
||||
}
|
||||
if route.LastActivity.IsZero() {
|
||||
t.Fatalf("Expected LastActivity to be set, got %+v", route)
|
||||
}
|
||||
if route.Uptime == _EMPTY_ {
|
||||
t.Fatalf("Expected Uptime to be set, it was not")
|
||||
}
|
||||
if route.Idle == _EMPTY_ {
|
||||
t.Fatalf("Expected Idle to be set, it was not")
|
||||
}
|
||||
|
||||
// Don't ask for subs, so there should not be any
|
||||
|
||||
@@ -1289,7 +1289,7 @@ func (s *Server) createRoute(conn net.Conn, rURL *url.URL) *client {
|
||||
}
|
||||
}
|
||||
|
||||
c := &client{srv: s, nc: conn, opts: ClientOpts{}, kind: ROUTER, msubs: -1, mpay: -1, route: r}
|
||||
c := &client{srv: s, nc: conn, opts: ClientOpts{}, kind: ROUTER, msubs: -1, mpay: -1, route: r, start: time.Now()}
|
||||
|
||||
// Grab server variables
|
||||
s.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user