Cardinality

Cardinality refers to the number of unique elements in a set or the number of distinct values in a data set. In the context of metrics and time-series data, cardinality refers to the number of unique combinations of metric name, label name, and label value that are present in a data set.

For example, consider a metric called "http_requests_total" that is collected from a web server. The metric has two labels: "status" (with values "200" and "500") and "method" (with values "GET" and "POST"). The cardinality of this metric would be 4, because there are 4 unique combinations of label values (200 GET, 200 POST, 500 GET, and 500 POST).

Another example is a metric called "cpu_usage" that is collected from a server. The metric has one label "host" (with values "host1","host2","host3"). The cardinality of this metric would be 3, because there are 3 unique host values.

Cardinality is an important consideration in metrics and monitoring, because high cardinality can lead to increased storage and memory usage, and can make it more difficult to query and visualize metrics. Therefore, it is important to keep an eye on cardinality when designing metrics and monitoring systems, and consider techniques such as data downsampling or aggregation to reduce cardinality.