[英]Getting a count of distinct label values in prometheus/grafana
I am trying to create a table/chart in Grafana showing the total number of unique users who have logged in to a given application over a given time range (eg last 24 hours).我正在尝试在 Grafana 中创建一个表格/图表,显示在给定时间范围内(例如过去 24 小时)登录给定应用程序的唯一用户总数。 I have a metric,
app_request_path
which records the number of requests hitting a specific path per minute:我有一个指标
app_request_path
记录每分钟app_request_path
特定路径的请求数:
app_request_count{app="my-app", path="/login"}
This gives me the following:这给了我以下内容:
app_request_count{app="my-app",path="/login",status="200",username="username1"}
app_request_count{app="my-app",path="/login",status="200",username="username2"}
Now I want to count the number of unique usernames, so I run:现在我想计算唯一用户名的数量,所以我运行:
count_values("username", app_request_count{app="my_app", path="/login"})
and I get:我得到:
{username="0"}
{username="1"}
{username="2"}
{username="3"}
{username="4"}
{username="5"}
What am I missing / what am I doing wrong?我错过了什么/我做错了什么? Ideally I'd like to get a single scalar value that display the total number of unique usernames who have logged in in the past 24 hours.
理想情况下,我想获得一个标量值,显示过去 24 小时内登录的唯一用户名的总数。
Many thanks.非常感谢。
count without (username)(app_request_count)
count_values
is for metric values, count
is for time series. count_values
用于度量值, count
用于时间序列。 It's also not advised to have something like usernames as label values as they tend to be high cardinality.也不建议将用户名之类的东西作为标签值,因为它们往往是高基数。 They may also be PII, which could have legal implications.
它们也可能是 PII,这可能会产生法律影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.