Skip to content

Commit

Permalink
add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudzp committed Apr 16, 2024
1 parent c48a90b commit 3bceccd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/recommendation/recommendation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ func (r Checker) runChecker() {
"owner_name": recommend.Spec.TargetRef.Name,
"update_status": updateStatus,
"result_status": resultStatus,
}).Set(1)
}).Set(time.Now().Sub(recommend.Status.LastUpdateTime.Time).Seconds())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ func executeIdentity(ctx context.Context, wg *sync.WaitGroup, recommenderMgr rec
defer func() {
if wg != nil {
wg.Done()
metrics.RecommendationExecutionCounter.WithLabelValues(id.APIVersion, id.Kind, id.Namespace, id.Name, id.Recommender).Inc()
}
}()
var message string
Expand Down
12 changes: 11 additions & 1 deletion pkg/metrics/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
)

var (
RecommendationExecutionCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "crane",
Subsystem: "analysis",
Name: "recommendation_execution_total",
Help: "The number of times Recommendation has been executed",
},
[]string{"apiversion", "owner_kind", "namespace", "owner_name", "type"},
)

ResourceRecommendation = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "crane",
Expand Down Expand Up @@ -48,5 +58,5 @@ var (
)

func init() {
metrics.Registry.MustRegister(ResourceRecommendation, ReplicasRecommendation, SelectTargets, RecommendationsStatus)
metrics.Registry.MustRegister(RecommendationExecutionCounter, ResourceRecommendation, ReplicasRecommendation, SelectTargets, RecommendationsStatus)
}

0 comments on commit 3bceccd

Please sign in to comment.