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

chore: golines #189

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ clean:
format: tidy
go fmt ./...

golines:
golines -w --ignore-generated --chain-split-dots --max-len=80 --reformat-tags .

test: tidy
go test -v -race ./...

Expand Down
165 changes: 123 additions & 42 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ func main() {
resourceTextView.SetText(resourceText).SetTitle("Resources").SetBorder(true)

connectionText = getConnectionText(ctx)
connectionTextView.SetText(connectionText).SetTitle("Connections").SetBorder(true)
connectionTextView.SetText(connectionText).
SetTitle("Connections").
SetBorder(true)

coreText = getCoreText(ctx)
coreTextView.SetText(coreText).SetTitle("Core").SetBorder(true)
Expand All @@ -236,7 +238,9 @@ func main() {
chainTextView.SetText(chainText).SetTitle("Chain").SetBorder(true)

blockText = getBlockText(ctx)
blockTextView.SetText(blockText).SetTitle("Block Propagation").SetBorder(true)
blockTextView.SetText(blockText).
SetTitle("Block Propagation").
SetBorder(true)

peerText = getPeerText(ctx)
peerTextView.SetText(peerText).SetTitle("Peers").SetBorder(true)
Expand All @@ -255,6 +259,7 @@ func main() {
1,
1,
false).

// Row 2 is our main text section, and its own flex
AddItem(layout.
AddItem(leftSide.SetDirection(tview.FlexRow).
Expand Down Expand Up @@ -345,7 +350,11 @@ func main() {
coreTextView.Clear()
coreTextView.SetText(coreText)
}
tmpText = fmt.Sprintf("%s\n%s", getEpochText(ctx), getChainText(ctx))
tmpText = fmt.Sprintf(
"%s\n%s",
getEpochText(ctx),
getChainText(ctx),
)
if tmpText != "" && tmpText != chainText {
chainText = tmpText
chainTextView.Clear()
Expand Down Expand Up @@ -423,7 +432,11 @@ func main() {
coreTextView.Clear()
coreTextView.SetText(coreText)
}
tmpText = fmt.Sprintf("%s\n%s", getEpochText(ctx), getChainText(ctx))
tmpText = fmt.Sprintf(
"%s\n%s",
getEpochText(ctx),
getChainText(ctx),
)
if tmpText != "" && tmpText != chainText {
chainText = tmpText
chainTextView.Clear()
Expand Down Expand Up @@ -797,29 +810,49 @@ func getBlockText(ctx context.Context) string {
delay := fmt.Sprintf("%.2f", promMetrics.BlockDelay)

// Row 1
sb.WriteString(fmt.Sprintf(" [green]Last Delay : [white]%s[blue]%-"+strconv.Itoa(10-len(delay))+"s",
delay,
"s",
))
sb.WriteString(fmt.Sprintf(" [green]Served : [white]%-"+strconv.Itoa(10)+"s",
strconv.FormatUint(promMetrics.BlocksServed, 10),
))
sb.WriteString(fmt.Sprintf(" [green]Late (>5s) : [white]%-"+strconv.Itoa(10)+"s\n",
strconv.FormatUint(promMetrics.BlocksLate, 10),
))
sb.WriteString(
fmt.Sprintf(
" [green]Last Delay : [white]%s[blue]%-"+strconv.Itoa(
10-len(delay),
)+"s",
delay,
"s",
),
)
sb.WriteString(
fmt.Sprintf(" [green]Served : [white]%-"+strconv.Itoa(10)+"s",
strconv.FormatUint(promMetrics.BlocksServed, 10),
),
)
sb.WriteString(
fmt.Sprintf(" [green]Late (>5s) : [white]%-"+strconv.Itoa(10)+"s\n",
strconv.FormatUint(promMetrics.BlocksLate, 10),
),
)
// Row 2
sb.WriteString(fmt.Sprintf(" [green]Within 1s : [white]%s%-"+strconv.Itoa(10-len(blk1s))+"s",
blk1s,
"%",
))
sb.WriteString(fmt.Sprintf(" [green]Within 3s : [white]%s%-"+strconv.Itoa(10-len(blk3s))+"s",
blk3s,
"%",
))
sb.WriteString(fmt.Sprintf(" [green]Within 5s : [white]%s%-"+strconv.Itoa(10-len(blk5s))+"s\n",
blk5s,
"%",
))
sb.WriteString(
fmt.Sprintf(
" [green]Within 1s : [white]%s%-"+strconv.Itoa(10-len(blk1s))+"s",
blk1s,
"%",
),
)
sb.WriteString(
fmt.Sprintf(
" [green]Within 3s : [white]%s%-"+strconv.Itoa(10-len(blk3s))+"s",
blk3s,
"%",
),
)
sb.WriteString(
fmt.Sprintf(
" [green]Within 5s : [white]%s%-"+strconv.Itoa(
10-len(blk5s),
)+"s\n",
blk5s,
"%",
),
)

failCount = 0
return fmt.Sprint(sb.String())
Expand All @@ -835,14 +868,23 @@ func getNodeText(ctx context.Context) string {
}
nodeVersion, nodeRevision, _ := getNodeVersion()
var sb strings.Builder
sb.WriteString(fmt.Sprintf(" [green]Name : [white]%s\n", cfg.App.NodeName))
sb.WriteString(
fmt.Sprintf(" [green]Name : [white]%s\n", cfg.App.NodeName),
)
sb.WriteString(fmt.Sprintf(" [green]Role : [white]%s\n", role))
sb.WriteString(fmt.Sprintf(" [green]Network : [white]%s\n", network))
sb.WriteString(fmt.Sprintf(" [green]Version : [white]%s\n",
fmt.Sprintf("[white]%s[blue] [[white]%s[blue]]", nodeVersion, nodeRevision),
sb.WriteString(fmt.Sprintf(
" [green]Version : [white]%s\n",
fmt.Sprintf(
"[white]%s[blue] [[white]%s[blue]]",
nodeVersion,
nodeRevision,
),
))
if publicIP != nil {
sb.WriteString(fmt.Sprintf(" [green]Public IP : [white]%s\n", publicIP))
sb.WriteString(
fmt.Sprintf(" [green]Public IP : [white]%s\n", publicIP),
)
} else {
sb.WriteString(fmt.Sprintln())
}
Expand Down Expand Up @@ -960,15 +1002,25 @@ func getPeerText(ctx context.Context) string {
// Divider
sb.WriteString(fmt.Sprintf("%s\n", strings.Repeat("-", width-1)))

sb.WriteString(fmt.Sprintf(" [green]Total / Undetermined : [white]%d[white] / ", peerCount))
sb.WriteString(
fmt.Sprintf(
" [green]Total / Undetermined : [white]%d[white] / ",
peerCount,
),
)
if peerStats.CNT0 == 0 {
sb.WriteString("[blue]0[white]")
} else {
sb.WriteString(fmt.Sprintf("[fuchsia]%d[white]", peerStats.CNT0))
}
// TODO: figure out spacing here
if peerStats.RTTAVG >= 200 {
sb.WriteString(fmt.Sprintf(" Average RTT : [fuchsia]%d[white] ms\n", peerStats.RTTAVG))
sb.WriteString(
fmt.Sprintf(
" Average RTT : [fuchsia]%d[white] ms\n",
peerStats.RTTAVG,
),
)
} else if peerStats.RTTAVG >= 100 {
sb.WriteString(fmt.Sprintf(" Average RTT : [red]%d[white] ms\n", peerStats.RTTAVG))
} else if peerStats.RTTAVG >= 50 {
Expand All @@ -982,7 +1034,9 @@ func getPeerText(ctx context.Context) string {
// Divider
sb.WriteString(fmt.Sprintf("%s\n", strings.Repeat("-", width-1)))

sb.WriteString(fmt.Sprintf(" [green]# %24s I/O RTT Geolocation\n", "REMOTE PEER"))
sb.WriteString(
fmt.Sprintf(" [green]# %24s I/O RTT Geolocation\n", "REMOTE PEER"),
)
// peerLocationWidth := width - 41
for peerNbr, peer := range peerStats.RTTresultsSlice {
peerNbr++
Expand Down Expand Up @@ -1065,15 +1119,42 @@ func getResourceText(ctx context.Context) string {
}

memRss := fmt.Sprintf("%.1f", float64(rss)/float64(1073741824))
memLive := fmt.Sprintf("%.1f", float64(promMetrics.MemLive)/float64(1073741824))
memHeap := fmt.Sprintf("%.1f", float64(promMetrics.MemHeap)/float64(1073741824))

sb.WriteString(fmt.Sprintf(" [green]CPU (sys) : [white]%s%%\n", fmt.Sprintf("%.2f", cpuPercent)))
sb.WriteString(fmt.Sprintf(" [green]Mem (Live) : [white]%s[blue]G\n", memLive))
sb.WriteString(fmt.Sprintf(" [green]Mem (RSS) : [white]%s[blue]G\n", memRss))
sb.WriteString(fmt.Sprintf(" [green]Mem (Heap) : [white]%s[blue]G\n", memHeap))
sb.WriteString(fmt.Sprintf(" [green]GC Minor : [white]%s\n", strconv.FormatUint(promMetrics.GcMinor, 10)))
sb.WriteString(fmt.Sprintf(" [green]GC Major : [white]%s\n", strconv.FormatUint(promMetrics.GcMajor, 10)))
memLive := fmt.Sprintf(
"%.1f",
float64(promMetrics.MemLive)/float64(1073741824),
)
memHeap := fmt.Sprintf(
"%.1f",
float64(promMetrics.MemHeap)/float64(1073741824),
)

sb.WriteString(
fmt.Sprintf(
" [green]CPU (sys) : [white]%s%%\n",
fmt.Sprintf("%.2f", cpuPercent),
),
)
sb.WriteString(
fmt.Sprintf(" [green]Mem (Live) : [white]%s[blue]G\n", memLive),
)
sb.WriteString(
fmt.Sprintf(" [green]Mem (RSS) : [white]%s[blue]G\n", memRss),
)
sb.WriteString(
fmt.Sprintf(" [green]Mem (Heap) : [white]%s[blue]G\n", memHeap),
)
sb.WriteString(
fmt.Sprintf(
" [green]GC Minor : [white]%s\n",
strconv.FormatUint(promMetrics.GcMinor, 10),
),
)
sb.WriteString(
fmt.Sprintf(
" [green]GC Major : [white]%s\n",
strconv.FormatUint(promMetrics.GcMajor, 10),
),
)
return fmt.Sprint(sb.String())
}

Expand Down
3 changes: 2 additions & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func getP2P(ctx context.Context, processMetrics *process.Process) bool {
}
cmd, err := processMetrics.CmdlineWithContext(ctx)
if err == nil {
if !strings.Contains(cmd, "p2p") && strings.Contains(cmd, "--config") {
if !strings.Contains(cmd, "p2p") &&
strings.Contains(cmd, "--config") {
cmdArray := strings.Split(cmd, " ")
for p, arg := range cmdArray {
if arg == "--config" {
Expand Down
41 changes: 33 additions & 8 deletions peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var scrollPeers bool = false

func filterPeers(ctx context.Context) error {
var peers []string
if len(peerStats.RTTresultsSlice) != 0 && len(peerStats.RTTresultsSlice) == len(peersFiltered) {
if len(peerStats.RTTresultsSlice) != 0 &&
len(peerStats.RTTresultsSlice) == len(peersFiltered) {
return nil
}
if processMetrics == nil {
Expand All @@ -44,7 +45,11 @@ func filterPeers(ctx context.Context) error {
cfg := config.GetConfig()

// Get process in/out connections
connections, err := netutil.ConnectionsPidWithContext(ctx, "tcp", processMetrics.Pid)
connections, err := netutil.ConnectionsPidWithContext(
ctx,
"tcp",
processMetrics.Pid,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -219,24 +224,44 @@ func pingPeers(ctx context.Context) error {
UpdatedAt: time.Now(),
}
peerStats.RTTresultsMap[peerIP] = peer
peerStats.RTTresultsSlice = append(peerStats.RTTresultsSlice, peer)
peerStats.RTTresultsSlice = append(
peerStats.RTTresultsSlice,
peer,
)
sort.Sort(peerStats.RTTresultsSlice)
}()
wg.Wait()
}
peerCNTreachable := peerCount - peerStats.CNT0
if peerCNTreachable > 0 {
peerStats.RTTAVG = peerStats.RTTSUM / peerCNTreachable
peerStats.PCT1 = float32(peerStats.CNT1) / float32(peerCNTreachable) * 100
peerStats.PCT1 = float32(
peerStats.CNT1,
) / float32(
peerCNTreachable,
) * 100
peerStats.PCT1items = int(peerStats.PCT1) * granularitySmall / 100
peerStats.PCT2 = float32(peerStats.CNT2) / float32(peerCNTreachable) * 100
peerStats.PCT2 = float32(
peerStats.CNT2,
) / float32(
peerCNTreachable,
) * 100
peerStats.PCT2items = int(peerStats.PCT2) * granularitySmall / 100
peerStats.PCT3 = float32(peerStats.CNT3) / float32(peerCNTreachable) * 100
peerStats.PCT3 = float32(
peerStats.CNT3,
) / float32(
peerCNTreachable,
) * 100
peerStats.PCT3items = int(peerStats.PCT3) * granularitySmall / 100
peerStats.PCT4 = float32(peerStats.CNT4) / float32(peerCNTreachable) * 100
peerStats.PCT4 = float32(
peerStats.CNT4,
) / float32(
peerCNTreachable,
) * 100
peerStats.PCT4items = int(peerStats.PCT4) * granularitySmall / 100
}
if len(peerStats.RTTresultsSlice) != 0 && len(peerStats.RTTresultsSlice) >= peerCount {
if len(peerStats.RTTresultsSlice) != 0 &&
len(peerStats.RTTresultsSlice) >= peerCount {
checkPeers = false
scrollPeers = true
}
Expand Down
6 changes: 5 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ func getGeoIP(ctx context.Context, address string) string {
return fmt.Sprintf("%v", record.Country.IsoCode)
}
}
return fmt.Sprintf("%v, %v", record.City.Names["en"], record.Country.IsoCode)
return fmt.Sprintf(
"%v, %v",
record.City.Names["en"],
record.Country.IsoCode,
)
}