mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
001442e75e
* Send relays and internet gws count to amb
* Unify usage funcs in logic pkg
* Fix ee build
* Revert "Unify usage funcs in logic pkg"
This reverts commit 28afc91f7e
.
* Add more resource metrics on getUsage handler
* Use pro module's function to get server usage on lic val
* Move GetRelays to pro package
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
//go:build ee
|
|
// +build ee
|
|
|
|
package pro
|
|
|
|
import (
|
|
"encoding/base64"
|
|
|
|
"github.com/gravitl/netmaker/logic"
|
|
)
|
|
|
|
// base64encode - base64 encode helper function
|
|
func base64encode(input []byte) string {
|
|
return base64.StdEncoding.EncodeToString(input)
|
|
}
|
|
|
|
// base64decode - base64 decode helper function
|
|
func base64decode(input string) []byte {
|
|
bytes, err := base64.StdEncoding.DecodeString(input)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
return bytes
|
|
}
|
|
|
|
func getCurrentServerUsage() (limits Usage) {
|
|
limits.SetDefaults()
|
|
hosts, hErr := logic.GetAllHosts()
|
|
if hErr == nil {
|
|
limits.Hosts = len(hosts)
|
|
}
|
|
clients, cErr := logic.GetAllExtClients()
|
|
if cErr == nil {
|
|
limits.Clients = len(clients)
|
|
}
|
|
users, err := logic.GetUsers()
|
|
if err == nil {
|
|
limits.Users = len(users)
|
|
}
|
|
networks, err := logic.GetNetworks()
|
|
if err == nil {
|
|
limits.Networks = len(networks)
|
|
}
|
|
// TODO this part bellow can be optimized to get nodes just once
|
|
ingresses, err := logic.GetAllIngresses()
|
|
if err == nil {
|
|
limits.Ingresses = len(ingresses)
|
|
}
|
|
egresses, err := logic.GetAllEgresses()
|
|
if err == nil {
|
|
limits.Egresses = len(egresses)
|
|
}
|
|
relays, err := logic.GetRelays()
|
|
if err == nil {
|
|
limits.Relays = len(relays)
|
|
}
|
|
gateways, err := logic.GetInternetGateways()
|
|
if err == nil {
|
|
limits.InternetGateways = len(gateways)
|
|
}
|
|
return
|
|
}
|