How can I monitor the number of active Terminal Server sessions on a Windows Terminal Server?
Best Answer
In current PRTG versions, there are two dedicated sensors available out of the box for this purpose:
7 Replies
Hi, I wrote s small exe that can be used as a user defined program sensor. It needs a installed Microsoft Net 3.5 environment. Programm and source can be found here: http://www.obeco.de/termseraszip.exe
you could use a custom WMI sensor using these WQL querys
depending on the OS...
2003
Total Sessions
SELECT TotalSessions FROM Win32_PerfFormattedData_TermService_TerminalServices
Active Sessions
SELECT ActiveSessions FROM Win32_PerfFormattedData_TermService_TerminalServices
2008
Total Sessions
SELECT TotalSessions FROM Win32_TerminalService
Active Sessions
SELECT ActiveSessions FROM Win32_PerfFormattedData_LocalSessionManager_TerminalServices
In current PRTG versions, there are two dedicated sensors available out of the box for this purpose:
If you try the above WMI request or the WMI Sensor on a Server 2003 machine, you might find that it lies to you if you are using a non-admin account to make the request. You have to add the non-admin account to Remote Desktop Users on that machine.
This is not true on a Server 2008 machine. The numbers returned by a admin and non-admin account are both accurate without adding the non-admin to Remote Desktop Users. BTW, ActiveSessions doesn't exist in 2008 - there is DisconnectedSessions instead.
The non-admin account I use for PRTG monitoring has been added to DCOM Users, Performance Log Users, and Performance Monitor Users.
The EXE Advanced Sensor worked for us . We have several (35) RD Servers (2012) (Under the PRTG's Max of 50 Channels) and instead of having multiple sensor graphs, this script was created to scan all the servers and report back to one sensor graph. It works for Windows 2012 and 2008 servers.
Save this script to the C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML folder. (If the RDS.txt file can't be created when the script is run you may have to adjust the permissions on that folder.)
Add parameters/arguments to the sensor settings using quotes. The QWinsta program reports all sessions to a text file. The script than reads the text file and converts it into XML.
It creates a channel for Total users and each server with the number of logged in users. Options to include disconnected sessions and exclude user accounts. (Services account)
DIM XMLStart, XMLEnd, xmlResult, XmlTotal DIM strRDServer, TotalUsers Dim ArgObj, ARG Set ArgObj = WScript.Arguments XMLStart = "<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "Windows-1252" & chr(34) & " ?>" & vbCRLF & "<prtg>" & vbCRLF XMLEnd = "</prtg>" & vbCRLF XMLResult = "" for each ARG in ARGobj strRDServer = UCase(trim(ARG)) 'msgbox strRDServer AllUsers() next xmlTotal = "<result>" & vbCRLF & "<channel>" & "All Remote Users" & "</channel>" & vbCRLF xmlTotal = xmlTotal & "<value>" & TotalUsers & "</value>" & vbCRLF xmlTotal = xmlTotal & "</result>" XMLFinal = XMLStart & xmlTotal & xmlResult & XMLEnd wscript.echo XMLFinal Sub AllUsers strError = "" 'msgbox strRDServer Count = 0 xmlChannel = "" xmlValue = "" Set objShell = CreateObject("WScript.Shell") cmdQuery = "%comspec% /c QWinsta.exe /server:" & strRDServer & " > rds.txt" 'msgbox cmdQuery objshell.run cmdQuery,0,1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile1 = objFSO.OpenTextFile("rds.txt", 1) Do Until objFile1.AtEndOfStream strSessionID = objFile1.ReadLine if left(trim(strSessionID),8) <> "services" Then if inSTR(strSessionID,"Active") > 0 Then Count = Count + 1 end if if inSTR(strSessionID,"Disc") > 0 Then if instr(trim(strSessionID),".") = 0 or instr(trim(strSessionID),"administrator") = 1 then 'strError = strError & vbCRLF & "Unknown user" & vbtab & replace(trim(strSessionID)," Disc","") 'Count = Count + 1 'Optional else Count = Count + 1 end if end if end if Loop TotalUsers = TotalUsers + Count xmlChannel = "<channel>" & strRDServer & "</channel>" & vbCRLF xmlValue = "<value>" & Count & "</value>" & vbCRLF xmlResult = xmlResult & vbCRLF & "<result>" & vbCRLF & xmlChannel & xmlValue & "</result>" & vbCLRF end sub
Created on Apr 29, 2016 8:24:13 PM by
Glen Munro
(60)
●1
Last change on May 2, 2016 8:07:20 AM by
Torsten Lindner [Paessler Support]
This is exactly what I'd like to do, but the exe page is no longer there? Does anyone have a copy of the exe they can share?
Thanks, Mike
Hi Mike,
you don't need the exe file, as there are native PRTG sensors you can use for this purpose:
Kind regards,
Matthias Kupfer - Team Tech Support
Please log in or register to enter your reply.
Add comment