Skip to content

Commit

Permalink
More accurate TOTAL rates
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuratczyk committed Dec 17, 2024
1 parent 6e02254 commit a982571
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func start(cfg config.Config) {

startPublishing := make(chan bool)
startPublishers(ctx, &wg, startPublishing)
metricsServer.StartTime(time.Now())
close(startPublishing)

if cfg.Duration > 0 {
Expand Down
6 changes: 5 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Start(ctx context.Context, cfg config.Config) *MetricsServer {

go func() {
for {
metricsServer.started = time.Now()
metricsServer.started = time.Now() // updated later for higher accuracy
log.Debug("starting Prometheus metrics server", "address", metricsServer.httpServer.Addr)
err := metricsServer.httpServer.ListenAndServe()
if errors.Is(err, syscall.EADDRINUSE) {
Expand Down Expand Up @@ -168,6 +168,10 @@ func (m *MetricsServer) printMessageRates(ctx context.Context) {
}()
}

func (m *MetricsServer) StartTime(t time.Time) {
m.started = t
}

func (m *MetricsServer) Stop() {
m.PrintSummary()
if m.printAllOnStop {
Expand Down

0 comments on commit a982571

Please sign in to comment.