Skip to content

Instantly share code, notes, and snippets.

@johndownskloud
Created September 7, 2017 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johndownskloud/11106a0c45a66c4136aed90ac31e9db7 to your computer and use it in GitHub Desktop.
Save johndownskloud/11106a0c45a66c4136aed90ac31e9db7 to your computer and use it in GitHub Desktop.
Azure Function - Queue Monitor (v2)
#r "Microsoft.WindowsAzure.Storage"
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
private static string key = TelemetryConfiguration.Active.InstrumentationKey = System.Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process);
private static TelemetryClient telemetry = new TelemetryClient() { InstrumentationKey = key };
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
// connect to Azure Storage
var connectionString = System.Configuration.ConfigurationManager.AppSettings["AzureWebJobsStorage"];
var account = CloudStorageAccount.Parse(connectionString);
var queueClient = account.CreateCloudQueueClient();
// check the length of each queue
var queueNames = new string[] { "processorders", "processorders-poison" };
foreach (var queueName in queueNames)
{
// get a reference to the queue and retrieve the queue length
var queue = queueClient.GetQueueReference(queueName);
queue.FetchAttributes();
var length = queue.ApproximateMessageCount;
// log the length
log.Info($"{queueName}: {length}");
telemetry.TrackMetric($"Queue length - {queueName}", (double)length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment