title: How to get the count of distinct values for a certain label in prometheus?
body: <p>We are monitoring kafka consumers with prometheus and grafana by drawing a consuming rate curve per topic and partition. We noticed that a consumer for some partition may stop working because of some error. It would be convenient to add an alert if there is some function that counts the number of distinct partitions (as a label value) that's being consumed.</p>
  
  <p>Update:</p>
  
  <p>We have a time series like this:</p>
  
  <pre><code>consume_rate_count{topic="my-kafka-topic",partition="0"} 320 1495164869031
  consume_rate_count{topic="my-kafka-topic",partition="1"} 316 1495164869031
  consume_rate_count{topic="my-kafka-topic",partition="2"} 331 1495164869031
  consume_rate_count{topic="my-kafka-topic",partition="3"} 322 1495164869031
  </code></pre>
  
  <p>And we're looking for way to get the count of distinct partitions with a positive consume rate. So if we get the following data, an alert will be trigger, because we have 4 partitions in total, but only 3 of them is being consumed.</p>
  
  <pre><code>consume_rate_count{topic="my-kafka-topic",partition="0"} 320 1495164869031
  consume_rate_count{topic="my-kafka-topic",partition="1"} 316 1495164869031
  consume_rate_count{topic="my-kafka-topic",partition="2"} 0   1495164869031
  consume_rate_count{topic="my-kafka-topic",partition="3"} 322 1495164869031
  </code></pre>