Skip to main content

Metrics in Apps

The ArconQ Metrics module, in addition to monitoring the cluster and services, also enables monitoring of the apps running in ArconQ.

Prerequisites​

Enable the Metrics module​

To enable the Metrics module, refer to the Installation Guide.

Enable the metrics exposure in Apps​

To allow scraping of app metrics, a specific feature flag must be enabled in the ArconQ Helm chart.

Add the following line to your installation script to enable this feature:

helm upgrade --install arconq-prod arconq/arconq \
--namespace arq-prod \
--set "arconq.advanced.featureFlags.isAppMetricsExposureEnabled=true"

Enabling this flag configures ArconQ to expose metrics endpoints for your applications, allowing Prometheus (or similar tools) to scrape app-specific metrics for monitoring.

Adding custom metrics to Apps​

Necessary libraries​

ArconQ .NET SDK does not include metrics libraries by default. Add the following NuGet packages to your project to enable metrics:

In Program.cs, add these lines to enable HTTP metrics and configure the /metrics endpoint:

// Expose default HTTP metrics
app.UseHttpMetrics();

// Configure the metrics endpoint
app.UseEndpoints(endpoints => endpoints.MapMetrics(settings => settings.EnableOpenMetrics = false));

Example of adding custom metrics​

In this example we'll add two custom metrics to a MessageHandler

  • Received Messages Counter - Increments by 1 every time a message is handled by this MessageHandler.
  • Message Exchange Duration Gauge - Stores the time difference (in milliseconds) between when a message is sent and when it is received.
using ArconQ.SDK.Messaging;
using Prometheus;

public class MessageHandlerWithMetrics : IMessageHandler<ExampleMessage>
{
private static readonly Counter _receivedMessagesCount = Metrics.CreateCounter("received_messages_count_total", "Number of received messages");
private static readonly Gauge _messageExchangeDurationGauge = Metrics.CreateGauge("message_exchange_duration_milliseconds", "Time between sending a message and receiving it");

public MessageHandlerWithMetrics() {}

public Task HandleAsync(ExampleMessage message)
{
_receivedMessagesCount.Inc();

var timeOfReceiving = DateTime.UtcNow;
var exchangeTime = timeOfReceiving - message.SendTime;
_messageExchangeDurationGauge.Set(exchangeTime.TotalMilliseconds)
}
}
info

Note that message.SendTime is a field of the custom class ExampleMessage. It's not a part of ArconQ SDK.

Exploring the Prometheus libraries​

For more information about used libraries please refer to their documentation: