#一般的なパフォーマンスカウンターの集計 $logpath = "C:\perflogs\Admin\HostLog\*.blg" $intervalhr = 24 $since = (Get-Date).AddHours(-1*$intervalhr) $logs = Get-ChildItem $logpath | Where-Object { $_.LastWriteTime -ge $since } | Sort-Object LastWriteTime -Descending $counters = @() foreach ($log in $logs) { $ret = $null if((get-item($log)).Length -gt 131072) { $ret = Import-Counter -Path $log.FullName -ErrorAction SilentlyContinue | Where-Object { $_.TimeStamp -ge $since } | Select-Object -Expand CounterSamples if ($ret -and $ret.Count -gt 0) { $counters += $ret } } } $perfcounters = @( "\Processor Information(*)\% Processor Time", "\Memory\Available MBytes", "\Memory\Pages/sec", "\Memory\Pool Nonpaged Bytes", "PhysicalDisk(*)\% Idle Time", "PhysicalDisk(*)\Avg. Disk sec/Read", "PhysicalDisk(*)\Avg. Disk sec/Write", "PhysicalDisk(*)\Disk Read Bytes/sec", "PhysicalDisk(*)\Disk Write Bytes/sec", "PhysicalDisk(*)\Disk Reads/sec", "PhysicalDisk(*)\Disk Writes/sec", "LogicalDisk(*)\% Idle Time", "LogicalDisk(*)\Avg. Disk sec/Read", "LogicalDisk(*)\Avg. Disk sec/Write", "LogicalDisk(*)\Disk Read Bytes/sec", "LogicalDisk(*)\Disk Write Bytes/sec", "LogicalDisk(*)\Disk Reads/sec", "LogicalDisk(*)\Disk Writes/sec", "Network Interface(*)\Bytes Total/sec", "Network Interface(*)\Output Queue Length", "Network Interface(*)\Packets Outbound Errors", "Network Interface(*)\Packets Received Errors" ) foreach ($perfcounter in $perfcounters) { $usage = $counters | Where-Object {$_.Path -like "*$perfcounter*" } | ForEach-Object { if ($_.TimeStamp -ge $since ) { [PSCustomObject]@{ Time = $_.TimeStamp Instance = $_.InstanceName Value = $_.CookedValue } } } $result = $usage | Group-Object { $_.Time.ToString("yyyy-MM-dd HH:00-59") },Instance | ForEach-Object { $values = $_.Group.Value [PSCustomObject]@{ Hour = $_.Name Avg = [math]::Round(($values | Measure-Object -Average).Average,2) Max = [math]::Round(($values | Measure-Object -Maximum).Maximum,2) Min = [math]::Round(($values | Measure-Object -Minimum).Minimum,2) } } $perfcounter $result | Sort-Object Hour | Format-Table -AutoSize }