go.ligato.io/vpp-agent/v3@v3.5.0/plugins/kvscheduler/metrics.go (about)

     1  //  Copyright (c) 2020 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package kvscheduler
    16  
    17  import (
    18  	"time"
    19  
    20  	"github.com/prometheus/client_golang/prometheus"
    21  
    22  	kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api"
    23  )
    24  
    25  // Set of raw Prometheus metrics.
    26  // Labels
    27  // * txn_type
    28  // * slice
    29  // Do not increment directly, use Report* methods.
    30  var (
    31  	transactionsProcessed = prometheus.NewCounter(prometheus.CounterOpts{
    32  		Namespace: "ligato",
    33  		Subsystem: "kvscheduler",
    34  		Name:      "txn_processed",
    35  		Help:      "The total number of transactions processed.",
    36  	})
    37  	transactionsDropped = prometheus.NewCounter(prometheus.CounterOpts{
    38  		Namespace: "ligato",
    39  		Subsystem: "kvscheduler",
    40  		Name:      "txn_dropped",
    41  		Help:      "The total number of transactions dropped.",
    42  	})
    43  	queueCapacity = prometheus.NewGauge(prometheus.GaugeOpts{
    44  		Namespace: "ligato",
    45  		Subsystem: "kvscheduler",
    46  		Name:      "queue_capacity",
    47  		Help:      "The capacity of the transactions queue.",
    48  	})
    49  	queueLength = prometheus.NewGauge(prometheus.GaugeOpts{
    50  		Namespace: "ligato",
    51  		Subsystem: "kvscheduler",
    52  		Name:      "queue_length",
    53  		Help:      "The number of transactions in the queue.",
    54  	})
    55  	queueWaitSeconds = prometheus.NewSummaryVec(prometheus.SummaryOpts{
    56  		Namespace: "ligato",
    57  		Subsystem: "kvscheduler",
    58  		Name:      "queue_wait_seconds",
    59  		Help:      "Wait time in queue for transactions.",
    60  		MaxAge:    time.Second * 30,
    61  	},
    62  		[]string{"txn_type"},
    63  	)
    64  	txnProcessDurationSeconds = prometheus.NewSummaryVec(prometheus.SummaryOpts{
    65  		Namespace: "ligato",
    66  		Subsystem: "kvscheduler",
    67  		Name:      "txn_process_duration_seconds",
    68  		Help:      "Processing time of transactions.",
    69  		MaxAge:    time.Second * 30,
    70  	},
    71  		[]string{"slice"},
    72  	)
    73  	txnDurationSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    74  		Namespace: "ligato",
    75  		Subsystem: "kvscheduler",
    76  		Name:      "txn_duration_seconds",
    77  		Help:      "Bucketed histogram of processing time of transactions by type.",
    78  	},
    79  		[]string{"txn_type"},
    80  	)
    81  )
    82  
    83  func init() {
    84  	prometheus.MustRegister(transactionsProcessed)
    85  	prometheus.MustRegister(transactionsDropped)
    86  	prometheus.MustRegister(queueCapacity)
    87  	prometheus.MustRegister(queueLength)
    88  	prometheus.MustRegister(queueWaitSeconds)
    89  	prometheus.MustRegister(txnProcessDurationSeconds)
    90  	prometheus.MustRegister(txnDurationSeconds)
    91  }
    92  
    93  func reportTxnProcessed(typ kvs.TxnType, sec float64) {
    94  	transactionsProcessed.Inc()
    95  	txnDurationSeconds.WithLabelValues(typ.String()).Observe(sec)
    96  }
    97  
    98  func reportTxnDropped() {
    99  	transactionsDropped.Inc()
   100  }
   101  
   102  func reportQueueCap(c int) {
   103  	queueCapacity.Set(float64(c))
   104  }
   105  
   106  func reportQueued(n int) {
   107  	queueLength.Add(float64(n))
   108  }
   109  
   110  func reportQueueWait(typ kvs.TxnType, sec float64) {
   111  	queueWaitSeconds.WithLabelValues(typ.String()).Observe(sec)
   112  }
   113  
   114  func reportTxnProcessDuration(slice string, sec float64) {
   115  	txnProcessDurationSeconds.WithLabelValues(slice).Observe(sec)
   116  }