title: Prometheus - Aggregate and relabel by regex
body: <p>I currently have the following Promql query which allow me to query the memory used by each of my K8S pods:</p>
  
  <p><code>sum(container_memory_working_set_bytes{image!="",name=~"^k8s_.*"}) by (pod_name)</code></p>
  
  <p>The pod's name is followed by a hash defined by K8S:</p>
  
  <pre><code>weave-net-kxpxc
  weave-net-jjkki
  weave-net-asdkk
  </code></pre>
  
  <p>Which all belongs to the same app: <code>weave-net</code></p>
  
  <p>What I would like is to aggregate the memory of all pods which belongs to the same app. </p>
  
  <p>So, the query would sum the memory of all <code>weave-net</code> pods and place the result in an app called <code>weave</code>. Such as the result would be: </p>
  
  <pre><code>{pod_name="weave-net"}            10
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>{pod_name="weave-net-kxpxc"}       5
  {pod_name="weave-net-jjkki"}       3
  {pod_name="weave-net-asdkk"}       2
  </code></pre>
  
  <p>Is it even possible to do so, and if yes, how ? </p>