Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): Add getters #462

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pkg/api/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
io_prometheus_client "github.com/prometheus/client_model/go"
)

const (
Expand Down Expand Up @@ -60,6 +61,30 @@

var registered map[string]interface{}

// Get current value of a Counter metric
func GetCounter(name string) *float64 {
if _, ok := registered[name]; ok {
m := io_prometheus_client.Metric{}
registered[name].(prometheus.Counter).Write(&m)

Check failure on line 68 in pkg/api/prometheus/prometheus.go

View workflow job for this annotation

GitHub Actions / Validate Go code linting

Error return value of `(github.com/prometheus/client_golang/prometheus.Metric).Write` is not checked (errcheck)
return m.Counter.Value
}
return nil
}

// Get current value of an Average metric
func GetAverage(name string) *float64 {
if _, ok := registered[name]; ok {
m := io_prometheus_client.Metric{}
registered[name].(prometheus.Histogram).Write(&m)

Check failure on line 78 in pkg/api/prometheus/prometheus.go

View workflow job for this annotation

GitHub Actions / Validate Go code linting

Error return value of `(github.com/prometheus/client_golang/prometheus.Metric).Write` is not checked (errcheck)
if m.Histogram.SampleSum != nil && m.Histogram.SampleCountFloat != nil {
average := *m.Histogram.SampleSum / *m.Histogram.SampleCountFloat
return &average
}
return nil
}
return nil
}

// Increment will increment the counter.
func Increment(name string) {
if _, ok := registered[name]; ok {
Expand Down
Loading