Skip to content

Commit

Permalink
Merge pull request #388 from nyaruka/fix_duration_metrics
Browse files Browse the repository at this point in the history
Fix integer rounding in duration metrics
  • Loading branch information
rowanseymour authored Dec 18, 2024
2 parents d70011e + de97f26 commit dc02171
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions mailroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func (mr *Mailroom) reportMetrics(ctx context.Context) (int, error) {
hostDim := cwatch.Dimension("Host", mr.rt.Config.InstanceID)
metrics = append(metrics,
cwatch.Datum("DBConnectionsInUse", float64(dbStats.InUse), types.StandardUnitCount, hostDim),
cwatch.Datum("DBConnectionWaitDuration", float64(dbWaitDurationInPeriod/time.Second), types.StandardUnitSeconds, hostDim),
cwatch.Datum("DBConnectionWaitDuration", float64(dbWaitDurationInPeriod)/float64(time.Second), types.StandardUnitSeconds, hostDim),
cwatch.Datum("RedisConnectionsInUse", float64(redisStats.ActiveCount), types.StandardUnitCount, hostDim),
cwatch.Datum("RedisConnectionsWaitDuration", float64(redisWaitDurationInPeriod/time.Second), types.StandardUnitSeconds, hostDim),
cwatch.Datum("RedisConnectionsWaitDuration", float64(redisWaitDurationInPeriod)/float64(time.Second), types.StandardUnitSeconds, hostDim),
cwatch.Datum("QueuedTasks", float64(handlerSize), types.StandardUnitCount, cwatch.Dimension("QueueName", "handler")),
cwatch.Datum("QueuedTasks", float64(batchSize), types.StandardUnitCount, cwatch.Dimension("QueueName", "batch")),
cwatch.Datum("QueuedTasks", float64(throttledSize), types.StandardUnitCount, cwatch.Dimension("QueueName", "throttled")),
Expand Down
6 changes: 3 additions & 3 deletions runtime/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ func (s *Stats) ToMetrics() []types.MetricDatum {

metrics = append(metrics,
cwatch.Datum("HandlerTaskCount", float64(s.HandlerTaskCount), types.StandardUnitCount),
cwatch.Datum("HandlerTaskDuration", float64(avgHandlerTaskDuration/time.Second), types.StandardUnitCount),
cwatch.Datum("HandlerTaskLatency", float64(avgHandlerTaskLatency/time.Second), types.StandardUnitCount),
cwatch.Datum("HandlerTaskDuration", float64(avgHandlerTaskDuration)/float64(time.Second), types.StandardUnitCount),
cwatch.Datum("HandlerTaskLatency", float64(avgHandlerTaskLatency)/float64(time.Second), types.StandardUnitCount),
)

for name, count := range s.CronTaskCount {
avgTime := s.CronTaskDuration[name] / time.Duration(count)

metrics = append(metrics,
cwatch.Datum("CronTaskCount", float64(count), types.StandardUnitCount, cwatch.Dimension("TaskName", name)),
cwatch.Datum("CronTaskDuration", float64(avgTime/time.Second), types.StandardUnitSeconds, cwatch.Dimension("TaskName", name)),
cwatch.Datum("CronTaskDuration", float64(avgTime)/float64(time.Second), types.StandardUnitSeconds, cwatch.Dimension("TaskName", name)),
)
}

Expand Down

0 comments on commit dc02171

Please sign in to comment.