diff --git a/pkg/databaseclaim/databaseclaim.go b/pkg/databaseclaim/databaseclaim.go index d9206db..587f211 100644 --- a/pkg/databaseclaim/databaseclaim.go +++ b/pkg/databaseclaim/databaseclaim.go @@ -131,9 +131,6 @@ func (r *DatabaseClaimReconciler) Reconcile(ctx context.Context, req ctrl.Reques } } - // Increment total claims count. - metrics.TotalDatabaseClaims.Inc() - // Track if the claim is using an existing source. if dbClaim.Spec.UseExistingSource != nil && *dbClaim.Spec.UseExistingSource { metrics.ExistingSourceClaims.WithLabelValues("true").Inc() @@ -257,6 +254,13 @@ func (r *DatabaseClaimReconciler) Reconcile(ctx context.Context, req ctrl.Reques metrics.ActiveDBState.WithLabelValues(string(dbClaim.Status.ActiveDB.DbState)).Inc() } + var databaseClaims v1.DatabaseClaimList + if err := r.List(ctx, &databaseClaims); err != nil { + logr.Error(err, "unable to list database claims") + } else { + metrics.TotalDatabaseClaims.WithLabelValues("total_claims").Set(float64(len(databaseClaims.Items))) + } + return res, nil } diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 891a4da..a8eb00f 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -82,11 +82,12 @@ var ( // ----------------------------------------------------------------------- // Database controller metrics - TotalDatabaseClaims = prometheus.NewGauge( + TotalDatabaseClaims = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "dbcontroller_total_database_claims", Help: "Total number of database claims", }, + []string{"total_claims"}, ) TotalDatabaseClaimsDeleted = prometheus.NewGauge( prometheus.GaugeOpts{