Update sql-vm-io-analysis.ps1

This commit is contained in:
Masha Thomas (MSFT)
2024-05-22 12:16:20 -07:00
committed by GitHub
parent 308136be11
commit f9eb783e60
+10 -10
View File
@@ -1,7 +1,7 @@
# Prompt user for details # Enter parameters
$subscriptionId = Read-Host "Enter Subscription ID" $subscriptionId = Read-Host "<Subscription ID>"
$resourceGroup = Read-Host "Enter Resource Group Name" $resourceGroup = Read-Host "<Resource Group>"
$vmName = Read-Host "Enter VM Name" $vmName = Read-Host "<Virtual machine name>"
# Set resource details # Set resource details
$resourceType = "Microsoft.Compute/virtualMachines" $resourceType = "Microsoft.Compute/virtualMachines"
@@ -10,7 +10,7 @@ $resourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/prov
# Get Azure access token # Get Azure access token
$accessToken = az account get-access-token --query accessToken -o tsv $accessToken = az account get-access-token --query accessToken -o tsv
# Function to invoke Azure Monitor Metrics API # Invoke Azure Monitor Metrics API
function Get-Metrics { function Get-Metrics {
[CmdletBinding()] [CmdletBinding()]
param ( param (
@@ -39,7 +39,7 @@ function Get-Metrics {
} }
} }
# Function to check if Data Disk Latency data is violating thresholds # Check if data disk latency violates thresholds
function Check-Latency { function Check-Latency {
[CmdletBinding()] [CmdletBinding()]
param ( param (
@@ -78,7 +78,7 @@ function Check-Latency {
} }
} }
# Function to check metrics other than Latency and evaluate if they are throttled # Check metrics other than latency to evaluate for throttling
function Check-OtherMetricsThrottled { function Check-OtherMetricsThrottled {
[CmdletBinding()] [CmdletBinding()]
param ( param (
@@ -114,7 +114,7 @@ function Check-OtherMetricsThrottled {
return $violatedMetrics return $violatedMetrics
} }
# Function to compare the times for Latency Metric & other Throttled Metrics. Logs Violations with Values & Timestamps # Compare times for latency & other throttled metrics. Logs the volations with values & timestamps
function CompareTimes { function CompareTimes {
[CmdletBinding()] [CmdletBinding()]
param ( param (
@@ -163,13 +163,13 @@ if (-not [int]::TryParse($latencyThreshold, [ref]0)) {
Write-Host "No valid input provided. Using Default 500ms for disk latency threshold" Write-Host "No valid input provided. Using Default 500ms for disk latency threshold"
} }
# Main Logic Execution: # Execute main logic
$latencyMetrics = Get-Metrics -accessToken $accessToken -resourceId $resourceId -metricNames "Data Disk Latency" $latencyMetrics = Get-Metrics -accessToken $accessToken -resourceId $resourceId -metricNames "Data Disk Latency"
$latencyResult = Check-Latency -metrics $latencyMetrics -latencyThreshold $latencyThreshold $latencyResult = Check-Latency -metrics $latencyMetrics -latencyThreshold $latencyThreshold
if ($latencyResult.Flag) { if ($latencyResult.Flag) {
# Only if Latency is flagged we will check for other metrics. If no disk latency is experienced, machine is likely not throttled but only at high consumption # If latency is flagged, check for other metrics. If there is no disk latency, machine is likely not throttled but only at high consumption
Write-Verbose "Checking the following metrics: Data Disk Bandwidth Consumed Percentage,Data Disk IOPS Consumed Percentage,VM Cached Bandwidth Consumed Percentage,VM Cached IOPS Consumed Percentage,VM Uncached Bandwidth Consumed Percentage,VM Uncached IOPS Consumed Percentage" Write-Verbose "Checking the following metrics: Data Disk Bandwidth Consumed Percentage,Data Disk IOPS Consumed Percentage,VM Cached Bandwidth Consumed Percentage,VM Cached IOPS Consumed Percentage,VM Uncached Bandwidth Consumed Percentage,VM Uncached IOPS Consumed Percentage"
$DiskVMMetrics = Get-Metrics -accessToken $accessToken -resourceId $resourceId -metricNames "Data Disk Bandwidth Consumed Percentage,Data Disk IOPS Consumed Percentage,VM Cached Bandwidth Consumed Percentage,VM Cached IOPS Consumed Percentage,VM Uncached Bandwidth Consumed Percentage,VM Uncached IOPS Consumed Percentage" $DiskVMMetrics = Get-Metrics -accessToken $accessToken -resourceId $resourceId -metricNames "Data Disk Bandwidth Consumed Percentage,Data Disk IOPS Consumed Percentage,VM Cached Bandwidth Consumed Percentage,VM Cached IOPS Consumed Percentage,VM Uncached Bandwidth Consumed Percentage,VM Uncached IOPS Consumed Percentage"