|
|
@@ -6,36 +6,6 @@ import (
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
)
|
|
|
|
|
|
-//--------------------------------------------------------------------------
|
|
|
-// KubecostPodCollector
|
|
|
-//--------------------------------------------------------------------------
|
|
|
-
|
|
|
-// KubecostPodCollector is a prometheus collector that emits pod metrics
|
|
|
-type KubecostPodLabelsCollector struct {
|
|
|
- KubeClusterCache clustercache.ClusterCache
|
|
|
-}
|
|
|
-
|
|
|
-// Describe sends the super-set of all possible descriptors of metrics
|
|
|
-// collected by this Collector.
|
|
|
-func (kpmc KubecostPodLabelsCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
|
- ch <- prometheus.NewDesc("kube_pod_annotations", "All annotations for each pod prefix with annotation_", []string{}, nil)
|
|
|
-}
|
|
|
-
|
|
|
-// Collect is called by the Prometheus registry when collecting metrics.
|
|
|
-func (kpmc KubecostPodLabelsCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
- pods := kpmc.KubeClusterCache.GetAllPods()
|
|
|
- for _, pod := range pods {
|
|
|
- podName := pod.GetName()
|
|
|
- podNS := pod.GetNamespace()
|
|
|
-
|
|
|
- // Pod Annotations
|
|
|
- labels, values := prom.KubeAnnotationsToLabels(pod.Annotations)
|
|
|
- if len(labels) > 0 {
|
|
|
- ch <- newPodAnnotationMetric("kube_pod_annotations", podNS, podName, labels, values)
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
//--------------------------------------------------------------------------
|
|
|
// KubePodLabelsCollector
|
|
|
//--------------------------------------------------------------------------
|
|
|
@@ -71,7 +41,7 @@ func (kpmc KubePodLabelsCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
|
|
|
// Pod Labels
|
|
|
if _, disabled := disabledMetrics["kube_pod_labels"]; !disabled {
|
|
|
- labelNames, labelValues := prom.KubePrependQualifierToLabels(pod.GetLabels(), "label_")
|
|
|
+ labelNames, labelValues := prom.KubePrependQualifierToLabels(prom.SanitizeLabels(pod.GetLabels()), "label_")
|
|
|
ch <- newKubePodLabelsMetric("kube_pod_labels", podNS, podName, podUID, labelNames, labelValues)
|
|
|
}
|
|
|
|