Reputation: 61
We have quite a few Azure service-bus topics/queues in production. Any given topic has a MAX SIZE and its possible to hit that limit due to various reasons no related to load viz. ununsed subscriptions attached to the topic etc.
We had more than one outages when a topic hit it's size limits as we had ununsed subscriptions. We are looking for fundamental monitoring where
While 2. is good to have but having just 1. should also be fine.
Azure service bus has "Metrics" in preview currently and there are bunch of metrics we can setup to get alerted on. It looks like it is in very early stages and even above requirement cannot be fulfilled.
Am I missing something or I need to build custom monitoring using Azure functions / Logic Apps by invoking REST APIs exposed at - https://learn.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics?redirectedfrom=MSDN#microsoftservicebusnamespaces
https://www.servicebus360.com/ is selling the above functionality but my requirement is very rudimentary.
Upvotes: 3
Views: 1907
Reputation: 1494
Size of the Queue/Topic is now available in the Azure Monitor Metrics. As it is in preview stage, the values may not reflect instantaneously. But it is possible to monitor those metrics using Azure Monitor, which is also in the Preview stage.
Upvotes: 1
Reputation: 2642
Yes, it is possible to get usage details about Azure Service Bus Queues space usage. Find below a sample Console Application (C# + .NET Framework 4.7 + WindowsAzure.ServiceBus 4.1.10) that calculates the free space in a given queue. Use TopicDescription for topics.
private static async Task GetFreeSpace(string connectionString, string queueName)
{
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentException("Service bus connection string cannot be null, empty or whitespace.");
}
if (string.IsNullOrWhiteSpace(queueName))
{
throw new ArgumentException("Service bus queue name cannot be null, empty or whitespace.");
}
NamespaceManager nm = NamespaceManager.CreateFromConnectionString(connectionString);
QueueDescription queueDescription = await nm.GetQueueAsync(queueName);
double spaceUsedInMB = 0;
double freeSpaceInMB = 0;
double percentageFreeSpace = 100;
if (queueDescription.SizeInBytes > 0)
{
spaceUsedInMB = (queueDescription.SizeInBytes / 1024.0 / 1024.0);
freeSpaceInMB = queueDescription.MaxSizeInMegabytes - spaceUsedInMB;
percentageFreeSpace = 100 * freeSpaceInMB / queueDescription.MaxSizeInMegabytes;
}
Console.WriteLine($"Max Size (MB) = {queueDescription.MaxSizeInMegabytes:0.00000}");
Console.WriteLine($"Used Space (MB) = {spaceUsedInMB:0.00000}");
Console.WriteLine($"Free Space (MB) = {freeSpaceInMB:0.00000}");
Console.WriteLine($"Free Space (%) = {percentageFreeSpace:0.00000}");
}
Here is the packages.config file content:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="WindowsAzure.ServiceBus" version="4.1.10" targetFramework="net47" />
</packages>
This can be automated using a Timer as long as it meets your requirements. Find more details at https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer.
In addition, per documentation https://learn.microsoft.com/en-us/powershell/module/azurerm.servicebus/get-azurermservicebusqueue?view=azurermps-6.1.0 it is also possible to get these details using PowerShell.
Upvotes: 0