Skip to content

Commit

Permalink
add diameter_req_failed metric
Browse files Browse the repository at this point in the history
  • Loading branch information
luissimas committed Dec 11, 2023
1 parent 1bd17ab commit bf16483
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,20 @@ func (c *DiameterClient) Send(msg *DiameterMessage) (*DiameterMessage, error) {

// Register current time to calculate request duration
sentAt := time.Now()
tags := map[string]string{
"cmd_code": strconv.FormatUint(uint64(msg.diamMsg.Header.CommandCode), 10),
}

// Send Request
_, err := req.WriteTo(c.conn)
if err != nil {
c.reportMetric(c.metrics.FailedRequestCount, time.Now(), 1, tags)
return nil, err
}

// Wait for Response
select {
case resp := <-c.hopIds[hopByHopID]:
tags := map[string]string{
"cmd_code": strconv.FormatUint(uint64(msg.diamMsg.Header.CommandCode), 10),
}
now := time.Now()
c.reportMetric(c.metrics.RequestDuration, now, metrics.D(now.Sub(sentAt)), tags)
c.reportMetric(c.metrics.RequestCount, now, 1, tags)
Expand All @@ -194,6 +195,7 @@ func (c *DiameterClient) Send(msg *DiameterMessage) (*DiameterMessage, error) {

return &DiameterMessage{diamMsg: resp}, nil
case <-timeout:
c.reportMetric(c.metrics.FailedRequestCount, time.Now(), 1, tags)
return nil, errors.New("Response timeout")
}
}
Expand Down
10 changes: 6 additions & 4 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
)

type DiameterMetrics struct {
RequestDuration *metrics.Metric
RequestCount *metrics.Metric
RequestDuration *metrics.Metric
RequestCount *metrics.Metric
FailedRequestCount *metrics.Metric
}

func registerMetrics(vu modules.VU) DiameterMetrics {
registry := vu.InitEnv().Registry
metrics := DiameterMetrics{
RequestDuration: registry.MustNewMetric("diameter_req_duration", metrics.Trend, metrics.Time),
RequestCount: registry.MustNewMetric("diameter_req_count", metrics.Counter, metrics.Default),
RequestDuration: registry.MustNewMetric("diameter_req_duration", metrics.Trend, metrics.Time),
RequestCount: registry.MustNewMetric("diameter_req_count", metrics.Counter, metrics.Default),
FailedRequestCount: registry.MustNewMetric("diameter_req_failed", metrics.Counter, metrics.Default),
}
return metrics
}
Expand Down

0 comments on commit bf16483

Please sign in to comment.