diff --git a/pkg/primitives/statistics.go b/pkg/primitives/statistics.go index 41aa534bd..ed9a64255 100644 --- a/pkg/primitives/statistics.go +++ b/pkg/primitives/statistics.go @@ -4,6 +4,9 @@ import ( "context" "encoding/json" "fmt" + "os/exec" + "strconv" + "strings" "time" "github.com/pkg/errors" @@ -31,9 +34,7 @@ func GetCapacity(ctx context.Context) gridtypes.Capacity { return val.(gridtypes.Capacity) } -var ( - _ provision.Provisioner = (*Statistics)(nil) -) +var _ provision.Provisioner = (*Statistics)(nil) type Reserved func() (gridtypes.Capacity, error) @@ -146,7 +147,6 @@ func (s *Statistics) hasEnoughCapacity(wl *gridtypes.WorkloadWithID) (gridtypes. id, _ := gridtypes.NewWorkloadID(dl_.TwinID, dl_.ContractID, wl_.Name) return id == wl.ID }) - if err != nil { return used, errors.Wrap(err, "failed to get available memory") } @@ -155,7 +155,7 @@ func (s *Statistics) hasEnoughCapacity(wl *gridtypes.WorkloadWithID) (gridtypes. return used, fmt.Errorf("cannot fulfil required memory size %d bytes out of usable %d bytes", required.MRU, usable) } - //check other resources as well? + // check other resources as well? return used, nil } @@ -253,10 +253,16 @@ func (s *statsStream) GetCounters() (pkg.Counters, error) { if err != nil { return pkg.Counters{}, err } + + conn, err := s.openConnectionsCount() + if err != nil { + return pkg.Counters{}, err + } return pkg.Counters{ - Total: s.stats.Total(), - Used: activeCounters.cap, - System: reserved, + Total: s.stats.Total(), + Used: activeCounters.cap, + System: reserved, + OpenConnecions: conn, Users: pkg.UsersCounters{ Deployments: activeCounters.deployments, Workloads: activeCounters.workloads, @@ -298,10 +304,6 @@ func (s *statsStream) ListGPUs() ([]pkg.GPUInfo, error) { return nil, errors.Wrap(err, "failed to list available devices") } - if err != nil { - return nil, errors.Wrap(err, "failed to list active deployments") - } - used, err := usedGpus() if err != nil { return nil, errors.Wrap(err, "failed to list used gpus") @@ -332,3 +334,12 @@ func (s *statsStream) ListGPUs() ([]pkg.GPUInfo, error) { return list, nil } + +func (s *statsStream) openConnectionsCount() (int, error) { + cmd := exec.Command("/bin/sh", "-c", "ss -ptn state established | wc -l") + out, err := cmd.Output() + if err != nil { + return 0, err + } + return strconv.Atoi(strings.TrimSpace(string(out))) +} diff --git a/pkg/provision.go b/pkg/provision.go index c0d2ee898..22090e91c 100644 --- a/pkg/provision.go +++ b/pkg/provision.go @@ -40,6 +40,8 @@ type Counters struct { System gridtypes.Capacity `json:"system"` // Users statistics by zos Users UsersCounters `json:"users"` + // OpenConnecions number of open connections in the node + OpenConnecions int `json:"open_connections"` } // UsersCounters the expected counters for deployments and workloads