I am trying to get the count of messages in a particular queue from Azure Storage account using Log Analytics to ultimately publish on a dashboard.
Thanks in advance for your help
I am trying to get the count of messages in a particular queue from Azure Storage account using Log Analytics to ultimately publish on a dashboard.
Thanks in advance for your help
We have tested this in our local environment, below statements are based on our analysis.
kql queries
in log analytics you can pull logs only on the below operations that were performed on the storage accountAzure Monitor provides several ways to interact with metrics, including charting them in the Azure portal, accessing them through the REST API, or querying them by using PowerShell or the Azure CLI. All the platform metrics that were collected automatically are available with consolidated metric pipeline.
platform metrics
in Azure portal we can get the over all metrics (QueueCapacity,QueueCount,QueueMessageCount
) at account level as show below.Alternatively, You can create a Timer trigger
function to monitor the length of the queue as explained in this blog post.
Here is the code in function.cs file :
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Azure.Storage.Queues;
namespace FunctionApp3
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
var value = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
var queueNames = "<queueName>";
var queueClient = new QueueClient(value, queueNames);
int count = 0;
foreach (var message in queueClient.ReceiveMessages(maxMessages:32).Value)
{
count=count+1;
}
log.LogInformation($"current queueLength :{count}");
}
}
}
Here are the setting in our local.setting.json file :
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "StrgAccountConnectionString"
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
Here is the sample output for reference: