2016-02-28 68 views
1

此問題與this post有關。性能計數器路徑無效

還有一個問題,如果計數器是這樣的:

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

我得到這個錯誤:

The \MSSQL$SQLMET:Databases(fee_monsson)\Log Bytes Flushed/sec performance 
counter path is not valid. 
At C:\Users\MihaiDarzanGefee\Desktop\sql-perfmon.ps1:49 char:12 
+ Get-Counter <<<< -Counter $counters -SampleInterval 1 -MaxSamples 3600 | 
    + CategoryInfo   : InvalidResult: (:) [Get-Counter], Exception 
    + FullyQualifiedErrorId : CounterPathIsInvalid,Microsoft.PowerShell.Commands.GetCounterCommand

如果我去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 
+0

任何人,任何想法? –

回答

0

只好運行PowerShell腳本以管理員身份對我來說(如:右擊powershell.exe,然後單擊「以管理員身份運行」,不只是從管理員帳戶運行它) 。它抓取性能計數器,而不是數據庫中的數據,所以它需要適當的權限。