Citrix will have you believe that that only way to find out how many Citrix Users you have connected, disconnected or in total, is via thier Edge suite. This is only correct if you only want to use Citrix to get the information. After some searching, it turns out that terminal services provides, via the PerfMon performance monitor (and hence probbaly via SNMP if you know how to query PerfMon stats via that), all three of these numbers. The only difference is that the PerfMon data comes with the Admin RDP sessions as well, rather then ‘normal’ Terminal Services client users, so you may need to reduce the count by 1-2, depending on whether you leave Admin RDP sessions connected.
I spent an interesting half an hour writing this, including researching how to write a Munin plugin. Unfortunately, after doing so, I took a closer look at the Munin For Windows sample config file, and included details of how to query these values directlly, so it was all a bit moot. However, this might be usefull for someone as a template of how to do so…
TerminalServicesUsers_plugin.ps1
#import the parameters, if any
param($Argument1)
#create an empty array since powershell wont do this for us
$TSUsers = @()
##function library
#get the individual performance counters for Total, Active and Inactive sessions and add to the $TSUsers array
function Get-TSUsers
{
$tscount = Get-Counter '\Terminal Services\Total Sessions'
$var = $tscount.CounterSamples[0].CookedValue
$TSUsers = $TSUsers + $var
$tscount = Get-Counter '\Terminal Services\Active Sessions'
$var = $tscount.CounterSamples[0].CookedValue
$TSUsers = $TSUsers + $var
$tscount = Get-Counter '\Terminal Services\Inactive Sessions'
$var = $tscount.CounterSamples[0].CookedValue
$TSUsers = $TSUsers + $var
#return the values
$TSUsers
}
#respond to the munin config command - see http://munin-monitoring.org/wiki/HowToWritePlugins
function Generate-MuninConfig
{
Write-Host "graph_title Terminsal Services Users
graph_vlabel No of Users
Total.label Total
Active.label Active
Inactive.label Inactive
Total.warning 18
Total.critical 20
Active.warning 18
Active.critical 20
Inactive.warning 10
Inactive.critical 20
"
}
function Generate-MuninData
{
$TSUsers = Get-TSUsers
#dump the array values
write-host "Total" $TSUsers[0]
write-host "Active" $TSUsers[1]
write-host "Inactive" $TSUsers[2]
}
##Main code starts here
switch ($Argument1)
{
config { Generate-MuninConfig }
#otherwise, generate the output
Default{ Generate-MuninData }
}
It strikes me someone might also be interested in the Munin config I used to query this information directly;
[PerfCounterPlugin_TSTotalUsers]
DropTotal=1
Object=Terminal Services
Counter=Total Sessions
CounterFormat=double
CounterMultiply=1.000000
GraphTitle=Total TS Users
GraphCategory=system
GraphDraw=LINE
[PerfCounterPlugin_TSActiveUsers]
DropTotal=1
Object=Terminal Services
Counter=Active Sessions
CounterFormat=double
CounterMultiply=1.000000
GraphTitle=Active TS Users
GraphCategory=system
GraphDraw=LINE
[PerfCounterPlugin_TSInactiveUsers]
DropTotal=1
Object=Terminal Services
Counter=Inactive Sessions
CounterFormat=double
CounterMultiply=1.000000
GraphTitle=Inactive TS Users
GraphCategory=system
GraphDraw=LINE
Add the above to your munin-node.conf on the server, and it will produce graphs like this in the system part of the machines report;

