-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from mercedes-benz/additional_metrics
feat: add new metrics
- Loading branch information
Showing
10 changed files
with
579 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package metrics | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
|
||
"github.com/cloudbase/garm/auth" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// CollectOrganizationMetric collects the metrics for the enterprise objects | ||
func (c *GarmCollector) CollectEnterpriseMetric(ch chan<- prometheus.Metric, hostname string, controllerID string) { | ||
ctx := auth.GetAdminContext() | ||
|
||
enterprises, err := c.runner.ListEnterprises(ctx) | ||
if err != nil { | ||
log.Printf("listing providers: %s", err) | ||
return | ||
} | ||
|
||
for _, enterprise := range enterprises { | ||
|
||
enterpriseInfo, err := prometheus.NewConstMetric( | ||
c.enterpriseInfo, | ||
prometheus.GaugeValue, | ||
1, | ||
enterprise.Name, // label: name | ||
enterprise.ID, // label: id | ||
) | ||
if err != nil { | ||
log.Printf("cannot collect enterpriseInfo metric: %s", err) | ||
continue | ||
} | ||
ch <- enterpriseInfo | ||
|
||
enterprisePoolManagerStatus, err := prometheus.NewConstMetric( | ||
c.enterprisePoolManagerStatus, | ||
prometheus.GaugeValue, | ||
bool2float64(enterprise.PoolManagerStatus.IsRunning), | ||
enterprise.Name, // label: name | ||
enterprise.ID, // label: id | ||
strconv.FormatBool(enterprise.PoolManagerStatus.IsRunning), // label: running | ||
) | ||
if err != nil { | ||
log.Printf("cannot collect enterprisePoolManagerStatus metric: %s", err) | ||
continue | ||
} | ||
ch <- enterprisePoolManagerStatus | ||
} | ||
} |
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,22 @@ | ||
package metrics | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func (c *GarmCollector) CollectHealthMetric(ch chan<- prometheus.Metric, hostname string, controllerID string) { | ||
m, err := prometheus.NewConstMetric( | ||
c.healthMetric, | ||
prometheus.GaugeValue, | ||
1, | ||
hostname, | ||
controllerID, | ||
) | ||
if err != nil { | ||
log.Printf("error on creating health metric: %s", err) | ||
return | ||
} | ||
ch <- m | ||
} |
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,79 @@ | ||
package metrics | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/cloudbase/garm/auth" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// CollectInstanceMetric collects the metrics for the runner instances | ||
// reflecting the statuses and the pool they belong to. | ||
func (c *GarmCollector) CollectInstanceMetric(ch chan<- prometheus.Metric, hostname string, controllerID string) { | ||
ctx := auth.GetAdminContext() | ||
|
||
instances, err := c.runner.ListAllInstances(ctx) | ||
if err != nil { | ||
log.Printf("cannot collect metrics, listing instances: %s", err) | ||
return | ||
} | ||
|
||
pools, err := c.runner.ListAllPools(ctx) | ||
if err != nil { | ||
log.Printf("listing pools: %s", err) | ||
return | ||
} | ||
|
||
type poolInfo struct { | ||
Name string | ||
Type string | ||
ProviderName string | ||
} | ||
|
||
poolNames := make(map[string]poolInfo) | ||
for _, pool := range pools { | ||
if pool.EnterpriseName != "" { | ||
poolNames[pool.ID] = poolInfo{ | ||
Name: pool.EnterpriseName, | ||
Type: string(pool.PoolType()), | ||
ProviderName: pool.ProviderName, | ||
} | ||
} else if pool.OrgName != "" { | ||
poolNames[pool.ID] = poolInfo{ | ||
Name: pool.OrgName, | ||
Type: string(pool.PoolType()), | ||
ProviderName: pool.ProviderName, | ||
} | ||
} else { | ||
poolNames[pool.ID] = poolInfo{ | ||
Name: pool.RepoName, | ||
Type: string(pool.PoolType()), | ||
ProviderName: pool.ProviderName, | ||
} | ||
} | ||
} | ||
|
||
for _, instance := range instances { | ||
|
||
m, err := prometheus.NewConstMetric( | ||
c.instanceMetric, | ||
prometheus.GaugeValue, | ||
1, | ||
instance.Name, // label: name | ||
string(instance.Status), // label: status | ||
string(instance.RunnerStatus), // label: runner_status | ||
poolNames[instance.PoolID].Name, // label: pool_owner | ||
poolNames[instance.PoolID].Type, // label: pool_type | ||
instance.PoolID, // label: pool_id | ||
hostname, // label: hostname | ||
controllerID, // label: controller_id | ||
poolNames[instance.PoolID].ProviderName, // label: provider | ||
) | ||
|
||
if err != nil { | ||
log.Printf("cannot collect runner metric: %s", err) | ||
continue | ||
} | ||
ch <- m | ||
} | ||
} |
Oops, something went wrong.