Created
May 2, 2018 17:35
-
-
Save smarterclayton/92c7181473c6a948fb6221a86b9c4eff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// containerPrometheusLabels maps cAdvisor labels to prometheus labels. | |
func containerPrometheusLabels(c *cadvisorapi.ContainerInfo) map[string]string { | |
// Prometheus requires that all metrics in the same family have the same labels, | |
// so we arrange to supply blank strings for missing labels | |
var name, image, podName, namespace, containerName string | |
if len(c.Aliases) > 0 { | |
name = c.Aliases[0] | |
} | |
image = c.Spec.Image | |
if v, ok := c.Spec.Labels[kubelettypes.KubernetesPodNameLabel]; ok { | |
podName = v | |
} | |
if v, ok := c.Spec.Labels[kubelettypes.KubernetesPodNamespaceLabel]; ok { | |
namespace = v | |
} | |
if v, ok := c.Spec.Labels[kubelettypes.KubernetesContainerNameLabel]; ok { | |
containerName = v | |
} | |
if len(podName) == 0 { | |
if len(c.Subcontainers) > 0 { | |
if v, ok := c.Subcontainers[0].Labels[kubelettypes.KubernetesPodNameLabel]; ok { | |
podName = v | |
} | |
if v, ok := c.Subcontainers[0].Labels[kubelettypes.KubernetesPodNamespaceLabel]; ok { | |
namespace = v | |
} | |
} | |
} | |
set := map[string]string{ | |
metrics.LabelID: c.Name, | |
metrics.LabelName: name, | |
metrics.LabelImage: image, | |
"pod_name": podName, | |
"namespace": namespace, | |
"container_name": containerName, | |
} | |
return set | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment