Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code Sample STTS - MonitorPoisonQueues
public static class MonitorPoisonQueues
private static readonly TelemetryClient TelemetryClient = new TelemetryClient();
private static string key = TelemetryConfiguration.Active.InstrumentationKey
= Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY",
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
var queuesToMonitor = new List<CloudQueue>();
var queueStorageConnectionString = ConfigurationManager.AppSettings["MonitorQueueStorage"];
var account = CloudStorageAccount.Parse(queueStorageConnectionString);
var queueClient = account.CreateCloudQueueClient();
QueueContinuationToken continuationToken = null;
var segment = await queueClient.ListQueuesSegmentedAsync(continuationToken);
var poisonQueues = segment.Results.Where(
q => q.Name.EndsWith("-poison", StringComparison.InvariantCultureIgnoreCase));
continuationToken = segment.ContinuationToken;
while (continuationToken != null);
foreach (var queue in queuesToMonitor)
await queue.FetchAttributesAsync();
var queueLength = queue.ApproximateMessageCount;
TelemetryClient.TrackMetric($"Poisonqueue length - {queue.Name}", (double)queueLength);
log.Info($"Queue: {queue.Name} (Items: {queueLength})");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment