title: How can I 'join' two metrics in a Prometheus query?
body: <p>I am using the <a href="https://github.com/prometheus/consul_exporter" rel="noreferrer">consul exporter</a> to ingest the health and status of my services into Prometheus. I'd like to fire alerts when the status of services and nodes in Consul is critical and then use tags extracted from Consul when routing those alerts.</p>
  
  <p>I understand from <a href="https://github.com/prometheus/consul_exporter/issues/45" rel="noreferrer">this discussion</a> that service tags are likely to be exported as a separate metric, but I'm not sure how to join one series with another so I can leverage the tags with the health status.</p>
  
  <p>For example, the following query:</p>
  
  <pre><code>max(consul_health_service_status{status="critical"}) by (service_name, status,node) == 1
  </code></pre>
  
  <p>could return:</p>
  
  <pre><code>{node="app-server-02",service_name="app-server",status="critical"} 1
  </code></pre>
  
  <p>but I'd also like 'env' from this series:</p>
  
  <pre><code>consul_service_tags{node="app-server-02",service_name="app-server",env="prod"} 1
  </code></pre>
  
  <p>to get joined along node and service_name to pass the following to the Alertmanager as a single series:</p>
  
  <pre><code>{node="app-server-02",service_name="app-server",status="critical",env="prod"} 1
  </code></pre>
  
  <p>I could then match 'env' in my routing.</p>
  
  <p>Is there any way to do this? It doesn't look to me like any operations or functions give me the ability to group or join like this. As far as I can see, the tags would already need to be labels on the consul_health_service_status metric.</p>