1
還有一個問題,如果計數器是這樣的:
"\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
任何人,任何想法? –