Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(metrics): add pipeline average time metrics
Add two prometheus gauges measuring the following metrics: 1. Average time spent from kernel to decoding 2. Average time spent from kernel to publishing
- Loading branch information
1 parent
92ac6f2
commit 4aed8fc
Showing
6 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package counter | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
type Average struct { | ||
sum Counter | ||
c Counter | ||
m *sync.RWMutex | ||
} | ||
|
||
func NewAverage() Average { | ||
return Average{ | ||
sum: NewCounter(0), | ||
c: NewCounter(0), | ||
m: new(sync.RWMutex), | ||
} | ||
} | ||
|
||
func (avg *Average) Read() float64 { | ||
avg.m.RLock() | ||
defer avg.m.RUnlock() | ||
|
||
sum := float64(avg.sum.Get()) | ||
count := float64(avg.c.Get()) | ||
|
||
return sum / count | ||
} | ||
|
||
func (avg *Average) Add(val uint64) error { | ||
_, err := avg.AddAndRead(val) | ||
return err | ||
} | ||
|
||
func (avg *Average) AddAndRead(val uint64) (float64, error) { | ||
avg.m.Lock() | ||
defer avg.m.Unlock() | ||
|
||
sum, err := avg.sum.IncrementValueAndRead(val) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to increment average sum: %v", err) | ||
} | ||
count, err := avg.c.IncrementValueAndRead(1) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to increment average count: %v", err) | ||
} | ||
|
||
return float64(sum) / float64(count), nil | ||
} | ||
|
||
func (avg Average) String() string { | ||
return fmt.Sprintf("%f", avg.Read()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters