[英]Performance Monitor: User defined Data Collector Sets Path
以下是您可以使用的 Powershell 代碼,您只需根據需要更改代碼和數據收集器中的路徑,它將自動使用代碼中給定的進程名稱啟動性能數據收集器
首先,如果代碼只是為了繞過任何主機的 powershell 中的腳本執行策略並以管理員權限運行腳本,則如果啟用了腳本執行,您可以刪除它
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs;}
Param(
[string]$name = "Test"
)
$datacollectorset = New-Object -COM Pla.DataCollectorSet
$datacollectorset.DisplayName = $name;
$datacollectorset.Duration = 14400 ;
$datacollectorset.SubdirectoryFormat = 1 ;
$datacollectorset.SubdirectoryFormatPattern = "yyyy\-MM";
$datacollectorset.RootPath = "%systemdrive%\PerfLogs\Admin\" + $name ;
$DataCollector = $datacollectorset.DataCollectors.CreateDataCollector(0)
$DataCollector.FileName = $name + "_";
$DataCollector.FileNameFormat = 0x1 ;
$DataCollector.FileNameFormatPattern = "yyyy\-MM\-dd";
$DataCollector.SampleInterval = 10
$counters = @(
"\Memory\Available MBytes",
"\Memory\Page Faults/sec",
"\Memory\Page Reads/sec",
"\Memory\Page Writes/sec",
"\Memory\Pages Input/sec",
"\Memory\Pages Output/sec",
"\Process(CloudHASHService)\*",
"\Processor(_Total)\% Idle Time",
"\Processor(_Total)\% Interrupt Time",
"\Processor(_Total)\% Privileged Time",
"\Processor(_Total)\% Processor Time",
"\Processor(_Total)\% User Time"
) ;
$DataCollector.PerformanceCounters = $counters
try
{
$datacollectorset.DataCollectors.Add($DataCollector)
$datacollectorset.Commit("$name" , $null , 0x0003) | Out-Null
$datacollectorset.Start($false);
}
catch [Exception]
{
Write-Host "Exception Caught: " $_.Exception -ForegroundColor Red
return
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.