-
Notifications
You must be signed in to change notification settings - Fork 175
/
main.go
52 lines (44 loc) · 1.64 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"math/rand"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/module/metrics/example"
"github.com/onflow/flow-go/module/trace"
"github.com/onflow/flow-go/utils/unittest"
)
// main runs a local tracer server on the machine and starts monitoring some metrics for sake of execution, which
// increases result approvals counter and checked chunks counter 100 times each
func main() {
example.WithMetricsServer(func(logger zerolog.Logger) {
tracer, err := trace.NewTracer(logger, "collection")
if err != nil {
panic(err)
}
collector := struct {
*metrics.HotstuffCollector
*metrics.ExecutionCollector
*metrics.NetworkCollector
}{
HotstuffCollector: metrics.NewHotstuffCollector("some_chain_id"),
ExecutionCollector: metrics.NewExecutionCollector(tracer, prometheus.DefaultRegisterer),
NetworkCollector: metrics.NewNetworkCollector(),
}
diskTotal := rand.Int63n(1024 ^ 3)
for i := 0; i < 1000; i++ {
blockID := unittest.BlockFixture().ID()
collector.StartBlockReceivedToExecuted(blockID)
// adds a random delay for execution duration, between 0 and 2 seconds
time.Sleep(time.Duration(rand.Int31n(2000)) * time.Millisecond)
collector.ExecutionGasUsedPerBlock(uint64(rand.Int63n(1e6)))
collector.ExecutionStateReadsPerBlock(uint64(rand.Int63n(1e6)))
diskIncrease := rand.Int63n(1024 ^ 2)
diskTotal += diskIncrease
collector.ExecutionStateStorageDiskTotal(diskTotal)
collector.ExecutionStorageStateCommitment(diskIncrease)
collector.FinishBlockReceivedToExecuted(blockID)
}
})
}