Created
December 20, 2018 21:03
-
-
Save taddison/4bcd73c79aa09d686d3f22adef5e9ea1 to your computer and use it in GitHub Desktop.
appinsights sql check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.ApplicationInsights; | |
using Microsoft.ApplicationInsights.DependencyCollector; | |
using Microsoft.ApplicationInsights.Extensibility; | |
using System; | |
using System.Collections.Generic; | |
using System.Data.SqlClient; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var config = TelemetryConfiguration.Active; | |
config.InstrumentationKey = "nope"; | |
var client = new TelemetryClient(); | |
var module = new DependencyTrackingTelemetryModule(); | |
module.Initialize(config); | |
using (var conn = new SqlConnection("server=server;initial catalog=master;trusted_connection=true")) | |
{ | |
conn.Open(); | |
for (var i = 0; i < 600; i += 10) | |
{ | |
var ts = new TimeSpan(0, 0, i); | |
using (var cmd = new SqlCommand($"waitfor delay '00:{ts.Minutes:00}:{ts.Seconds:00}'", conn)) | |
{ | |
cmd.CommandTimeout = Int32.MaxValue; | |
client.TrackTrace($"Running SQL query for {ts.TotalSeconds} seconds"); | |
cmd.ExecuteNonQuery(); | |
} | |
} | |
} | |
client.Flush(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment