如何使用PowerShell获取Azure数据库的DTU百分比?

mwyxok5s  于 2023-08-05  发布在  Shell
关注(0)|答案(1)|浏览(136)

如何使用PowerShell获取数据库的DTU百分比?
当前我正在运行查询

SELECT    
AVG(avg_cpu_percent) AS 'Average CPU Utilization In Percent',   
MAX(avg_cpu_percent) AS 'Maximum CPU Utilization In Percent',   
AVG(avg_data_io_percent) AS 'Average Data IO In Percent',   
MAX(avg_data_io_percent) AS 'Maximum Data IO In Percent',   
AVG(avg_log_write_percent) AS 'Average Log Write Utilization In Percent',   
MAX(avg_log_write_percent) AS 'Maximum Log Write Utilization In Percent',   
AVG(avg_memory_usage_percent) AS 'Average Memory Usage In Percent',   
MAX(avg_memory_usage_percent) AS 'Maximum Memory Usage In Percent'   
FROM sys.dm_db_resource_stats;

字符串
但这需要每次都连接到数据库。有没有一个powershell命令我可以运行,将给予我的DTU百分比为一定的时间段?

5n0oy7gb

5n0oy7gb1#

如果度量名称未正确给出,则Get-AzMetric命令会出现 “Bad request” 错误。
要使用PowerShell获取Azure数据库的DTU百分比,您需要提供指标名称为dtu_consumption_percent

**注意:**支持的数据库指标在MSDoc中列出,供您参考。

$Metrics = Get-AzMetric -ResourceId "/subscriptions/<SubscriptionID>/resourceGroups/<resourcegroup>/providers/Microsoft.Sql/servers/<servername>/databases/<Databasename>" -MetricName "dtu_consumption_percent" -TimeGrain 00:05:00 -AggregationType Maximum -DetailedOutput
$Metrics.data

字符串


的数据

  • 或者,您也可以使用所需参数编写脚本,如下所示。*
$MonitorParameters = @{                  
ResourceId ="/subscriptions/<SubscriptionID>/resourceGroups/<resourcegroup>/providers/Microsoft.Sql/servers/<servername>/databases/<Databasename>"
MetricNames = "dtu_consumption_percent"
}
$Metrics = Get-AzMetric @MonitorParameters -DetailedOutput


  • 如果您想清楚地检索数据指标,请在上面的脚本 * 中使用 * $Metrics.data *。

相关问题