Hi, with following query i get total number of logs by label “SipSessionId”.
That’s ok, but i would like to have in my stat graph just total number of “unique” SipSessionId labels.
Is this possible?
QUERY:
sum by (SipSessionId)(count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range]))
codi639
September 2, 2024, 11:28am
2
Could you show what you expect to have?
I would like to have a simple graph, like shown, that rapresents total number of “unique” sipsessionid labels.
codi639
September 2, 2024, 11:42am
4
Can you try the query:
count(count_over_time({origin="MYORIGIN", SipSessionId=~".+"}[$__range]) by (SipSessionId))
Your code give me an error.
I have to adjust like this:
count(count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range])) by (SipSessionId)
but I already tested and I realized that i get same identical result of using “sum by”
codi639
September 2, 2024, 11:47am
6
Okay, what else did you already try?
What’s the error?
Played around “count”… count by, sum, etc but cannot get what i need.
If you meant error related to your preview code, this is error:
{
“request”: {
“url”: “api/ds/query?ds_type=loki&requestId=Q936_1”,
“method”: “POST”,
“data”: {
“queries”: [
{
“datasource”: {
“type”: “loki”,
“uid”: “advz300kmjgg0e”
},
“editorMode”: “code”,
“expr”: “count(count_over_time({origin="MYORIGIN", SipSessionId=~".+"}[$__range]) by (SipSessionId))”,
“queryType”: “range”,
“refId”: “A”,
“legendFormat”: “”,
“maxLines”: 1000,
“datasourceId”: 58,
“intervalMs”: 60000,
“maxDataPoints”: 1179
}
],
“from”: “1725191357852”,
“to”: “1725277757852”
},
“hideFromInspector”: false
},
“response”: {
“results”: {
“A”: {
“error”: “invalid request”,
“errorSource”: “downstream”,
“status”: 500,
“refId”: “A”
}
}
}
}
codi639
September 2, 2024, 11:56am
8
Seems similar to this issue , can you take a look at it?
Tried but not luck.
See error. Always it returns “invalid request” and cannot understand why
QUERY:
count by (SipSessionId)(sum by (SipSessionId)(count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range])))
{
“request”: {
“url”: “api/ds/query?ds_type=loki&requestId=Q956_1”,
“method”: “POST”,
“data”: {
“queries”: [
{
“datasource”: {
“type”: “loki”,
“uid”: “advz300kmjgg0e”
},
“editorMode”: “code”,
“expr”: “count by (SipSessionId)(sum by (SipSessionId)(count_over_time({origin="MYORIGIN", SipSessionId=~".+"} [$__range])))”,
“queryType”: “instant”,
“refId”: “A”,
“legendFormat”: “”,
“maxLines”: 1000,
“datasourceId”: 58,
“intervalMs”: 86400000,
“maxDataPoints”: 1
}
],
“from”: “1725192327381”,
“to”: “1725278727381”
},
“hideFromInspector”: false
},
“response”: {
“results”: {
“A”: {
“error”: “invalid request”,
“errorSource”: “downstream”,
“status”: 500,
“refId”: “A”
}
}
}
}
codi639
September 2, 2024, 12:17pm
10
Ok, I’m not so good with Loki, sorry…
Looks like Loki’s having issue to count a sum (which makes sense…).
Why the result of your query:
sum by(SipSessionId)(count_over_time({origin="MYORIGIN", SipSessionId=~".+"} [$__range]))
doesn’t suit you? Looks like the total of unique labels to me…
This is what i need at the end.
Sound strange grafana cannot do this simple achivment.
codi639
September 2, 2024, 12:35pm
12
Okk! Make sense.
Can you show me what you get using:
count(count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range])) by (SipSessionId)
Also, I quite sure that keeping your actually query and adding a new transformation you can achieve the sum of each statement and get 6…
Also can you take a look at this ?
Using following query give me same identical result.
count(count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range])) by (SipSessionId)
Trying query of this link give me error on query. Alway same error of “ivalid request”
count(count(count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range])) by (SipSessionId))
codi639
September 2, 2024, 12:52pm
14
Well… I’m sorry but I’ll not be able to help you furthermore…
1 Like
Finally!!! Found solution with transformation!!
QUERY
count_over_time({origin=“MYORIGIN”, SipSessionId=~“.+”} [$__range])
2 Likes