Make Prometheus cAdvisor metrics labels consistent
Prometheus requires that all metrics in the same family have the same labels, so we arrange to supply blank strings for missing labels See https://github.com/google/cadvisor/issues/1704
This commit is contained in:
parent
7100d00491
commit
c193bbc7c2
@ -78,21 +78,29 @@ func init() {
|
||||
}
|
||||
|
||||
func containerLabels(c *cadvisorapi.ContainerInfo) map[string]string {
|
||||
set := map[string]string{metrics.LabelID: c.Name}
|
||||
// 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 {
|
||||
set[metrics.LabelName] = c.Aliases[0]
|
||||
}
|
||||
if image := c.Spec.Image; len(image) > 0 {
|
||||
set[metrics.LabelImage] = image
|
||||
name = c.Aliases[0]
|
||||
}
|
||||
image = c.Spec.Image
|
||||
if v, ok := c.Spec.Labels[types.KubernetesPodNameLabel]; ok {
|
||||
set["pod_name"] = v
|
||||
podName = v
|
||||
}
|
||||
if v, ok := c.Spec.Labels[types.KubernetesPodNamespaceLabel]; ok {
|
||||
set["namespace"] = v
|
||||
namespace = v
|
||||
}
|
||||
if v, ok := c.Spec.Labels[types.KubernetesContainerNameLabel]; ok {
|
||||
set["container_name"] = v
|
||||
containerName = 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
|
||||
}
|
||||
|
@ -813,21 +813,29 @@ func (a prometheusHostAdapter) GetMachineInfo() (*cadvisorapi.MachineInfo, error
|
||||
|
||||
// containerPrometheusLabels maps cAdvisor labels to prometheus labels.
|
||||
func containerPrometheusLabels(c *cadvisorapi.ContainerInfo) map[string]string {
|
||||
set := map[string]string{metrics.LabelID: c.Name}
|
||||
// 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 {
|
||||
set[metrics.LabelName] = c.Aliases[0]
|
||||
}
|
||||
if image := c.Spec.Image; len(image) > 0 {
|
||||
set[metrics.LabelImage] = image
|
||||
name = c.Aliases[0]
|
||||
}
|
||||
image = c.Spec.Image
|
||||
if v, ok := c.Spec.Labels[kubelettypes.KubernetesPodNameLabel]; ok {
|
||||
set["pod_name"] = v
|
||||
podName = v
|
||||
}
|
||||
if v, ok := c.Spec.Labels[kubelettypes.KubernetesPodNamespaceLabel]; ok {
|
||||
set["namespace"] = v
|
||||
namespace = v
|
||||
}
|
||||
if v, ok := c.Spec.Labels[kubelettypes.KubernetesContainerNameLabel]; ok {
|
||||
set["container_name"] = v
|
||||
containerName = 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user