mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-02 11:29:46 +01:00
[management] add selfhosted metrics for networks (#3118)
This commit is contained in:
parent
1a623943c8
commit
18316be09a
2
.github/workflows/golangci-lint.yml
vendored
2
.github/workflows/golangci-lint.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: codespell
|
- name: codespell
|
||||||
uses: codespell-project/actions-codespell@v2
|
uses: codespell-project/actions-codespell@v2
|
||||||
with:
|
with:
|
||||||
ignore_words_list: erro,clienta,hastable,iif,groupd
|
ignore_words_list: erro,clienta,hastable,iif,groupd,testin
|
||||||
skip: go.mod,go.sum
|
skip: go.mod,go.sum
|
||||||
only_warn: 1
|
only_warn: 1
|
||||||
golangci:
|
golangci:
|
||||||
|
@ -195,6 +195,10 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
groups int
|
groups int
|
||||||
routes int
|
routes int
|
||||||
routesWithRGGroups int
|
routesWithRGGroups int
|
||||||
|
networks int
|
||||||
|
networkResources int
|
||||||
|
networkRouters int
|
||||||
|
networkRoutersWithPG int
|
||||||
nameservers int
|
nameservers int
|
||||||
uiClient int
|
uiClient int
|
||||||
version string
|
version string
|
||||||
@ -219,6 +223,16 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
groups += len(account.Groups)
|
groups += len(account.Groups)
|
||||||
|
networks += len(account.Networks)
|
||||||
|
networkResources += len(account.NetworkResources)
|
||||||
|
|
||||||
|
networkRouters += len(account.NetworkRouters)
|
||||||
|
for _, router := range account.NetworkRouters {
|
||||||
|
if len(router.PeerGroups) > 0 {
|
||||||
|
networkRoutersWithPG++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
routes += len(account.Routes)
|
routes += len(account.Routes)
|
||||||
for _, route := range account.Routes {
|
for _, route := range account.Routes {
|
||||||
if len(route.PeerGroups) > 0 {
|
if len(route.PeerGroups) > 0 {
|
||||||
@ -312,6 +326,10 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
metricsProperties["rules_with_src_posture_checks"] = rulesWithSrcPostureChecks
|
metricsProperties["rules_with_src_posture_checks"] = rulesWithSrcPostureChecks
|
||||||
metricsProperties["posture_checks"] = postureChecks
|
metricsProperties["posture_checks"] = postureChecks
|
||||||
metricsProperties["groups"] = groups
|
metricsProperties["groups"] = groups
|
||||||
|
metricsProperties["networks"] = networks
|
||||||
|
metricsProperties["network_resources"] = networkResources
|
||||||
|
metricsProperties["network_routers"] = networkRouters
|
||||||
|
metricsProperties["network_routers_with_groups"] = networkRoutersWithPG
|
||||||
metricsProperties["routes"] = routes
|
metricsProperties["routes"] = routes
|
||||||
metricsProperties["routes_with_routing_groups"] = routesWithRGGroups
|
metricsProperties["routes_with_routing_groups"] = routesWithRGGroups
|
||||||
metricsProperties["nameservers"] = nameservers
|
metricsProperties["nameservers"] = nameservers
|
||||||
|
@ -5,6 +5,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
|
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
||||||
|
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
||||||
|
networkTypes "github.com/netbirdio/netbird/management/server/networks/types"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
"github.com/netbirdio/netbird/management/server/posture"
|
"github.com/netbirdio/netbird/management/server/posture"
|
||||||
"github.com/netbirdio/netbird/management/server/store"
|
"github.com/netbirdio/netbird/management/server/store"
|
||||||
@ -172,6 +175,31 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Networks: []*networkTypes.Network{
|
||||||
|
{
|
||||||
|
ID: "1",
|
||||||
|
AccountID: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NetworkResources: []*resourceTypes.NetworkResource{
|
||||||
|
{
|
||||||
|
ID: "1",
|
||||||
|
AccountID: "1",
|
||||||
|
NetworkID: "1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: "2",
|
||||||
|
AccountID: "1",
|
||||||
|
NetworkID: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NetworkRouters: []*routerTypes.NetworkRouter{
|
||||||
|
{
|
||||||
|
ID: "1",
|
||||||
|
AccountID: "1",
|
||||||
|
NetworkID: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,6 +228,15 @@ func TestGenerateProperties(t *testing.T) {
|
|||||||
if properties["routes"] != 2 {
|
if properties["routes"] != 2 {
|
||||||
t.Errorf("expected 2 routes, got %d", properties["routes"])
|
t.Errorf("expected 2 routes, got %d", properties["routes"])
|
||||||
}
|
}
|
||||||
|
if properties["networks"] != 1 {
|
||||||
|
t.Errorf("expected 1 networks, got %d", properties["networks"])
|
||||||
|
}
|
||||||
|
if properties["network_resources"] != 2 {
|
||||||
|
t.Errorf("expected 2 network_resources, got %d", properties["network_resources"])
|
||||||
|
}
|
||||||
|
if properties["network_routers"] != 1 {
|
||||||
|
t.Errorf("expected 1 network_routers, got %d", properties["network_routers"])
|
||||||
|
}
|
||||||
if properties["rules"] != 4 {
|
if properties["rules"] != 4 {
|
||||||
t.Errorf("expected 4 rules, got %d", properties["rules"])
|
t.Errorf("expected 4 rules, got %d", properties["rules"])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user