Hi,
I have a data like this:
product_sold = 120, {customer_name = ural, product_name = x}
product_sold = 121, {customer_name = nil, product_name = y}
product_sold = 123, {customer_name = ural, product_name = y}
product_sold = 127, {customer_name = nil, product_name = a}
product_sold = 132, {customer_name = tuna, product_name = b}
product_sold = 134, {customer_name = tuna, product_name = a}
It’s a prometheus counter. Cumulative data, never goes down, always up.
- I want to plot how it changes over time and ignore the customer_name and product_name.
- I want to plot how it changes over time in a minute (group by 1m), for a all customers (group by customer_name)
SELECT non_negative_difference(sum("product_sold")) FROM "db" WHERE $timeFilter GROUP BY time(1m) fill(null)
SELECT non_negative_difference(sum("product_sold")) FROM "db" WHERE $timeFilter GROUP BY time(1m), "customer_name" fill(null)
So, what I expect is that first query should sum all “product_sold” values in a time range in this case 1m.
Second query should do the same but for each customer and should return 3 values per minute since there are 3 customers in the example.
Can you help to query these two examples? I think, I did fine but the plot on grafana seems a bit off.
Another similar case:
I’m dealing with data called jvm_memory_bytes_used. This is a gauge metric and shows used memory. Has a tag called {area=“heap”, “nonheap”}
I want to sum this data by tag area. However, I don’t want to sum it over time. I only need to sum jvm_memory_bytes_used with same date. Of course timestamps will not be exactly same. So, I used subqueries.
SELECT percentile("Memory Used Raw",95) AS "Memory Used" FROM (SELECT sum("jvm_memory_bytes_used") AS "Memory Used Raw" FROM "db" WHERE $timeFilter GROUP BY time(10s) fill(previous)) GROUP BY time($sampling_interval)
Is this an overkill? Please, share if there is a better/efficient way to write this query.