我的主要問題是:我想將Azure SQL中運行速度最慢的查詢發送到負載測試調試的集中式日誌記錄系統。以表格格式嚮應用程序洞察發送Azure自動化輸出
如何將結果集發送給應用程序見解?我想將Azure自動化中運行速度最慢的查詢發送給Application Insights?
我有運氣嘗試這樣做時,它以表格形式
workflow Use-SqlCommandSample
{
param(
[parameter(Mandatory=$True)]
[string] $SqlServer,
[parameter(Mandatory=$False)]
[int] $SqlServerPort = 1433,
[parameter(Mandatory=$True)]
[string] $Database,
[parameter(Mandatory=$True)]
[string] $Table,
[parameter(Mandatory=$True)]
[PSCredential] $SqlCredential
)
# Get the username and password from the SQL Credential
$SqlUsername = $SqlCredential.UserName
$SqlPass = $SqlCredential.GetNetworkCredential().Password
inlinescript {
# Define the connection to the SQL Database
$Conn = New-Object System.Data.SqlClient.SqlConnection("xxxx")
# Open the SQL connection
$Conn.Open()
$Cmd=new-object system.Data.SqlClient.SqlCommand("SELECT top 10 creation_time"+
",last_execution_time"+
",total_physical_reads"+
",total_logical_reads "+
",total_logical_writes"+
", execution_count"+
", total_worker_time"+
" , total_elapsed_time"+
", total_elapsed_time/execution_count avg_elapsed_time"+
",SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,"+
" ((CASE statement_end_offset"+
" WHEN -1 THEN DATALENGTH(st.text)"+
" ELSE qs.statement_end_offset END"+
" - qs.statement_start_offset)/2) + 1) AS statement_text"+
" FROM sys.dm_exec_query_stats AS qs"+
" CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st"+
" ORDER BY total_elapsed_time/execution_count DESC;", $Conn)
$Cmd.CommandTimeout=120
# Execute the SQL command
$Ds=New-Object system.Data.DataSet
$Da=New-Object system.Data.SqlClient.SqlDataAdapter($Cmd)
[void]$Da.fill($Ds)
$assemblyPath =
"C:\Modules\Global\Azure\Compute\Microsoft.ApplicationInsights.dll"
[System.Reflection.Assembly]::LoadFrom($assemblyPath)
$TelClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"
$TelClient.InstrumentationKey = "1234"
# Output the result
$TelClient.TrackEvent($Ds.Tables)
$TelClient.Flush
# Close the SQL connection
$Conn.Close()
}
}
我遇到了從Azure觸發應用程序洞察的麻煩。它適用於我的PowerShell ISE。我如何參考Azure自動化中的DLL? –