> For the complete documentation index, see [llms.txt](https://zhangguanzhang.gitbook.io/prometheus-up-running/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zhangguanzhang.gitbook.io/prometheus-up-running/part-ii.-application-monitoring/5.-labels/what-are-labels.md).

# What Are Labels?

&#x20;       标签是与时间序列关联的键值对，除了度量标准名称之外，它还有唯一地标识来识别它们。 这有点拗口，让我们来看一个例子。 如果您有按路径划分的HTTP请求的度量标准，则可以尝试将该路径放在度量标准名称中，例如在Graphite中常见的:\
&#x20;    http\_requests\_login\_total\
&#x20;    http\_requests\_logout\_total\
&#x20;    http\_requests\_adduser\_total\
&#x20;    http\_requests\_comment\_total\
&#x20;    http\_requests\_view\_total

&#x20;       这回导致你很难在PromQL中使用它。 为了计算总请求，您需要知道每个可能的HTTP的metrics的名字，或者在所有度量标准名称中进行某种形式的潜在昂贵匹配。 因此，这是一个你应该避免的反模式。 相反，为了处理这个常见用例，prometheus有标签。 在上述情况下，您可以使用路径标签\
&#x20;    http\_requests\_total{path="/login"}\
&#x20;    http\_requests\_total{path="/logout"}\
&#x20;    http\_requests\_total{path="/adduser"}\
&#x20;    http\_requests\_total{path="/comment"}\
&#x20;    http\_requests\_total{path="/view"}

&#x20;       然后，您可以使用`http_requests_total`指标及其所有路径标签作为一个标签。 使用PromQL即可获得总体聚合请求比率，例如一个路径的速率，或每个请求的整体比例都可以利用标签统计出来。

&#x20;   您还可以拥有包含多个标签的指标。 标签上没有排序，因此您可以按任何给定标签进行聚合，同时忽略其他标签，甚至可以同时按几个标签聚合。\
\ <br>
