AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 625962
Accepted
Reaces
Reaces
Asked: 2014-09-04 05:33:33 +0800 CST2014-09-04 05:33:33 +0800 CST 2014-09-04 05:33:33 +0800 CST

使用 Powershell 获取一组特定的性能计数器

  • 772

我正在尝试使用 powershell 设置一个脚本,该脚本每隔一定时间生成 blg 文件。我知道这可以使用 perfmon XML 模板来完成,但是对于这个特定的项目,如果可能的话,我必须使用 powershell 来完成。

我的主要问题是我无法将要使用的性能计数器列表存储在变量中并重用它们。

我尝试使用以下脚本创建要使用的性能计数器列表:

$Counters = @()
$Counters += '\Memory\Available Bytes' 
$counters += '\Paging File(*)\% Usage'
$Counters += '\PhysicalDisk(*)\Disk Reads/sec'
$Counters += '\PhysicalDisk(*)\Disk Writes/sec'
$Counters += '\PhysicalDisk(*)\Avg. Disk sec/Read'
$Counters += '\PhysicalDisk(*)\Avg. Disk sec/Write'
$Counters += '\Processor(*)\% Processor Time'
$Counters += '\System\Processor Queue Length'
foreach($counter in $Counters)
{
$string = $string + ", '" + $counter + "'" 
$string = $string.TrimStart(",")
}

如果我继续使用 get-counter $string 我收到以下错误:

Get-Counter : The specified counter path could not be interpreted.

然而,当我复制字符串的确切值并使用$string 的 get-counter -counter 值时,它可以正常工作......

有人可以建议我让get-counter使用数组或带有计数器列表的字符串吗?

powershell
  • 1 1 个回答
  • 2625 Views

1 个回答

  • Voted
  1. Best Answer
    jscott
    2014-09-04T07:41:27+08:002014-09-04T07:41:27+08:00

    当我使用你的+=块时,我得到$counters一个长连接字符串。

    $counters += '\Memory\Available Bytes'
    $counters += '\Paging File(*)\% Usage'
    $counters += '\PhysicalDisk(*)\Disk Reads/sec'
    $counters += '\PhysicalDisk(*)\Disk Writes/sec'
    $counters += '\PhysicalDisk(*)\Avg. Disk sec/Read'
    $counters += '\PhysicalDisk(*)\Avg. Disk sec/Write'
    $counters += '\Processor(*)\% Processor Time'
    $counters += '\System\Processor Queue Length'
    $counters
    
    \Memory\Available Bytes\Paging File(*)\% Usage\PhysicalDisk(*)\Disk Reads/sec\PhysicalDisk(*)\Disk Writes/sec\PhysicalDisk(*)\Avg. Disk sec/Read\PhysicalDisk(*)\Avg. Disk sec/Write\Processor(*)\% Processor Time\System\Processor Queue Length
    
    $counters.GetType()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     String                                   System.Object
    

    那可能不是你想要的。如果你$counters明确地制作一个数组,事情会更好一些。

    $counters = @()
    $counters += '\Memory\Available Bytes' 
    $counters += '\Paging File(*)\% Usage'
    $counters += '\PhysicalDisk(*)\Disk Reads/sec'
    $counters += '\PhysicalDisk(*)\Disk Writes/sec'
    $counters += '\PhysicalDisk(*)\Avg. Disk sec/Read'
    $counters += '\PhysicalDisk(*)\Avg. Disk sec/Write'
    $counters += '\Processor(*)\% Processor Time'
    $counters += '\System\Processor Queue Length'
    $counters.GetType()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     Object[]                                 System.Array
    
    $counters | Get-Counter
    
    • 2

相关问题

  • 资源锁和电源外壳

  • 脚本 - 如何断开远程桌面会话?

  • 如何限制向通讯组发送到外部地址?

  • Powershell对值与数组的作用不同?

  • Windows Powershell Vim 键绑定

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve