Skip to content

Commit

Permalink
fix metric counter type
Browse files Browse the repository at this point in the history
  • Loading branch information
canercidam committed Jan 31, 2024
1 parent b067fd8 commit 66fe511
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions services/publisher/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type metricsBucket struct {
}

type metricsData struct {
Counters []uint32
Counters []float64
Details string
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func (ama *AgentMetricsAggregator) AddAgentMetrics(ms *protocol.AgentMetricList)

bucket := ama.findBucket(m.AgentId, chainID, t)
bucket.MetricsData[m.Name] = metricsData{
Counters: append(bucket.MetricsData[m.Name].Counters, uint32(m.Value)),
Counters: append(bucket.MetricsData[m.Name].Counters, m.Value),
Details: m.Details,
}
}
Expand Down Expand Up @@ -193,16 +193,16 @@ func (allMetrics allAgentMetrics) PrepareMetrics() {
}
}

func avgMetricArray(data []uint32) float64 {
func avgMetricArray(data []float64) float64 {
sum := decimal.NewFromInt(0)
for _, dataPoint := range data {
sum = sum.Add(decimal.NewFromInt32(int32(dataPoint)))
sum = sum.Add(decimal.NewFromFloat(dataPoint))
}
f, _ := sum.Div(decimal.NewFromInt32(int32(len(data)))).Round(2).Float64()
return f
}

func maxDataPoint(data []uint32) float64 {
func maxDataPoint(data []float64) float64 {
var max float64
for _, dataPoint := range data {
if float64(dataPoint) > max {
Expand All @@ -212,7 +212,7 @@ func maxDataPoint(data []uint32) float64 {
return max
}

func calcP95(data []uint32) float64 {
func calcP95(data []float64) float64 {
switch len(data) {
case 0:
return 0
Expand All @@ -228,7 +228,7 @@ func calcP95(data []uint32) float64 {
return float64(data[k95-1])
}

func sumNums(data []uint32) (n float64) {
func sumNums(data []float64) (n float64) {
for _, d := range data {
n += float64(d)
}
Expand Down

0 comments on commit 66fe511

Please sign in to comment.