-
-
Save SebastianAchatz/17066bc19e9227effef1068f3c595756 to your computer and use it in GitHub Desktop.
Code Sample STTS - MonitorPoisonQueues
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
public static class MonitorPoisonQueues | |
{ | |
private static readonly TelemetryClient TelemetryClient = new TelemetryClient(); | |
private static string key = TelemetryConfiguration.Active.InstrumentationKey | |
= Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", | |
EnvironmentVariableTarget.Process); | |
[FunctionName("MonitorPoisonQueues")] | |
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; | |
do | |
{ | |
var segment = await queueClient.ListQueuesSegmentedAsync(continuationToken); | |
var poisonQueues = segment.Results.Where( | |
q => q.Name.EndsWith("-poison", StringComparison.InvariantCultureIgnoreCase)); | |
queuesToMonitor.AddRange(poisonQueues); | |
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