Hi Appdynamics Community
I am creating extension using Powershell script for monitoring chrome session running in any particular application
I have created a script in the Powershell which is giving the desired output . But I have to make that script compatible to Appdynamics so that data can be shown in the form of Metrics and we can create Dashboard and Alert out of it .
This is the script I have created :-
[int]$runTimethreshold = 0
#Get all executing chrome processes
$allChromes = Get-Process chrome
## Code for Sorting the Output
$CPU = Get-Process chrome | Sort-Object -Property CPU | Select-Object -Last 20
$WS = Get-Process chrome | Sort-Object -Property WS | Select-Object -Last 20
$PM = Get-Process chrome | Sort-Object -Property PM | Select-Object -Last 20
#$MS = get-process chrome | select-object PrivateMemorySize, Description -Last 20
## Code to fetch the Parent Process ID
$ParentProcessIds = Get-CimInstance -Class Win32_Process -Filter "Name = 'chrome.exe'"
$s = Write-Output PPID $ParentProcessIds[0].ParentProcessId
#Code to fetch the thread which are in hung state
function Thread_Hung_State_Chrome ($waitProc, $idleTimeout) {
Get-CimInstance -Class Win32_Process -Filter "Name = 'chrome.exe'"
if($allChromes -eq $null){
$script:allChromes=New-Object -TypeName System.Collections.Stack
}
if($idleTimeout -gt 0){
$lastMemUsageCount=Get-chromeMemoryUsage $waitProc.ID
$memUsageStack.Push($lastMemUsageCount)
if($lastMemUsageCount -eq 0 -or (($memUsageStack.ToArray() | ? { $_ -ne $lastMemUsageCount }) -ne $null)){
$memUsageStack.Clear()
}
if($memUsageStack.Count -gt $idleTimeout){
KillTree $waitProc.ID
throw "TASK:`r`n$command`r`n`r`nIs likely in a hung state."
}
}
Start-Sleep -Second 1
}
$Thread = Thread_Hung_State_Chrome
## Code to post custom event when a chrome process is running for more than 10 mins (user defined)
## Iterate through all the chrome processes and find the elapsed time
foreach ($cp in $allChromes){
$startTime = $cp.StartTime
$elapsedTime = $(get-date) - $startTime }
#$totalTime = "{0:mm:ss}" -f ([datetime]$elapsedTime.Ticks)
$totalTime= [int]$elapsedTime.Minutes
## Code to post custom event when a chrome process is running for more than 10 mins
If ($totalTime -gt $runTimethreshold){
$id = $cp.Id
Write-Host Host_ID $cp.Id}
## Code for Printing the Output
Write-Output All_Chromes CustomMetric/Chromes $allChromes
Write-Output CPU_Usage CustomMetric/CPU $CPU
Write-Output Working_Set_Process CustomMetric/Working_Set_Process $WS
Write-Output Pageable_Memory CustomMetric/Pageable_Memory $PM
#Write-Output Chrome_MemorySize $MS
Write-Output Chrome_Thread_Hung_State CustomMetric/Hung_Threads $Thread
Write-Output Elapsed_Time CustomMetric/ $elapsedTime
Write-Output Total_Time CustomMetric/ $totalTime
Monitor .xml file which is created
<monitor>
<name>ChromeExtension</name>
<type>managed</type>
<description>Chrome Memory Usage </description>
<monitor-configuration>
</monitor-configuration>
<monitor-run-task>
<execution-style>continuous</execution-style>
<name>Run</name>
<type>executable</type>
<task-arguments>
</task-arguments>
<executable-task>
<type>file</type>
<file>Chrome_Test.ps</file>
</executable-task>
</monitor-run-task>
</monitor>
--> I have also made the necessary configuration and restarted the machine agent but desired result is not coming
-->> Please suggest where I am going wrong ..
Thanks
-------------------
Hi Appdynamics Community
I am creating extension using Powershell script for monitoring chrome session running in any particular application
I have created a script in the Powershell which is giving the desired output . But I have to make that script compatible to Appdynamics so that data can be shown in the form of Metrics and we can create Dashboard and Alert out of it .
This is the script I have created :-
[int]$runTimethreshold = 0
#Get all executing chrome processes
$allChromes = Get-Process chrome
## Code for Sorting the Output
$CPU = Get-Process chrome | Sort-Object -Property CPU | Select-Object -Last 20
$WS = Get-Process chrome | Sort-Object -Property WS | Select-Object -Last 20
$PM = Get-Process chrome | Sort-Object -Property PM | Select-Object -Last 20
#$MS = get-process chrome | select-object PrivateMemorySize, Description -Last 20
## Code to fetch the Parent Process ID
$ParentProcessIds = Get-CimInstance -Class Win32_Process -Filter "Name = 'chrome.exe'"
$s = Write-Output PPID $ParentProcessIds[0].ParentProcessId
#Code to fetch the thread which are in hung state
function Thread_Hung_State_Chrome ($waitProc, $idleTimeout) {
Get-CimInstance -Class Win32_Process -Filter "Name = 'chrome.exe'"
if($allChromes -eq $null){
$script:allChromes=New-Object -TypeName System.Collections.Stack
}
if($idleTimeout -gt 0){
$lastMemUsageCount=Get-chromeMemoryUsage $waitProc.ID
$memUsageStack.Push($lastMemUsageCount)
if($lastMemUsageCount -eq 0 -or (($memUsageStack.ToArray() | ? { $_ -ne $lastMemUsageCount }) -ne $null)){
$memUsageStack.Clear()
}
if($memUsageStack.Count -gt $idleTimeout){
KillTree $waitProc.ID
throw "TASK:`r`n$command`r`n`r`nIs likely in a hung state."
}
}
Start-Sleep -Second 1
}
$Thread = Thread_Hung_State_Chrome
## Code to post custom event when a chrome process is running for more than 10 mins (user defined)
## Iterate through all the chrome processes and find the elapsed time
foreach ($cp in $allChromes){
$startTime = $cp.StartTime
$elapsedTime = $(get-date) - $startTime }
#$totalTime = "{0:mm:ss}" -f ([datetime]$elapsedTime.Ticks)
$totalTime= [int]$elapsedTime.Minutes
## Code to post custom event when a chrome process is running for more than 10 mins
If ($totalTime -gt $runTimethreshold){
$id = $cp.Id
Write-Host Host_ID $cp.Id}
## Code for Printing the Output
Write-Output All_Chromes CustomMetric/Chromes $allChromes
Write-Output CPU_Usage CustomMetric/CPU $CPU
Write-Output Working_Set_Process CustomMetric/Working_Set_Process $WS
Write-Output Pageable_Memory CustomMetric/Pageable_Memory $PM
#Write-Output Chrome_MemorySize $MS
Write-Output Chrome_Thread_Hung_State CustomMetric/Hung_Threads $Thread
Write-Output Elapsed_Time CustomMetric/ $elapsedTime
Write-Output Total_Time CustomMetric/ $totalTime
Monitor .xml file which is created
<monitor>
<name>ChromeExtension</name>
<type>managed</type>
<description>Chrome Memory Usage </description>
<monitor-configuration>
</monitor-configuration>
<monitor-run-task>
<execution-style>continuous</execution-style>
<name>Run</name>
<type>executable</type>
<task-arguments>
</task-arguments>
<executable-task>
<type>file</type>
<file>Chrome_Test.ps</file>
</executable-task>
</monitor-run-task>
</monitor>
--> I have also made the necessary configuration and restarted the machine agent but desired result is not coming
-->> Please suggest where I am going wrong ..
Thanks
-------------------