...

Source file src/edge-infra.dev/pkg/f8n/warehouse/k8s/controllers/lumperctl/internal/metrics.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/k8s/controllers/lumperctl/internal

     1  package internal
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  
     7  	"github.com/prometheus/client_golang/prometheus"
     8  
     9  	"edge-infra.dev/pkg/k8s/runtime/controller/metrics"
    10  )
    11  
    12  var (
    13  	// CacheReadOpsMetric metric for total reads from cache.
    14  	CacheReadOpsMetric prometheus.CounterVec = *prometheus.NewCounterVec(
    15  		prometheus.CounterOpts{
    16  			Name: metrics.Name("lpctl", "cache_get_count"),
    17  			Help: "Custom cache read operations metric for lumperctl",
    18  		},
    19  		[]string{"result", "provider", "obj_type"})
    20  
    21  	// CacheWriteOpsMetric metric for total writes to cache.
    22  	CacheWriteOpsMetric prometheus.CounterVec = *prometheus.NewCounterVec(
    23  		prometheus.CounterOpts{
    24  			Name: metrics.Name("lpctl", "cache_write_ops"),
    25  			Help: "Custom cache write operations metric for lumperctl",
    26  		},
    27  		[]string{"provider"})
    28  
    29  	// CacheReadLatencyMetric metric for the read latency in milliseconds to read an artifact from the cache.
    30  	CacheReadLatencyMetric prometheus.HistogramVec = *prometheus.NewHistogramVec(
    31  		prometheus.HistogramOpts{
    32  			Name:    metrics.Name("lpctl", "cache_read_latency_count"),
    33  			Help:    "Custom cache read latency metric for lumperctl",
    34  			Buckets: prometheus.LinearBuckets(20, 5, 5),
    35  		},
    36  		[]string{"provider"})
    37  
    38  	// CacheWriteLatencyMetric metric for the write latency in milliseconds to add a new artifact in the cache.
    39  	CacheWriteLatencyMetric prometheus.HistogramVec = *prometheus.NewHistogramVec(
    40  		prometheus.HistogramOpts{
    41  			Name:    metrics.Name("lpctl", "cache_write_latency_count"),
    42  			Help:    "Custom cache write latency metric for lumperctl",
    43  			Buckets: prometheus.LinearBuckets(20, 5, 5),
    44  		},
    45  		[]string{"provider"})
    46  
    47  	// CacheLenMetric metric for the total count of artifacts in the cache.
    48  	CacheLenMetric prometheus.GaugeVec = *prometheus.NewGaugeVec(
    49  		prometheus.GaugeOpts{
    50  			Name: metrics.Name("lpctl", "cache_len_count"),
    51  			Help: "Custom cache length metric for lumperctl",
    52  		},
    53  		[]string{"provider"})
    54  
    55  	// CacheUtilizationMetric metric for the percentage utilization of the allocated total cache memory.
    56  	CacheUtilizationMetric prometheus.GaugeVec = *prometheus.NewGaugeVec(
    57  		prometheus.GaugeOpts{
    58  			Name: metrics.Name("lpctl", "cache_utilization_percentage"),
    59  			Help: "Custom cache utilization percentage metric for lumperctl",
    60  		},
    61  		[]string{"provider"})
    62  
    63  	// EdgeVersionMetric metric for the edge version of an unpackedpallet.
    64  	EdgeVersionMetric prometheus.GaugeVec = *prometheus.NewGaugeVec(
    65  		prometheus.GaugeOpts{
    66  			Name: metrics.Name("lpctl", "edge_version"),
    67  			Help: "Custom lumperctl metric for recording edge version of an unpackedpallet",
    68  		},
    69  		[]string{"name", "version"})
    70  )
    71  
    72  type CacheRecorder struct{}
    73  
    74  func (r CacheRecorder) RecordGet(hit bool, provider string, objType string) {
    75  	CacheReadOpsMetric.WithLabelValues(strconv.FormatBool(hit), provider, objType).Inc()
    76  }
    77  
    78  func RecordCacheLen(val float64) {
    79  	CacheLenMetric.WithLabelValues("memory").Set(val)
    80  }
    81  
    82  func RecordEdgeVersion(name, version string, deleted bool) {
    83  	// Delete metrics for this object to reset the observed version.
    84  	// If the unpackedpallet has been deleted, exit before recording.
    85  	EdgeVersionMetric.DeletePartialMatch(prometheus.Labels{"name": name})
    86  	if deleted {
    87  		return
    88  	}
    89  	v := strings.Split(version, "-")[0]
    90  	EdgeVersionMetric.WithLabelValues(name, v).Set(1)
    91  }
    92  

View as plain text