github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/edge/edge_stats.go (about)

     1  package edge
     2  
     3  import (
     4  	"github.com/ronaksoft/rony"
     5  )
     6  
     7  /*
     8     Creation Time: 2020 - Mar - 06
     9     Created by:  (ehsan)
    10     Maintainers:
    11        1.  Ehsan N. Moosa (E2)
    12     Auditor: Ehsan N. Moosa (E2)
    13     Copyright Ronak Software Group 2020
    14  */
    15  
    16  // Stats exports some internal metrics data
    17  type Stats struct {
    18  	Address         string
    19  	ReplicaSet      uint64
    20  	Members         int
    21  	MembershipScore int
    22  	TunnelAddr      []string
    23  	GatewayProtocol rony.GatewayProtocol
    24  	GatewayAddr     []string
    25  }
    26  
    27  // Stats exports some internal metrics data packed in 'Stats' struct
    28  func (edge *Server) Stats() Stats {
    29  	s := Stats{}
    30  
    31  	if edge.gateway != nil {
    32  		s.GatewayAddr = edge.gateway.Addr()
    33  		s.GatewayProtocol = edge.gateway.Protocol()
    34  	}
    35  
    36  	if edge.tunnel != nil {
    37  		s.TunnelAddr = edge.tunnel.Addr()
    38  	}
    39  
    40  	if edge.cluster != nil {
    41  		s.ReplicaSet = edge.cluster.ReplicaSet()
    42  		s.Address = edge.cluster.Addr()
    43  		s.Members = len(edge.cluster.Members())
    44  	}
    45  
    46  	return s
    47  }