garm/runner/metrics/enterprise.go
Mario Constanti 7221812dfa fix: remove unused cobra args
Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
2024-02-22 17:20:05 +01:00

35 lines
926 B
Go

package metrics
import (
"context"
"strconv"
"github.com/cloudbase/garm/metrics"
"github.com/cloudbase/garm/runner" //nolint:typecheck
)
// CollectOrganizationMetric collects the metrics for the enterprise objects
func CollectEnterpriseMetric(ctx context.Context, r *runner.Runner) error {
// reset metrics
metrics.EnterpriseInfo.Reset()
metrics.EnterprisePoolManagerStatus.Reset()
enterprises, err := r.ListEnterprises(ctx)
if err != nil {
return err
}
for _, enterprise := range enterprises {
metrics.EnterpriseInfo.WithLabelValues(
enterprise.Name, // label: name
enterprise.ID, // label: id
).Set(1)
metrics.EnterprisePoolManagerStatus.WithLabelValues(
enterprise.Name, // label: name
enterprise.ID, // label: id
strconv.FormatBool(enterprise.PoolManagerStatus.IsRunning), // label: running
).Set(metrics.Bool2float64(enterprise.PoolManagerStatus.IsRunning))
}
return nil
}