volcano.sh/volcano@v1.9.0/pkg/scheduler/metrics/queue.go (about)

     1  /*
     2  Copyright 2020 The Volcano Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package metrics
    18  
    19  import (
    20  	"github.com/prometheus/client_golang/prometheus"
    21  	"github.com/prometheus/client_golang/prometheus/promauto" // auto-registry collectors in default registry
    22  )
    23  
    24  var (
    25  	queueAllocatedMilliCPU = promauto.NewGaugeVec(
    26  		prometheus.GaugeOpts{
    27  			Subsystem: VolcanoNamespace,
    28  			Name:      "queue_allocated_milli_cpu",
    29  			Help:      "Allocated CPU count for one queue",
    30  		}, []string{"queue_name"},
    31  	)
    32  
    33  	queueAllocatedMemory = promauto.NewGaugeVec(
    34  		prometheus.GaugeOpts{
    35  			Subsystem: VolcanoNamespace,
    36  			Name:      "queue_allocated_memory_bytes",
    37  			Help:      "Allocated memory for one queue",
    38  		}, []string{"queue_name"},
    39  	)
    40  
    41  	queueRequestMilliCPU = promauto.NewGaugeVec(
    42  		prometheus.GaugeOpts{
    43  			Subsystem: VolcanoNamespace,
    44  			Name:      "queue_request_milli_cpu",
    45  			Help:      "Request CPU count for one queue",
    46  		}, []string{"queue_name"},
    47  	)
    48  
    49  	queueRequestMemory = promauto.NewGaugeVec(
    50  		prometheus.GaugeOpts{
    51  			Subsystem: VolcanoNamespace,
    52  			Name:      "queue_request_memory_bytes",
    53  			Help:      "Request memory for one queue",
    54  		}, []string{"queue_name"},
    55  	)
    56  
    57  	queueDeservedMilliCPU = promauto.NewGaugeVec(
    58  		prometheus.GaugeOpts{
    59  			Subsystem: VolcanoNamespace,
    60  			Name:      "queue_deserved_milli_cpu",
    61  			Help:      "Deserved CPU count for one queue",
    62  		}, []string{"queue_name"},
    63  	)
    64  
    65  	queueDeservedMemory = promauto.NewGaugeVec(
    66  		prometheus.GaugeOpts{
    67  			Subsystem: VolcanoNamespace,
    68  			Name:      "queue_deserved_memory_bytes",
    69  			Help:      "Deserved memory for one queue",
    70  		}, []string{"queue_name"},
    71  	)
    72  
    73  	queueShare = promauto.NewGaugeVec(
    74  		prometheus.GaugeOpts{
    75  			Subsystem: VolcanoNamespace,
    76  			Name:      "queue_share",
    77  			Help:      "Share for one queue",
    78  		}, []string{"queue_name"},
    79  	)
    80  
    81  	queueWeight = promauto.NewGaugeVec(
    82  		prometheus.GaugeOpts{
    83  			Subsystem: VolcanoNamespace,
    84  			Name:      "queue_weight",
    85  			Help:      "Weight for one queue",
    86  		}, []string{"queue_name"},
    87  	)
    88  
    89  	queueOverused = promauto.NewGaugeVec(
    90  		prometheus.GaugeOpts{
    91  			Subsystem: VolcanoNamespace,
    92  			Name:      "queue_overused",
    93  			Help:      "If one queue is overused",
    94  		}, []string{"queue_name"},
    95  	)
    96  
    97  	queuePodGroupInqueue = promauto.NewGaugeVec(
    98  		prometheus.GaugeOpts{
    99  			Subsystem: VolcanoNamespace,
   100  			Name:      "queue_pod_group_inqueue_count",
   101  			Help:      "The number of Inqueue PodGroup in this queue",
   102  		}, []string{"queue_name"},
   103  	)
   104  
   105  	queuePodGroupPending = promauto.NewGaugeVec(
   106  		prometheus.GaugeOpts{
   107  			Subsystem: VolcanoNamespace,
   108  			Name:      "queue_pod_group_pending_count",
   109  			Help:      "The number of Pending PodGroup in this queue",
   110  		}, []string{"queue_name"},
   111  	)
   112  
   113  	queuePodGroupRunning = promauto.NewGaugeVec(
   114  		prometheus.GaugeOpts{
   115  			Subsystem: VolcanoNamespace,
   116  			Name:      "queue_pod_group_running_count",
   117  			Help:      "The number of Running PodGroup in this queue",
   118  		}, []string{"queue_name"},
   119  	)
   120  
   121  	queuePodGroupUnknown = promauto.NewGaugeVec(
   122  		prometheus.GaugeOpts{
   123  			Subsystem: VolcanoNamespace,
   124  			Name:      "queue_pod_group_unknown_count",
   125  			Help:      "The number of Unknown PodGroup in this queue",
   126  		}, []string{"queue_name"},
   127  	)
   128  )
   129  
   130  // UpdateQueueAllocated records allocated resources for one queue
   131  func UpdateQueueAllocated(queueName string, milliCPU, memory float64) {
   132  	queueAllocatedMilliCPU.WithLabelValues(queueName).Set(milliCPU)
   133  	queueAllocatedMemory.WithLabelValues(queueName).Set(memory)
   134  }
   135  
   136  // UpdateQueueRequest records request resources for one queue
   137  func UpdateQueueRequest(queueName string, milliCPU, memory float64) {
   138  	queueRequestMilliCPU.WithLabelValues(queueName).Set(milliCPU)
   139  	queueRequestMemory.WithLabelValues(queueName).Set(memory)
   140  }
   141  
   142  // UpdateQueueDeserved records deserved resources for one queue
   143  func UpdateQueueDeserved(queueName string, milliCPU, memory float64) {
   144  	queueDeservedMilliCPU.WithLabelValues(queueName).Set(milliCPU)
   145  	queueDeservedMemory.WithLabelValues(queueName).Set(memory)
   146  }
   147  
   148  // UpdateQueueShare records share for one queue
   149  func UpdateQueueShare(queueName string, share float64) {
   150  	queueShare.WithLabelValues(queueName).Set(share)
   151  }
   152  
   153  // UpdateQueueWeight records weight for one queue
   154  func UpdateQueueWeight(queueName string, weight int32) {
   155  	queueWeight.WithLabelValues(queueName).Set(float64(weight))
   156  }
   157  
   158  // UpdateQueueOverused records if one queue is overused
   159  func UpdateQueueOverused(queueName string, overused bool) {
   160  	var value float64
   161  	if overused {
   162  		value = 1
   163  	} else {
   164  		value = 0
   165  	}
   166  	queueOverused.WithLabelValues(queueName).Set(value)
   167  }
   168  
   169  // UpdateQueuePodGroupInqueueCount records the number of Inqueue PodGroup in this queue
   170  func UpdateQueuePodGroupInqueueCount(queueName string, count int32) {
   171  	queuePodGroupInqueue.WithLabelValues(queueName).Set(float64(count))
   172  }
   173  
   174  // UpdateQueuePodGroupPendingCount records the number of Pending PodGroup in this queue
   175  func UpdateQueuePodGroupPendingCount(queueName string, count int32) {
   176  	queuePodGroupPending.WithLabelValues(queueName).Set(float64(count))
   177  }
   178  
   179  // UpdateQueuePodGroupRunningCount records the number of Running PodGroup in this queue
   180  func UpdateQueuePodGroupRunningCount(queueName string, count int32) {
   181  	queuePodGroupRunning.WithLabelValues(queueName).Set(float64(count))
   182  }
   183  
   184  // UpdateQueuePodGroupUnknownCount records the number of Unknown PodGroup in this queue
   185  func UpdateQueuePodGroupUnknownCount(queueName string, count int32) {
   186  	queuePodGroupUnknown.WithLabelValues(queueName).Set(float64(count))
   187  }
   188  
   189  // DeleteQueueMetrics delete all metrics related to the queue
   190  func DeleteQueueMetrics(queueName string) {
   191  	queueAllocatedMilliCPU.DeleteLabelValues(queueName)
   192  	queueAllocatedMemory.DeleteLabelValues(queueName)
   193  	queueRequestMilliCPU.DeleteLabelValues(queueName)
   194  	queueRequestMemory.DeleteLabelValues(queueName)
   195  	queueDeservedMilliCPU.DeleteLabelValues(queueName)
   196  	queueDeservedMemory.DeleteLabelValues(queueName)
   197  	queueShare.DeleteLabelValues(queueName)
   198  	queueWeight.DeleteLabelValues(queueName)
   199  	queueOverused.DeleteLabelValues(queueName)
   200  	queuePodGroupInqueue.DeleteLabelValues(queueName)
   201  	queuePodGroupPending.DeleteLabelValues(queueName)
   202  	queuePodGroupRunning.DeleteLabelValues(queueName)
   203  	queuePodGroupUnknown.DeleteLabelValues(queueName)
   204  }