简体   繁体   English

性能监视器:用户定义的数据收集器设置路径

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

As picture below, when I am checking"Properties" for any user defined Data Collector sets (Performance Monitor), I can see a "Directory" tab which refers the Path for it.如下图,当我检查任何用户定义的数据收集器集(性能监视器)的“属性”时,我可以看到一个“目录”选项卡,它指的是它的路径。

在此处输入图片说明

Is there any C# code or powershell script or any other way to get the same path by just providing user defined Data Collector sets name?是否有任何 C# 代码或 powershell 脚本或任何其他方式通过提供用户定义的数据收集器集名称来获得相同的路径? Thanks!谢谢!

Below is the Powershell code you can use just change the path in the code and data collectors as per your need it will automatically start the performance data collector with given process name in the code以下是您可以使用的 Powershell 代码,您只需根据需要更改代码和数据收集器中的路径,它将自动使用代码中给定的进程名称启动性能数据收集器

first if code is just to bypass the script execution policy in the powershell for any host machine and run the script with the admin rights you can remove that if script execution is enabled首先,如果代码只是为了绕过任何主机的 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