Skip to content

Commit

Permalink
robot, metrics: measure time spent waiting for global rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrtronium committed Nov 21, 2024
1 parent 86cd18f commit 0ef3deb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,15 @@ func newMetrics() *metrics.Metrics {
},
),
),
TMISendWait: metrics.NewPromCounter(
prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "robot",
Subsystem: "tmi",
Name: "send_wait",
Help: "Total time in seconds spent waiting for the global rate limit before sending messages to TMI.",
},
),
),
}
}
2 changes: 2 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Metrics struct {
SpeakLatency Observer
LearnLatency Observer
UsedMessagesForGeneration Observer
TMISendWait Observer
}

func (m Metrics) Collectors() []prometheus.Collector {
Expand All @@ -29,5 +30,6 @@ func (m Metrics) Collectors() []prometheus.Collector {
m.TMIMsgsCount,
m.LearnLatency,
m.UsedMessagesForGeneration,
m.TMISendWait,
}
}
1 change: 1 addition & 0 deletions privmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (robo *Robot) sendTMI(ctx context.Context, send chan<- *tmi.Message, msg me
slog.String("in", msg.To),
slog.String("text", msg.Text),
)
robo.Metrics.TMISendWait.Observe(d.Seconds())
select {
case <-ctx.Done():
return
Expand Down

0 comments on commit 0ef3deb

Please sign in to comment.