If anyone stumbles into this question in the future, I wasn't able to solve the initial problem of monitoring my processes with perfmon so I setup a powershell script and a custom app, my app is configured as follows
local/inputs.conf
# Process Monitor script
[script://.\bin\myapp.path]
interval = 10
disabled = 0
#monitor output of proc
[monitor://$SPLUNK_HOME\var\log\myapp\proc.csv]
disabled = 0
sourcetype = myappProc
interval = 10
crcSalt = <SOURCE>
index = oswin
local/props.conf
[myappProc]
DATETIME_CONFIG = CURRENT
LINE_BREAKER = ([\r\n]+)
FIELD_DELIMITER = ,
FIELD_NAMES = Name,StartTime,cpu_user_percent,NPM,PM,WS(MB),WS,VM,PID,Path,user
FIELD_QUOTE = "
INDEXED_EXTRACTIONS = csv
NO_BINARY_CHECK = true
SHOULD_LINEMERGE = false
category = Custom
description = myapp Process Monitor
disabled = false
pulldown_type = true
bin/myapp.path
$SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe -command " & 'C:\Program Files\SplunkUniversalForwarder\etc\apps\myapp\bin\myappproc.ps1'"
bin/myappproc.ps1
$CPUPercent = @{
Name = 'CPU'
Expression = {
$TotalSec = (New-TimeSpan -Start $_.StartTime).TotalSeconds
[Math]::Round( ($_.CPU * 100 / $TotalSec), 3)
}
}
$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
Set-Variable -Name "LogFolder" -Value "C:\Program Files\SplunkUniversalForwarder\var\log\myapp"
Set-Variable -Name "MonitoredLogFile" -Value "C:\Program Files\SplunkUniversalForwarder\var\log\myapp\proc.csv"
if (!(Test-Path -Path $LogFolder )) {
New-Item -ItemType directory -Path $LogFolder
}
$Processes = Get-Process |
Where-Object -property Path -like "*MYAPP*"|
Select-Object -Property Name,StartTime, $CPUPercent,NPM,PM,{$_.WorkingSet /1mb},WS,VM,Id,Path,@{l="Owner";e={$owners[$_.id.tostring()]}} |
Select-Object
$output = ForEach ($Process in $Processes){
$Process
}
$output |ConvertTo-Csv -NoTypeInformation |Select-Object -Skip 1| Set-Content -Path $MonitoredLogFile
Hope this helps anyone who finds this.
... View more