-
Notifications
You must be signed in to change notification settings - Fork 29
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 #216 from mercedes-benz/extended_metrics
chore: refactor metrics endpoint
- Loading branch information
Showing
28 changed files
with
651 additions
and
612 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
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
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 |
---|---|---|
@@ -1,50 +1,21 @@ | ||
package metrics | ||
|
||
import ( | ||
"log/slog" | ||
"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 { | ||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing providers") | ||
return | ||
} | ||
|
||
for _, enterprise := range enterprises { | ||
var ( | ||
EnterpriseInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsEnterpriseSubsystem, | ||
Name: "info", | ||
Help: "Info of the enterprise", | ||
}, []string{"name", "id"}) | ||
|
||
enterpriseInfo, err := prometheus.NewConstMetric( | ||
c.enterpriseInfo, | ||
prometheus.GaugeValue, | ||
1, | ||
enterprise.Name, // label: name | ||
enterprise.ID, // label: id | ||
) | ||
if err != nil { | ||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect enterpriseInfo metric") | ||
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 { | ||
slog.With(slog.Any("error", err)).ErrorContext(ctx, "cannot collect enterprisePoolManagerStatus metric") | ||
continue | ||
} | ||
ch <- enterprisePoolManagerStatus | ||
} | ||
} | ||
EnterprisePoolManagerStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsEnterpriseSubsystem, | ||
Name: "pool_manager_status", | ||
Help: "Status of the enterprise pool manager", | ||
}, []string{"name", "id", "running"}) | ||
) |
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 |
---|---|---|
@@ -1,22 +1,13 @@ | ||
package metrics | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"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 { | ||
slog.With(slog.Any("error", err)).Error("error on creating health metric") | ||
return | ||
} | ||
ch <- m | ||
} | ||
var ( | ||
GarmHealth = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Name: "health", | ||
Help: "Health of the garm", | ||
}, []string{"metadata_url", "callback_url", "webhook_url", "controller_webhook_url", "controller_id"}) | ||
) |
Oops, something went wrong.