Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save daniloalsilva/571bce944ba5885848e161b1392e3f99 to your computer and use it in GitHub Desktop.

Select an option

Save daniloalsilva/571bce944ba5885848e161b1392e3f99 to your computer and use it in GitHub Desktop.
Script used to collect "Sensu-Client" statistics during defined execution time
# default ids
$sensuId = (Get-Process sensu-client).id
$rubyId = (gwmi win32_process | ? {$_.ParentProcessId -eq $sensuId}).ProcessId
# define execution in minutes
$initialTime = Get-Date
$execTime = $initialTime + [timespan]"0:05:00"
# create an empty hashtable
$procCount = @{}
# execute script until defined execTime
$result = while ((get-date) -lt $execTime){
# get inner process ids
$innerProcIds = (gwmi win32_process | ? {$_.ParentProcessId -eq $rubyId}).ProcessId
# collect all sensu derived process
#$procs = gwmi win32_process |
# ? {$_.ProcessId -match "$sensuId|$rubyId|$($innerProcIds -join '|')" -or $_.ParentProcessId -match "$sensuId|$rubyId|$($innerProcIds -join '|')"}
$procs = gwmi Win32_PerfFormattedData_PerfProc_Process |
? {$_.IDProcess -match "$sensuId|$rubyId|$($innerProcIds -join '|')" -or $_.CreatingProcessID -match "$sensuId|$rubyId|$($innerProcIds -join '|')"}
# list process not yet computed
$procs | ?{ $procCount[$_.IDProcess] -ne $true } | %{
$procCount[$_.IDProcess] = $true
[pscustomobject]@{
IDProcess = $_.IDProcess
Name = $_.Name
WorkingSet = $_.WorkingSet
"CPU (%)" = $_.PercentProcessorTime
WorkingSetPrivate = $_.WorkingSetPrivate
}
}
}
@{
InitialTime = $initialTime
FinishTime = $execTime
"Total Created Process" = $procCount.Count
"CPU Average" = (($result."CPU (%)" | measure -Average).Average)
"Sum_WorkingSet" = "{0:n2}" -f (($result.WorkingSet | measure -sum).sum / 1mb)
"Sum_WorkingSetPrivate" = "{0:n2}" -f (($result.WorkingSetPrivate | measure -sum).sum / 1mb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment