mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
[misc] add additional metrics (#4028)
* add additional metrics we are collecting active rosenpass, ssh from the client side we are also collecting active user peers and active users * remove duplicated
This commit is contained in:
@@ -184,7 +184,9 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
ephemeralPeersSKs int
|
ephemeralPeersSKs int
|
||||||
ephemeralPeersSKUsage int
|
ephemeralPeersSKUsage int
|
||||||
activePeersLastDay int
|
activePeersLastDay int
|
||||||
|
activeUserPeersLastDay int
|
||||||
osPeers map[string]int
|
osPeers map[string]int
|
||||||
|
activeUsersLastDay map[string]struct{}
|
||||||
userPeers int
|
userPeers int
|
||||||
rules int
|
rules int
|
||||||
rulesProtocol map[string]int
|
rulesProtocol map[string]int
|
||||||
@@ -203,6 +205,7 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
version string
|
version string
|
||||||
peerActiveVersions []string
|
peerActiveVersions []string
|
||||||
osUIClients map[string]int
|
osUIClients map[string]int
|
||||||
|
rosenpassEnabled int
|
||||||
)
|
)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
metricsProperties := make(properties)
|
metricsProperties := make(properties)
|
||||||
@@ -210,6 +213,7 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
osUIClients = make(map[string]int)
|
osUIClients = make(map[string]int)
|
||||||
rulesProtocol = make(map[string]int)
|
rulesProtocol = make(map[string]int)
|
||||||
rulesDirection = make(map[string]int)
|
rulesDirection = make(map[string]int)
|
||||||
|
activeUsersLastDay = make(map[string]struct{})
|
||||||
uptime = time.Since(w.startupTime).Seconds()
|
uptime = time.Since(w.startupTime).Seconds()
|
||||||
connections := w.connManager.GetAllConnectedPeers()
|
connections := w.connManager.GetAllConnectedPeers()
|
||||||
version = nbversion.NetbirdVersion()
|
version = nbversion.NetbirdVersion()
|
||||||
@@ -277,10 +281,14 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
for _, peer := range account.Peers {
|
for _, peer := range account.Peers {
|
||||||
peers++
|
peers++
|
||||||
|
|
||||||
if peer.SSHEnabled {
|
if peer.SSHEnabled || peer.Meta.Flags.ServerSSHAllowed {
|
||||||
peersSSHEnabled++
|
peersSSHEnabled++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if peer.Meta.Flags.RosenpassEnabled {
|
||||||
|
rosenpassEnabled++
|
||||||
|
}
|
||||||
|
|
||||||
if peer.UserID != "" {
|
if peer.UserID != "" {
|
||||||
userPeers++
|
userPeers++
|
||||||
}
|
}
|
||||||
@@ -299,6 +307,10 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
_, connected := connections[peer.ID]
|
_, connected := connections[peer.ID]
|
||||||
if connected || peer.Status.LastSeen.After(w.lastRun) {
|
if connected || peer.Status.LastSeen.After(w.lastRun) {
|
||||||
activePeersLastDay++
|
activePeersLastDay++
|
||||||
|
if peer.UserID != "" {
|
||||||
|
activeUserPeersLastDay++
|
||||||
|
activeUsersLastDay[peer.UserID] = struct{}{}
|
||||||
|
}
|
||||||
osActiveKey := osKey + "_active"
|
osActiveKey := osKey + "_active"
|
||||||
osActiveCount := osPeers[osActiveKey]
|
osActiveCount := osPeers[osActiveKey]
|
||||||
osPeers[osActiveKey] = osActiveCount + 1
|
osPeers[osActiveKey] = osActiveCount + 1
|
||||||
@@ -320,6 +332,8 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
metricsProperties["ephemeral_peers_setup_keys"] = ephemeralPeersSKs
|
metricsProperties["ephemeral_peers_setup_keys"] = ephemeralPeersSKs
|
||||||
metricsProperties["ephemeral_peers_setup_keys_usage"] = ephemeralPeersSKUsage
|
metricsProperties["ephemeral_peers_setup_keys_usage"] = ephemeralPeersSKUsage
|
||||||
metricsProperties["active_peers_last_day"] = activePeersLastDay
|
metricsProperties["active_peers_last_day"] = activePeersLastDay
|
||||||
|
metricsProperties["active_user_peers_last_day"] = activeUserPeersLastDay
|
||||||
|
metricsProperties["active_users_last_day"] = len(activeUsersLastDay)
|
||||||
metricsProperties["user_peers"] = userPeers
|
metricsProperties["user_peers"] = userPeers
|
||||||
metricsProperties["rules"] = rules
|
metricsProperties["rules"] = rules
|
||||||
metricsProperties["rules_with_src_posture_checks"] = rulesWithSrcPostureChecks
|
metricsProperties["rules_with_src_posture_checks"] = rulesWithSrcPostureChecks
|
||||||
@@ -338,6 +352,7 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
metricsProperties["ui_clients"] = uiClient
|
metricsProperties["ui_clients"] = uiClient
|
||||||
metricsProperties["idp_manager"] = w.idpManager
|
metricsProperties["idp_manager"] = w.idpManager
|
||||||
metricsProperties["store_engine"] = w.dataSource.GetStoreEngine()
|
metricsProperties["store_engine"] = w.dataSource.GetStoreEngine()
|
||||||
|
metricsProperties["rosenpass_enabled"] = rosenpassEnabled
|
||||||
|
|
||||||
for protocol, count := range rulesProtocol {
|
for protocol, count := range rulesProtocol {
|
||||||
metricsProperties["rules_protocol_"+protocol] = count
|
metricsProperties["rules_protocol_"+protocol] = count
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
|||||||
"1": {
|
"1": {
|
||||||
ID: "1",
|
ID: "1",
|
||||||
UserID: "test",
|
UserID: "test",
|
||||||
SSHEnabled: true,
|
SSHEnabled: false,
|
||||||
Meta: nbpeer.PeerSystemMeta{GoOS: "linux", WtVersion: "0.0.1"},
|
Meta: nbpeer.PeerSystemMeta{GoOS: "linux", WtVersion: "0.0.1", Flags: nbpeer.Flags{ServerSSHAllowed: true, RosenpassEnabled: true}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Policies: []*types.Policy{
|
Policies: []*types.Policy{
|
||||||
@@ -312,7 +312,19 @@ func TestGenerateProperties(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if properties["posture_checks"] != 2 {
|
if properties["posture_checks"] != 2 {
|
||||||
t.Errorf("expected 1 posture_checks, got %d", properties["posture_checks"])
|
t.Errorf("expected 2 posture_checks, got %d", properties["posture_checks"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if properties["rosenpass_enabled"] != 1 {
|
||||||
|
t.Errorf("expected 1 rosenpass_enabled, got %d", properties["rosenpass_enabled"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if properties["active_user_peers_last_day"] != 2 {
|
||||||
|
t.Errorf("expected 2 active_user_peers_last_day, got %d", properties["active_user_peers_last_day"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if properties["active_users_last_day"] != 1 {
|
||||||
|
t.Errorf("expected 1 active_users_last_day, got %d", properties["active_users_last_day"])
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user