Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds modulation for node stats reporting and fixes dirSize variabilit… #11

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions quaistats/quaistats.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@

urlMap := make(map[string][]string)
var nodeStatsWarningCounter int
nodeStatsMod := 0

for key, path := range paths {
// url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779)
Expand Down Expand Up @@ -354,7 +355,6 @@
errTimer.Reset(0)
continue
}

}

// Keep sending status updates until the connection breaks
Expand All @@ -374,7 +374,8 @@
return

case <-fullReport.C:
if err = s.report("nodeStats", conns["nodeStats"]); err != nil {
nodeStatsMod ^= 1
if err = s.reportNodeStats(conns["nodeStats"], nodeStatsMod); err != nil {
noErrs = false
nodeStatsWarningCounter += 1
if nodeStatsWarningCounter == c_nodeStatsWarningThreshold {
Expand Down Expand Up @@ -404,12 +405,6 @@
log.Warn("Block internal stats report failed", "err", err)
}
}
case sideEvent := <-sideCh:
if err = s.reportSideBlock(conns["block"], sideEvent); err != nil {
noErrs = false
log.Warn("Block stats report failed", "err", err)
}
}
}
fullReport.Stop()
// Close the current connection and establish a new one
Expand All @@ -426,7 +421,7 @@
// from the network socket. If any of them match an active request, it forwards
// it, if they themselves are requests it initiates a reply, and lastly it drops
// unknown packets.
func (s *Service) readLoop(conn *connWrapper) {

Check failure on line 424 in quaistats/quaistats.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected { at end of statement
// If the read loop exits, close the connection
defer conn.Close()

Expand Down Expand Up @@ -615,7 +610,7 @@

switch dataType {
case "nodeStats":
if err := s.reportNodeStats(conn); err != nil {
if err := s.reportNodeStats(conn, 0); err != nil {
return err
}
default:
Expand Down Expand Up @@ -765,6 +760,7 @@
CurrentBlockNumber []*big.Int `json:"currentBlockNumber"`
RegionLocation int `json:"regionLocation"`
ZoneLocation int `json:"zoneLocation"`
NodeStatsMod int `json:"nodeStatsMod"`
}

type totalTransactions struct {
Expand Down Expand Up @@ -930,7 +926,11 @@

// reportNodeStats retrieves various stats about the node at the networking and
// mining layer and reports it to the stats server.
func (s *Service) reportNodeStats(conn *connWrapper) error {
func (s *Service) reportNodeStats(conn *connWrapper, mod int) error {
if conn == nil || conn.conn == nil {
log.Warn("node stats connection is nil")
return errors.New("node stats connection is nil")
}
// Get RAM usage
var ramUsagePercent, ramFreePercent, ramAvailablePercent, ramUsage float64
if vmStat, err := mem.VirtualMemory(); err == nil {
Expand Down Expand Up @@ -997,6 +997,7 @@
CurrentBlockNumber: currentBlockHeight,
RegionLocation: location.Region(),
ZoneLocation: location.Zone(),
NodeStatsMod: mod,
},
}

Expand All @@ -1008,6 +1009,14 @@

// dirSize returns the size of a directory in bytes.
func dirSize(path string) (int64, error) {
containsRegion := strings.Contains(path, "region")
containsPrime := strings.Contains(path, "prime")

if containsRegion || containsPrime {
log.Debug("Skipping dirSize for region or prime. Filtered out on backend")
return -1, nil
}

var cmd *exec.Cmd
if runtime.GOOS == "darwin" {
cmd = exec.Command("du", "-sk", path)
Expand Down
Loading