Skip to content

Commit

Permalink
Merge pull request #265 from vegaprotocol/264-add-eventrate-final-report
Browse files Browse the repository at this point in the history
Add final report to eventrate
  • Loading branch information
ValentinTrinque authored Feb 17, 2023
2 parents 5a50fd2 + 67c7025 commit 484f7ed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- [254](https://github.com/vegaprotocol/vegatools/issues/254) - Updated auth to use VWT header value
- [256](https://github.com/vegaprotocol/vegatools/issues/256) - Fix batch orders
- [260](https://github.com/vegaprotocol/vegatools/issues/260) - Better handling of staking assets in perftool
- [264](https://github.com/vegaprotocol/vegatools/issues/264) - Eventrate tool can now output a simple report and then exit for use in scripts

### 🐛 Fixes
- [78](https://github.com/vegaprotocol/vegatools/pull/78) - Fix build with missing dependency
Expand Down
1 change: 1 addition & 0 deletions cmd/eventrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
eventRateCmd.Flags().IntVarP(&eventRateOpts.Buckets, "buckets", "b", 10, "number of historic buckets")
eventRateCmd.Flags().IntVarP(&eventRateOpts.SecondsPerBucket, "secondsperbucket", "s", 1, "number of seconds to record each bucket")
eventRateCmd.Flags().IntVarP(&eventRateOpts.EventCountDump, "eventcountdump", "e", 0, "dump total event count every x seconds")
eventRateCmd.Flags().IntVarP(&eventRateOpts.FinalReportRowCount, "finalreport", "f", 0, "generate a report after x number of calculations")
eventRateCmd.Flags().BoolVarP(&eventRateOpts.ReportStyle, "reportstyle", "r", false, "print output on a new line")
eventRateCmd.MarkFlagRequired("address")
}
Expand Down
44 changes: 28 additions & 16 deletions eventrate/eventrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (

// Opts are the command line options passed to the sub command
type Opts struct {
ServerAddr string
Buckets int
SecondsPerBucket int
EventCountDump int
ReportStyle bool
ServerAddr string
Buckets int
SecondsPerBucket int
EventCountDump int
ReportStyle bool
FinalReportRowCount int
}

func min(a, b uint64) uint64 {
Expand Down Expand Up @@ -90,6 +91,9 @@ func Run(opts Opts) error {
return fmt.Errorf("error reading events: %v", err)
}

reportCount := 0
var avgEvents uint64
var avgBytes uint64
for {
time.Sleep(time.Second * time.Duration(opts.SecondsPerBucket))
mu.Lock()
Expand Down Expand Up @@ -119,18 +123,20 @@ func Run(opts Opts) error {
maxBytes = max(maxBytes, i.Bytes)
totalBytes += i.Bytes
}
avgEvents := totalEvents / uint64(len(historicData))
avgBytes := totalBytes / uint64(len(historicData))
fmt.Printf("%s Events:Bandwidth (", blockTime.Format(time.UnixDate))
for i := len(historicData) - 1; i > 0; i-- {
fmt.Printf("[%d:%s], ", historicData[i].Events, fixUnits(historicData[i].Bytes))
}
fmt.Printf("[%d:%s]) Min:[%d:%s] Max:[%d:%s] Avg:[%d:%s] \r",
historicData[0].Events, fixUnits(historicData[0].Bytes),
minEvents, fixUnits(minBytes), maxEvents, fixUnits(maxBytes), avgEvents, fixUnits(avgBytes))
avgEvents = totalEvents / uint64(len(historicData))
avgBytes = totalBytes / uint64(len(historicData))
if opts.FinalReportRowCount == 0 {
fmt.Printf("%s Events:Bandwidth (", blockTime.Format(time.UnixDate))
for i := len(historicData) - 1; i > 0; i-- {
fmt.Printf("[%d:%s], ", historicData[i].Events, fixUnits(historicData[i].Bytes))
}
fmt.Printf("[%d:%s]) Min:[%d:%s] Max:[%d:%s] Avg:[%d:%s] \r",
historicData[0].Events, fixUnits(historicData[0].Bytes),
minEvents, fixUnits(minBytes), maxEvents, fixUnits(maxBytes), avgEvents, fixUnits(avgBytes))

if opts.ReportStyle {
fmt.Println()
if opts.ReportStyle {
fmt.Println()
}
}

if opts.EventCountDump > 0 {
Expand Down Expand Up @@ -158,5 +164,11 @@ func Run(opts Opts) error {
}
}
}
reportCount++
if reportCount == opts.FinalReportRowCount {
fmt.Printf("AverageEvents:%d:AverageBytes:%d\n", avgEvents, avgBytes)
break
}
}
return nil
}

0 comments on commit 484f7ed

Please sign in to comment.