erigon-pulse/cmd/observer/reports/status_report.go
battlmonstr 92db317e06
Observer - P2P network crawler (#3928)
Observer crawls the Ethereum network and collects information about the nodes.
2022-04-22 12:02:12 +01:00

41 lines
898 B
Go

package reports
import (
"context"
"fmt"
"github.com/ledgerwatch/erigon/cmd/observer/database"
"strings"
)
type StatusReport struct {
TotalCount uint
DistinctIPCount uint
}
func CreateStatusReport(ctx context.Context, db database.DB, maxPingTries uint, networkID uint) (*StatusReport, error) {
totalCount, err := db.CountNodes(ctx, maxPingTries, networkID)
if err != nil {
return nil, err
}
distinctIPCount, err := db.CountIPs(ctx, maxPingTries, networkID)
if err != nil {
return nil, err
}
report := StatusReport{
totalCount,
distinctIPCount,
}
return &report, nil
}
func (report *StatusReport) String() string {
var builder strings.Builder
builder.WriteString(fmt.Sprintf("total: %d", report.TotalCount))
builder.WriteRune('\n')
builder.WriteString(fmt.Sprintf("distinct IPs: %d", report.DistinctIPCount))
builder.WriteRune('\n')
return builder.String()
}