Great! Now that you have diagnostic logs being sent to a log analytics workspace, you can create a variety of queries to monitor your SQL Managed Instance. Here are a few queries that you might find useful:
- CPU Utilization: This query will give you the CPU utilization percentage for your SQL Managed Instance:
Perf
| where ObjectName == "SQLServer:Resource Pool Stats"
| where CounterName == "CPU usage %"
| summarize AvgCPUUtilization = avg(CounterValue) by bin(TimeGenerated, 5m), Computer
| order by TimeGenerated desc
- Memory Utilization: This query will give you the memory utilization percentage for your SQL Managed Instance:
Perf
| where ObjectName == "SQLServer:Memory Manager"
| where CounterName == "Total Server Memory (KB)"
| summarize TotalServerMemory_MB = avg(CounterValue/1024./1024.) by bin(TimeGenerated, 5m), Computer
| order by TimeGenerated desc
Perf
| where ObjectName == "SQLServer:Memory Manager"
| where CounterName == "Target Server Memory (KB)"
| summarize TargetServerMemory_MB = avg(CounterValue/1024./1024.) by bin(TimeGenerated, 5m), Computer
| order by TimeGenerated desc
TotalServerMemory_MB - TargetServerMemory_MB
- Disk Utilization: This query will give you the disk utilization percentage for your SQL Managed Instance:
Perf
| where ObjectName == "LogicalDisk"
| where CounterName == "Free Megabytes"
| summarize FreeMB = avg(CounterValue) by bin(TimeGenerated, 5m), InstanceName, Computer
| where InstanceName == "_Total"
| order by TimeGenerated desc
Perf
| where ObjectName == "LogicalDisk"
| where CounterName == "Free Megabytes"
| summarize TotalMB = sum(CounterValue) by bin(TimeGenerated, 5m), Computer
| order by TimeGenerated desc
(TotalMB - FreeMB) * 100 / TotalMB
- Connection and Query Performance: This query will give you the number of connections, the number of transactions, and the average duration of transactions for your SQL Managed Instance.
AzureDiagnostics
| where Category == "SQLSecurityAuditEvents" and OperationName == "AuditSqlStatement"
| where EventLevelName == "Informational"
| where DatabaseName_s == "<Your Database Name>"
| extend ConnectionId = tostring(split(ClientIP_s, ":")[0])
| summarize Count = count(), Transactions = sum(Transaction_s), Duration = avg(Duration_s * 10000) by bin(TimeGenerated, 5m), ConnectionId
| order by TimeGenerated desc
You can customize these queries to your specific needs and use them as the basis for your dashboard.
Keep in mind that the above queries are written assuming you have enabled the Diagnostic Settings and configured the metrics to send to the Log Analytics workspace. Also, you need to replace in the fourth query with the name of your actual database.
Please let me know if you have any further questions. I'll be happy to help.