-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speak/Learn/MessagesUsed Metrics (#85)
* metrics: - refactor metrics from global vars - add learn and speak latency histograms. * add messages used histogram * remove duplicated metrics config Fixes #83.
- Loading branch information
Showing
9 changed files
with
189 additions
and
43 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package metrics | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type Observer interface { | ||
Observe(val float64, labels ...string) | ||
|
||
// for now we will tightly couple to the prometheus collector type | ||
// the go otel metrics sdk also has a prometheus adapter that implements this interface. | ||
prometheus.Collector | ||
} | ||
|
||
type Metrics struct { | ||
TMIMsgsCount Observer | ||
TMICommandCount Observer | ||
LearnedCount Observer | ||
ForgotCount Observer | ||
SpeakLatency Observer | ||
LearnLatency Observer | ||
UsedMessagesForGeneration Observer | ||
} | ||
|
||
func (m Metrics) Collectors() []prometheus.Collector { | ||
return []prometheus.Collector{ | ||
m.ForgotCount, | ||
m.LearnedCount, | ||
m.SpeakLatency, | ||
m.TMICommandCount, | ||
m.TMIMsgsCount, | ||
m.LearnLatency, | ||
m.UsedMessagesForGeneration, | ||
} | ||
} |
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,51 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func NewPromCounter(m prometheus.Counter) Observer { | ||
return &PrometheusMetric{ | ||
observe: func(val float64, labels ...string) { | ||
m.Add(val) | ||
}, | ||
Collector: m, | ||
} | ||
} | ||
|
||
func NewPromGauge(m prometheus.Counter) Observer { | ||
return &PrometheusMetric{ | ||
observe: func(val float64, labels ...string) { | ||
m.Add(val) | ||
}, | ||
Collector: m, | ||
} | ||
} | ||
|
||
// for histogram or summary vecs | ||
func NewPromObserverVec(m prometheus.ObserverVec) Observer { | ||
return &PrometheusMetric{ | ||
observe: func(val float64, labels ...string) { | ||
m.WithLabelValues(labels...).Observe(val) | ||
}, | ||
Collector: m, | ||
} | ||
} | ||
|
||
func NewPromHistogram(m prometheus.Histogram) Observer { | ||
return &PrometheusMetric{ | ||
observe: func(val float64, labels ...string) { | ||
m.Observe(val) | ||
}, | ||
Collector: m, | ||
} | ||
} | ||
|
||
type PrometheusMetric struct { | ||
observe func(val float64, labels ...string) | ||
prometheus.Collector | ||
} | ||
|
||
func (m *PrometheusMetric) Observe(val float64, labels ...string) { | ||
m.observe(val, labels...) | ||
} |
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