there is WVDConnections table in Log Analytics with such data:
| DateTime | User | Session status |
|---|---|---|
| 09:20:39 | user3 | Completed |
| 09:05:41 | user3 | Connected |
| 09:05:07 | user3 | Started |
| 06:51:58 | user1 | Completed |
| 06:46:22 | user2 | Completed |
| 06:12:40 | user2 | Connected |
| 06:12:18 | user2 | Started |
| 05:36:11 | user1 | Connected |
| 05:35:37 | user1 | Started |
Session status:
Started - user initiated connection.
Connected - user connected.
Completed - user disconnected.
I need a timechart that displays time gaps then there is no connected users (display as 0) and user counts on the server in certain periods.
So in this case if taking 24 hours period from above table:
0 connections between 09:20:39 - 24:00:00
1 connection between 09:05:07 - 09:20:39
0 connections between 06:51:58 - 09:05:07
1 connection between 06:46:22 - 06:51:58
2 connections between 06:12:18 - 06:46:22
1 connection between 05:35:37 - 06:12:18
0 connections between 00:00:00 - 05:35:37
Now I have only this query
WVDConnections
| where TimeGenerated between (datetime(2024-02-26,00:00) .. datetime(2024-02-26,23:59))
| summarize dcount(UserName) by bin(TimeGenerated, 1h)
| render timechart
But it just counts number of users in 1 hours periods and never display 0 connection on the chart.
How to write the correct kusto query that displays 0 connections and correct user counts then they connects/disconnects?
this is another interesting one where KQL like all languages like this isn't great at showing you what isn't there. So you need to give it things that you know from the start, in this case I've assumed a
StartWindowandEndWindow.I have taken your code and question, added some additional variables and some extra testing source data. I've added in the source data an entry with just "Connected" (with
//***for visibility), you may want to comment that line out for testing.Otherwise hope it helps.