Skip to content

Commit

Permalink
add cmd_code tag to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
luissimas committed Dec 11, 2023
1 parent 85970fd commit 4e5b9c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"os"
"strconv"
"time"

"github.com/fiorix/go-diameter/v4/diam"
Expand Down Expand Up @@ -182,9 +183,12 @@ func (c *DiameterClient) Send(msg *DiameterMessage) (*DiameterMessage, error) {
// 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, time.Now(), metrics.D(now.Sub(sentAt)))
c.reportMetric(c.metrics.RequestCount, time.Now(), 1)
c.reportMetric(c.metrics.RequestDuration, time.Now(), metrics.D(now.Sub(sentAt)), tags)
c.reportMetric(c.metrics.RequestCount, time.Now(), 1, tags)

delete(c.hopIds, hopByHopID)

Expand Down
3 changes: 2 additions & 1 deletion metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func registerMetrics(vu modules.VU) DiameterMetrics {
return metrics
}

func (c *DiameterClient) reportMetric(metric *metrics.Metric, now time.Time, value float64) {
func (c *DiameterClient) reportMetric(metric *metrics.Metric, now time.Time, value float64, tags map[string]string) {
state := c.vu.State()
ctx := c.vu.Context()
if state == nil || ctx == nil {
Expand All @@ -32,6 +32,7 @@ func (c *DiameterClient) reportMetric(metric *metrics.Metric, now time.Time, val
Time: now,
TimeSeries: metrics.TimeSeries{
Metric: metric,
Tags: metrics.NewRegistry().RootTagSet().WithTagsFromMap(tags),
},
Value: value,
})
Expand Down

0 comments on commit 4e5b9c2

Please sign in to comment.