Skip to content

Commit

Permalink
Add rate to stats reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Mar 24, 2022
1 parent 05c06b0 commit d4e4c5a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ func (d *Daemon) reportStats() {
stats := ix.Stats()
prev := d.prevStats[ix]

metrics[ix.Name()+"_indexed"] = float64(stats.Indexed - prev.Indexed)
metrics[ix.Name()+"_deleted"] = float64(stats.Deleted - prev.Deleted)
indexedInPeriod := stats.Indexed - prev.Indexed
deletedInPeriod := stats.Deleted - prev.Deleted
elapsedInPeriod := stats.Elapsed - prev.Elapsed
rateInPeriod := float64(0)
if indexedInPeriod > 0 && elapsedInPeriod > 0 {
rateInPeriod = float64(indexedInPeriod) / (float64(elapsedInPeriod) / float64(time.Second))
}

metrics[ix.Name()+"_indexed"] = float64(indexedInPeriod)
metrics[ix.Name()+"_deleted"] = float64(deletedInPeriod)
metrics[ix.Name()+"_rate"] = rateInPeriod

d.prevStats[ix] = stats
}
Expand Down

0 comments on commit d4e4c5a

Please sign in to comment.