【问题标题】:Performance counter path is not valid性能计数器路径无效
【发布时间】:2016-02-28 13:51:45
【问题描述】:

这个问题与this post有关。

还有一个问题,如果计数器看起来像这样:

"\MSSQL`$SQLMET:Databases($DatabaseName)\Log Bytes Flushed/sec"

我收到此错误:

\MSSQL$SQLMET:Databases(fee_monsson)\Log Bytes Flushed/sec 性能
计数器路径无效。
在 C:\Users\MihaiDarzanGefee\Desktop\sql-perfmon.ps1:49 char:12
+ 获取计数器 

如果我去perfmon,我会找到柜台\MSSQL$SQLMET:Databases(fee_monsson)\Log Bytes Flushed/sec,所以我不明白出了什么问题。

代码是:

<#
    .SYNOPSIS
    Collect counters required for DTU Calculator and log as CSV.

    .DESCRIPTION
    Collect counters required for DTU Calculator and log as CSV. Default disk
    drive parameters is F:. Default log file location is C:\sql-perfmon-log.csv.
    Counters are collected at 1 second intervals for 1 hour or 3600 seconds.

    .PARAMETER DatabaseName
    The name of the SQL Server database to monitor.
#>
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true)]
    [String]$DatabaseName
)

$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"

cls

Write-Output "Collecting counters..."
Write-Output "Press Ctrl+C to exit."

$counters = @("\Processor(_Total)\% Processor Time",
    "\LogicalDisk(C:)\Disk Reads/sec", "\LogicalDisk(C:)\Disk Writes/sec", 
    "\LogicalDisk(C:)\Disk Read Bytes/sec",
    "\LogicalDisk(C:)\Disk Write Bytes/sec",
    "\MSSQL`$SQLMET:Databases($DatabaseName)\Log Bytes Flushed/sec")

Get-Counter -Counter $counters -SampleInterval 1 -MaxSamples 3600 |
    Export-Counter -FileFormat csv -Path "C:\sql-perfmon-log.csv" -Force

【问题讨论】:

    标签: sql-server powershell counter


    【解决方案1】:

    我必须以管理员身份运行 powershell 脚本(例如:右键单击 powershell.exe 并单击“以管理员身份运行”,而不仅仅是从管理员帐户运行)。它抓取的是性能计数器,而不是数据库中的数据,因此它需要相应的权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      • 2016-12-24
      相关资源
      最近更新 更多