@@ -69,6 +69,7 @@ type SchedulerMetrics struct {
6969 tryNodeEvaluation prometheus.Histogram
7070 lock locking.RWMutex
7171 tryNodeCount * prometheus.CounterVec
72+ tryApplicationCount * prometheus.CounterVec
7273}
7374
7475// InitSchedulerMetrics to initialize scheduler metrics
@@ -79,6 +80,16 @@ func InitSchedulerMetrics() *SchedulerMetrics {
7980
8081 s .nodeResourceUsage = make (map [string ]* prometheus.GaugeVec ) // Note: This map might be updated at runtime
8182
83+ initCounterMetrics (s )
84+ initGaugeMetrics (s )
85+ initHistogramMetrics (s )
86+ registerSchedulerMetrics (s )
87+
88+ return s
89+ }
90+
91+ // initCounterMetrics initializes counter-based metrics
92+ func initCounterMetrics (s * SchedulerMetrics ) {
8293 s .containerAllocation = prometheus .NewCounterVec (
8394 prometheus.CounterOpts {
8495 Namespace : Namespace ,
@@ -95,6 +106,25 @@ func InitSchedulerMetrics() *SchedulerMetrics {
95106 Help : "Total number of application submissions. State of the attempt includes `new`, `accepted` and `rejected`." ,
96107 }, []string {"result" })
97108
109+ s .tryNodeCount = prometheus .NewCounterVec (
110+ prometheus.CounterOpts {
111+ Namespace : Namespace ,
112+ Subsystem : SchedulerSubsystem ,
113+ Name : "trynode_count" ,
114+ Help : "Total number of nodes evaluated during scheduling cycle" ,
115+ }, nil )
116+
117+ s .tryApplicationCount = prometheus .NewCounterVec (
118+ prometheus.CounterOpts {
119+ Namespace : Namespace ,
120+ Subsystem : SchedulerSubsystem ,
121+ Name : "tryapplication_count" ,
122+ Help : "Total number of applications evaluated during scheduling cycle" ,
123+ }, nil )
124+ }
125+
126+ // initGaugeMetrics initializes gauge-based metrics
127+ func initGaugeMetrics (s * SchedulerMetrics ) {
98128 s .application = prometheus .NewGaugeVec (
99129 prometheus.GaugeOpts {
100130 Namespace : Namespace ,
@@ -110,7 +140,10 @@ func InitSchedulerMetrics() *SchedulerMetrics {
110140 Name : "node" ,
111141 Help : "Total number of nodes. State of the node includes `active` and `failed`." ,
112142 }, []string {"state" })
143+ }
113144
145+ // initHistogramMetrics initializes histogram-based metrics
146+ func initHistogramMetrics (s * SchedulerMetrics ) {
114147 s .schedulingLatency = prometheus .NewHistogram (
115148 prometheus.HistogramOpts {
116149 Namespace : Namespace ,
@@ -169,15 +202,10 @@ func InitSchedulerMetrics() *SchedulerMetrics {
169202 Buckets : prometheus .ExponentialBuckets (0.0001 , 10 , 8 ),
170203 },
171204 )
205+ }
172206
173- s .tryNodeCount = prometheus .NewCounterVec (
174- prometheus.CounterOpts {
175- Namespace : Namespace ,
176- Subsystem : SchedulerSubsystem ,
177- Name : "trynode_count" ,
178- Help : "Total number of nodes evaluated during scheduling cycle" ,
179- }, nil )
180- // Register the metrics
207+ // registerSchedulerMetrics registers all scheduler metrics with Prometheus
208+ func registerSchedulerMetrics (s * SchedulerMetrics ) {
181209 var metricsList = []prometheus.Collector {
182210 s .containerAllocation ,
183211 s .applicationSubmission ,
@@ -190,13 +218,13 @@ func InitSchedulerMetrics() *SchedulerMetrics {
190218 s .tryNodeEvaluation ,
191219 s .tryPreemptionLatency ,
192220 s .tryNodeCount ,
221+ s .tryApplicationCount ,
193222 }
194223 for _ , metric := range metricsList {
195224 if err := prometheus .Register (metric ); err != nil {
196225 log .Log (log .Metrics ).Warn ("failed to register metrics collector" , zap .Error (err ))
197226 }
198227 }
199- return s
200228}
201229
202230// Reset all metrics that implement the Reset functionality.
@@ -207,6 +235,7 @@ func (m *SchedulerMetrics) Reset() {
207235 m .applicationSubmission .Reset ()
208236 m .containerAllocation .Reset ()
209237 m .tryNodeCount .Reset ()
238+ m .tryApplicationCount .Reset ()
210239}
211240
212241func SinceInSeconds (start time.Time ) float64 {
@@ -284,8 +313,20 @@ func (m *SchedulerMetrics) GetSchedulingErrors() (int, error) {
284313 return - 1 , err
285314}
286315
287- func (m * SchedulerMetrics ) IncTryNodeCount () {
288- m .tryNodeCount .With (nil ).Inc ()
316+ func (m * SchedulerMetrics ) AddTryNodeCount (count int64 ) {
317+ m .tryNodeCount .With (nil ).Add (float64 (count ))
318+ }
319+
320+ func (m * SchedulerMetrics ) ResetTryNodeCount () {
321+ m .tryNodeCount .Reset ()
322+ }
323+
324+ func (m * SchedulerMetrics ) AddTryApplicationCount (count int64 ) {
325+ m .tryApplicationCount .With (nil ).Add (float64 (count ))
326+ }
327+
328+ func (m * SchedulerMetrics ) ResetTryApplicationCount () {
329+ m .tryApplicationCount .Reset ()
289330}
290331
291332func (m * SchedulerMetrics ) GetTryNodeCount () (int64 , error ) {
0 commit comments