Queue statistics

Nexus can store statitics for your queues to help visualize the activity in a queue. If you've enabled statistics you can find them in the Admin UI under Statistics and in the queue list and queue details. The statistics shown in the queues list is the total number of status changes/total activity in a queue.

The statitics consists of counters for each status. The statistics represents the changes in status rather than the current count of a status at any given time. That is, if the statistics reports zero Error messages it means that no messages got the status Error at that point in time.

By default statistics are turned off but you can opt-in to them by either:

Turning it on for all queues by doing:

builder.Services.AddNexus().AddQueues(options =>
{
    options.StatisticsRetention = TimeSpan.FromDays(30); // TimeSpan.MaxValue to store forever
});

Turning it on on a specific queue:

[Queue(StatisticsRetention = "30d")]
public class MyQueueMessage : IQueueMessage
{

}

The string set for StatisticsRetention must either by a parsable TimeSpan or in the human readable format, eg 6h or 30d.

Updating through the Admin UI/API:

In the Admin UI you can go to the queue details and click on the More button and edit the Statistics retention per queue. The Admin UI uses the API to do this, so it's also possible to control through the API directly. See the Swagger docs for endpoint details.

Disabling statistics

By default statistics tables are created per queue to make it possible to enable it dynamically through the Admin UI. If you really don't want to see the statistics feature you can disable it completely by doing:

builder.Services.AddNexus().AddQueues(options =>
{
    options.DisableStatistics = true;
});

This deletes all statistics tables and prevents statistics features from being displayed in the UI.

IQueueStatisticsReader / IQueueStatisticsWriter

The reader and writer interfaces are interfaces you can override to either implement your own statistics storage or decorate to send the statistics to analytics. The writer interface gets called directly when any message status changes (or new messages are created), so you should store the changes in memory and persist the changes in batches in a background thread.