all: Add Prometheus-style metrics to expose some internal performance counters (fixes #5175) (#9003)

This commit is contained in:
Jakob Borg
2023-08-04 19:57:30 +02:00
committed by GitHub
parent 58042b3129
commit b9c08d3814
25 changed files with 945 additions and 53 deletions
+8 -4
View File
@@ -10,8 +10,9 @@ import (
type countingReader struct {
io.Reader
tot atomic.Int64 // bytes
last atomic.Int64 // unix nanos
idString string
tot atomic.Int64 // bytes
last atomic.Int64 // unix nanos
}
var (
@@ -24,6 +25,7 @@ func (c *countingReader) Read(bs []byte) (int, error) {
c.tot.Add(int64(n))
totalIncoming.Add(int64(n))
c.last.Store(time.Now().UnixNano())
metricDeviceRecvBytes.WithLabelValues(c.idString).Add(float64(n))
return n, err
}
@@ -35,8 +37,9 @@ func (c *countingReader) Last() time.Time {
type countingWriter struct {
io.Writer
tot atomic.Int64 // bytes
last atomic.Int64 // unix nanos
idString string
tot atomic.Int64 // bytes
last atomic.Int64 // unix nanos
}
func (c *countingWriter) Write(bs []byte) (int, error) {
@@ -44,6 +47,7 @@ func (c *countingWriter) Write(bs []byte) (int, error) {
c.tot.Add(int64(n))
totalOutgoing.Add(int64(n))
c.last.Store(time.Now().UnixNano())
metricDeviceSentBytes.WithLabelValues(c.idString).Add(float64(n))
return n, err
}