chore: refactor metrics endpoint
refactoring is needed to make the metrics package usable from within the runner package for further metrics. This change also makes the metric-collector independent from requests to the /metrics endpoint Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
This commit is contained in:
parent
f68cf98d67
commit
1d8d9459eb
21 changed files with 564 additions and 590 deletions
35
runner/metrics/repository.go
Normal file
35
runner/metrics/repository.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudbase/garm/metrics"
|
||||
"github.com/cloudbase/garm/runner"
|
||||
)
|
||||
|
||||
func CollectRepositoryMetric(ctx context.Context, r *runner.Runner) error {
|
||||
|
||||
// reset metrics
|
||||
metrics.EnterpriseInfo.Reset()
|
||||
metrics.EnterprisePoolManagerStatus.Reset()
|
||||
|
||||
repositories, err := r.ListRepositories(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, repository := range repositories {
|
||||
metrics.EnterpriseInfo.WithLabelValues(
|
||||
repository.Name, // label: name
|
||||
repository.ID, // label: id
|
||||
).Set(1)
|
||||
|
||||
metrics.EnterprisePoolManagerStatus.WithLabelValues(
|
||||
repository.Name, // label: name
|
||||
repository.ID, // label: id
|
||||
strconv.FormatBool(repository.PoolManagerStatus.IsRunning), // label: running
|
||||
).Set(metrics.Bool2float64(repository.PoolManagerStatus.IsRunning))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue