containerized-data-importer/pkg/monitoring/metrics/cdi-controller/storageprofile.go
Aviv Litman 42ec627e35
Refactor recording-rules and alerts code (#3068)
* Refactor recording-rules and alerts code

Signed-off-by: avlitman <alitman@redhat.com>

* Remove promv1 from schema

Signed-off-by: avlitman <alitman@redhat.com>

---------

Signed-off-by: avlitman <alitman@redhat.com>
2024-02-18 16:05:42 +01:00

63 lines
2.0 KiB
Go

package cdicontroller
import (
"github.com/machadovilaca/operator-observability/pkg/operatormetrics"
"github.com/prometheus/client_golang/prometheus"
ioprometheusclient "github.com/prometheus/client_model/go"
)
const (
counterLabelStorageClass = "storageclass"
counterLabelProvisioner = "provisioner"
counterLabelComplete = "complete"
counterLabelDefault = "default"
counterLabelVirtDefault = "virtdefault"
counterLabelRWX = "rwx"
counterLabelSmartClone = "smartclone"
)
var (
storageMetrics = []operatormetrics.Metric{
storageProfileStatus,
}
storageProfileStatus = operatormetrics.NewGaugeVec(
operatormetrics.MetricOpts{
Name: "kubevirt_cdi_storageprofile_info",
Help: "`StorageProfiles` info labels: " +
"`storageclass`, `provisioner`, " +
"`complete` indicates if all storage profiles recommended PVC settings are complete, " +
"`default` indicates if it's the Kubernetes default storage class, " +
"`virtdefault` indicates if it's the default virtualization storage class, " +
"`rwx` indicates if the storage class supports `ReadWriteMany`, " +
"`smartclone` indicates if it supports snapshot or CSI based clone",
},
[]string{
counterLabelStorageClass,
counterLabelProvisioner,
counterLabelComplete,
counterLabelDefault,
counterLabelVirtDefault,
counterLabelRWX,
counterLabelSmartClone,
},
)
)
// SetStorageProfileStatus sets storageProfileStatus value
func SetStorageProfileStatus(labels prometheus.Labels, status int) {
storageProfileStatus.With(labels).Set(float64(status))
}
// GetStorageProfileStatus returns the storageProfileStatus value
func GetStorageProfileStatus(labels prometheus.Labels) float64 {
dto := &ioprometheusclient.Metric{}
_ = storageProfileStatus.With(labels).Write(dto)
return dto.Gauge.GetValue()
}
// DeleteStorageProfileStatus deletes metrics by their labels, and return the number of deleted metrics
func DeleteStorageProfileStatus(labels prometheus.Labels) int {
return storageProfileStatus.DeletePartialMatch(labels)
}