1

This question is related to this post.

There is still one problem, if the counter looks like this:

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

I get this error:

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

If I go to perfmon I find the counter \MSSQL$SQLMET:Databases(fee_monsson)\Log Bytes Flushed/sec, so I cannot understand what is wrong.

The code is:

<#
    .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
Community
  • 1
  • 1

1 Answers1

0

Had to run the powershell script as administrator for me (eg: right click powershell.exe and click "run as administrator", not just running it from an admin account). It's grabbing performance counters, not data from the database, so it'll need the appropriate permissions for such.

StrangeWill
  • 2,106
  • 1
  • 23
  • 36