簡體   English   中英

性能監視器:用戶定義的數據收集器設置路徑

[英]Performance Monitor: User defined Data Collector Sets Path

如下圖,當我檢查任何用戶定義的數據收集器集(性能監視器)的“屬性”時,我可以看到一個“目錄”選項卡,它指的是它的路徑。

在此處輸入圖片說明

是否有任何 C# 代碼或 powershell 腳本或任何其他方式通過提供用戶定義的數據收集器集名稱來獲得相同的路徑? 謝謝!

以下是您可以使用的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM