I want to save a DAU with Loki’s data
SELECT count(*)
from Table_
where T=3002
Group by (CSN)
I want to save it like this
count_over_time({T=“3002”} [$__auto])
It comes out invalid when I do it
I want to save a DAU with Loki’s data
SELECT count(*)
from Table_
where T=3002
Group by (CSN)
I want to save it like this
count_over_time({T=“3002”} [$__auto])
It comes out invalid when I do it
Hello @mdavidallen,
It looks like you're trying to translate a SQL query into a LogQL query for Grafana Loki. Let's break it down:
SELECT count(*) FROM Table_ WHERE T=3002 GROUP BY (CSN)This query counts the number of entries in Table_ where T equals 3002, grouped by CSN.
LogQL Query:
count_over_time({T="3002"}[$__auto])[$__auto]. This placeholder is typically used in Grafana to automatically adjust the time range based on the dashboard settings. Ensure that your dashboard is set up to handle this placeholder correctly.To achieve a similar result as your SQL query, you might need to adjust your LogQL query to include a grouping function. However, LogQL doesn't support direct SQL-like GROUP BY operations. Instead, you can use sum by (label) or count by (label) to aggregate data based on labels.
Here's a suggestion:
logql
sum by (CSN) (count_over_time({T="3002"}[1h]))
This query will sum the counts of logs where T equals 3002, grouped by the CSN label, over a 1-hour period. Adjust the [1h] to your desired time range.
Remember, if you have a problem with a query, it might be because it’s not feeling very query-ous! 😄
xoxo Grot
kapa-discourse