Skip to content

Commit 0d79eff

Browse files
authored
Add new metric for initial call check. (#446)
1 parent a0868c2 commit 0d79eff

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/sip/inbound.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (s *Server) onInvite(log *slog.Logger, req *sip.Request, tx sip.ServerTrans
201201
}
202202

203203
func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retErr error) {
204+
start := time.Now()
204205
var state *CallState
205206
ctx := context.Background()
206207
defer func() {
@@ -265,6 +266,14 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
265266
cmon := s.mon.NewCall(stats.Inbound, from.Host, to.Host)
266267
cmon.InviteReq()
267268
defer cmon.SessionDur()()
269+
var checkDurOnce sync.Once
270+
checkDur := cmon.CheckDur()
271+
checked := func() {
272+
checkDurOnce.Do(func() {
273+
checkDur.Observe(time.Since(start).Seconds())
274+
})
275+
}
276+
defer checked()
268277
joinDur := cmon.JoinDur()
269278

270279
if !s.conf.HideInboundPort {
@@ -297,6 +306,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
297306
}
298307

299308
r, err := s.handler.GetAuthCredentials(ctx, callInfo)
309+
checked()
300310
if err != nil {
301311
cmon.InviteErrorShort("auth-error")
302312
log.Warnw("Rejecting inbound, auth check failed", err)

pkg/stats/monitor.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Monitor struct {
7070
durSession *prometheus.HistogramVec
7171
durCall *prometheus.HistogramVec
7272
durJoin *prometheus.HistogramVec
73+
durCheck *prometheus.HistogramVec
7374
cpuLoad prometheus.Gauge
7475
sdpSize *prometheus.HistogramVec
7576
nodeAvailable prometheus.GaugeFunc
@@ -191,6 +192,15 @@ func (m *Monitor) Start(conf *config.Config) error {
191192
Buckets: durBucketsLong,
192193
}, []string{"dir"}))
193194

195+
m.durCheck = mustRegister(m, prometheus.NewHistogramVec(prometheus.HistogramOpts{
196+
Namespace: "livekit",
197+
Subsystem: "sip",
198+
Name: "dur_check_sec",
199+
Help: "SIP call check duration (from INVITE to an initial dispatch response)",
200+
ConstLabels: prometheus.Labels{"node_id": conf.NodeID},
201+
Buckets: durBucketsOp,
202+
}, []string{"dir"}))
203+
194204
m.durJoin = mustRegister(m, prometheus.NewHistogramVec(prometheus.HistogramOpts{
195205
Namespace: "livekit",
196206
Subsystem: "sip",
@@ -365,6 +375,10 @@ func (c *CallMonitor) CallDur() func() time.Duration {
365375
return prometheus.NewTimer(c.m.durCall.With(c.labelsShort(nil))).ObserveDuration
366376
}
367377

378+
func (c *CallMonitor) CheckDur() prometheus.Observer {
379+
return c.m.durCheck.With(c.labelsShort(nil))
380+
}
381+
368382
func (c *CallMonitor) JoinDur() func() time.Duration {
369383
return prometheus.NewTimer(c.m.durJoin.With(c.labelsShort(nil))).ObserveDuration
370384
}

0 commit comments

Comments
 (0)