/
organization.go
50 lines (43 loc) · 1.5 KB
/
organization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package metrics
import (
"log/slog"
"strconv"
"github.com/cloudbase/garm/auth"
"github.com/prometheus/client_golang/prometheus"
)
// CollectOrganizationMetric collects the metrics for the organization objects
func (c *GarmCollector) CollectOrganizationMetric(ch chan<- prometheus.Metric, hostname string, controllerID string) {
ctx := auth.GetAdminContext()
organizations, err := c.runner.ListOrganizations(ctx)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing providers")
return
}
for _, organization := range organizations {
organizationInfo, err := prometheus.NewConstMetric(
c.organizationInfo,
prometheus.GaugeValue,
1,
organization.Name, // label: name
organization.ID, // label: id
)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect organizationInfo metric")
continue
}
ch <- organizationInfo
organizationPoolManagerStatus, err := prometheus.NewConstMetric(
c.organizationPoolManagerStatus,
prometheus.GaugeValue,
bool2float64(organization.PoolManagerStatus.IsRunning),
organization.Name, // label: name
organization.ID, // label: id
strconv.FormatBool(organization.PoolManagerStatus.IsRunning), // label: running
)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect organizationPoolManagerStatus metric")
continue
}
ch <- organizationPoolManagerStatus
}
}