I have special request to monitor the following on a Citrix server. We notice that sometimes certain processes are still running in the background although the application is closed within the Citrix session.
- for one separate process (eg. excel.exe)
- cpu usage (eg 20%)
- for a certain amount of time (eg 15 minutes)
- and for which user
It would be great if someone could help me with this. I found limited information on this in the forums, hence my new question.
I'm looking to have both syntax and trigger for Zabbix.
I think to have this monitored with a Powershell script, but I'm not sure if all is correct:
---BEGIN---
Param([string]$ProcessName, [int]$SelectFirst, [switch]$GridView)
If (! $ProcessName) { $ProcessName = '*' }
If (! $SelectFirst) { $SelectFirst = 5 }
If ($ProcessName -eq '*') {
$ProcessList = gwmi Win32_PerfFormattedData_PerfProc_Process | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -First $SelectFirst
}
Else {
$ProcessList = gwmi Win32_PerfFormattedData_PerfProc_Process | where {$_.Name -eq $ProcessName} | select IDProcess,Name,PercentProcessorTime | sort PercentProcessorTime -Descending | select -First $SelectFirst
}
$TopProcess = @()
ForEach ($Process in $ProcessList) {
$row = new-object PSObject -Property @{
Id = $Process.IDProcess
Name = $Process.Name
User = (gwmi Win32_Process | where {$_.ProcessId -eq $Process.IDProcess}).GetOwner().User
CPU = $Process.PercentProcessorTime
Description = (Get-Process -Id $Process.IDProcess).Description
}
$TopProcess += $row
}
If ($GridView) {
$TopProcess | sort CPU -Descending | select Id,Name,User,CPU,Description | Out-GridView
}
Else {
$TopProcess | sort CPU -Descending | select Id,Name,User,CPU,Description | ft -AutoSize
}
----END----
example output:
PS C:\Users\kevin\Documents\_Desktop> .\process.ps1
Id Name User CPU Description
-- ---- ---- --- -----------
1920 firefox kevin 6 Firefox
2092 srvany 0
2140 srvany#1 0
668 stacsv64 0
4448 sttray64 kevin 0 IDT PC Audio
Any help or advise is welcome!
Kev
- for one separate process (eg. excel.exe)
- cpu usage (eg 20%)
- for a certain amount of time (eg 15 minutes)
- and for which user
It would be great if someone could help me with this. I found limited information on this in the forums, hence my new question.
I'm looking to have both syntax and trigger for Zabbix.
I think to have this monitored with a Powershell script, but I'm not sure if all is correct:
---BEGIN---
Param([string]$ProcessName, [int]$SelectFirst, [switch]$GridView)
If (! $ProcessName) { $ProcessName = '*' }
If (! $SelectFirst) { $SelectFirst = 5 }
If ($ProcessName -eq '*') {
$ProcessList = gwmi Win32_PerfFormattedData_PerfProc_Process | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -First $SelectFirst
}
Else {
$ProcessList = gwmi Win32_PerfFormattedData_PerfProc_Process | where {$_.Name -eq $ProcessName} | select IDProcess,Name,PercentProcessorTime | sort PercentProcessorTime -Descending | select -First $SelectFirst
}
$TopProcess = @()
ForEach ($Process in $ProcessList) {
$row = new-object PSObject -Property @{
Id = $Process.IDProcess
Name = $Process.Name
User = (gwmi Win32_Process | where {$_.ProcessId -eq $Process.IDProcess}).GetOwner().User
CPU = $Process.PercentProcessorTime
Description = (Get-Process -Id $Process.IDProcess).Description
}
$TopProcess += $row
}
If ($GridView) {
$TopProcess | sort CPU -Descending | select Id,Name,User,CPU,Description | Out-GridView
}
Else {
$TopProcess | sort CPU -Descending | select Id,Name,User,CPU,Description | ft -AutoSize
}
----END----
example output:
PS C:\Users\kevin\Documents\_Desktop> .\process.ps1
Id Name User CPU Description
-- ---- ---- --- -----------
1920 firefox kevin 6 Firefox
2092 srvany 0
2140 srvany#1 0
668 stacsv64 0
4448 sttray64 kevin 0 IDT PC Audio
Any help or advise is welcome!
Kev
Comment