I deploy prometheus2.0 in kubernetes,and then I need to known every pods memory usage. I find two metrics: container_memory_usage_bytes and kube_pod_container_resource_limits_memory_bytes, and the sum(container_memory_usage_bytes) by (pod_name) show pods memory used bytes which already consumed ,the sum(kube_pod_container_resource_limits_memory_bytes) by (pod) show pods memory limits which config by kubernetes, I just to compute this two values then I can get all pods memory usage.
But this two metrics show different vector name , see below
sum(kube_pod_container_resource_limits_memory_bytes) by (pod)
Element Value
{pod="calico-node-lwmk4"} 536870912
{pod="security-1-0-1857679549-cbg5m"} 4294967296
{pod="msi-joomla-1-0-2319985720-kvjlg"} 536870912
sum(container_memory_usage_bytes) By (pod_name)
Element Value
{pod_name="calico-node-lwmk4"} 90996736
{pod_name="security-1-0-1857679549-cbg5m"} 627601408
{pod_name="msi-joomla-1-0-2319985720-kvjlg"} 59744665
how could I get usage with this two metrics by using PromQL?
You can handle this is a few ways. The best is with metric_relabel_configs for cadvisor (as cadvisor is the one not following the naming convention):
metric_relabel_configs:
- source_labels: [pod_name] # Copy pod_name to pod
target_label: pod
- replacement: '' # Remove pod_name label by setting it to empty
target_label: pod_name