Skip to content

Instantly share code, notes, and snippets.

@SebastianAchatz
Created March 31, 2018 12:33
Show Gist options
  • Save SebastianAchatz/17066bc19e9227effef1068f3c595756 to your computer and use it in GitHub Desktop.
Save SebastianAchatz/17066bc19e9227effef1068f3c595756 to your computer and use it in GitHub Desktop.
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",
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