Go to All Forums

Record the number of users

We are looking to monitor the number of users logged into a given system at a time. This would help us review periods of peek usage and correlate that to the number of users logged in at that particular time.

I can do this from the powershell prompt on windows:

(quser | measure | select -ExpandProperty count)-1

Thank you,
Like (1) Reply
Replies (5)

Dear Brose,

    Custom plugins is the way to go for this. Since you already know the command, you just have to get this in a ps1 file and need construct the json. 

I have created a powershell script that will do this. Name it as noofusers.ps1 (or anyother name of your choice)

Function Add-Data([string]$json,[string]$key,[string]$value,[bool]$isobj) {
   if($key -ne $null -and $value -ne $null) {
     if($json.Length -gt 0){
       $json = $json -replace "(.*)}(.*)", '$1,$2'
     } else {
$json = $json + "{"
  if($isobj -eq $true) {
   $json = $json + [char]34 + $key + [char]34 + " : " + $value +"}"
} else {
  $json = $json + [char]34 + $key + [char]34 + " : " + [char]34 + $value + [char]34 +"}"
return $json
$noofUsersLoggedIn = (quser.exe 2>&1 | measure | select -ExpandProperty count)-1

$version = "1"

$displayname = "User Logins"

$heartbeat = "True"

$units = ""

$data = ""
$data = Add-Data $data "No of User Logins" $noofUsersLoggedIn

$mainJson = ""
$mainJson = Add-Data $mainJson "version" $version
$mainJson = Add-Data $mainJson "data" $data $true
$mainJson = Add-Data $mainJson "displayname" $displayname

return $mainJson

All you have to do now is put this ps1 file in C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\noofusers\noofusers.ps1. 

Make sure the plugin folder name and the file name are same.

Restart the plugin service once. Also remember to set the execution policy to remotesigned. 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned 

You will then get the no.of users that have logged to a server. The plugin is run as per the polling interval you have set.


Product Manager, Site24x7

Like (0) Reply

Thank you for the custom plugin, and that is very helpful!

I was hoping that this would be a built-in measured value in the future.

Like (0) Reply

Glad that you found this helpful, Brose. We give performance monitoring data as part of our built-in set of attributes but no.of users who accessed the server is not a performance data per se. However, we'll add this to our roadmap and based on feedback we'll bring it in. Hope this makes sense. 


Product Manager, Site24x7

Like (0) Reply

Sounds great... I also updated the code slightly to handle when 0 users are logged in

 $noofUsersLoggedIn = (quser.exe 2>&1 | measure | select -ExpandProperty count)-1
Like (0) Reply

Thanks Brose. I've updated the script accordingly as well. 


Like (0) Reply

Was this post helpful?