Metrics
Note
This applies to the latest version of the library. If you are still using version 0.x, please refer to the migration guide.
Through the usage of an extension, it's possible to collect metrics about the channels and the data they send and receive. This extension provides metrics using Prometheus format and makes use of the prometheus-net library.
Currently, the following metrics are collected:
channels_active_total
: Total number of active channels.channels_bytes_received_total
: Total number of bytes received.channels_bytes_sent_total
: Total number of bytes sent.
Usage
To use the metrics extension, add the Faactory.Channels.Prometheus
package to your project:
Then register the metrics service. This will automatically start collecting metrics for all channels.
To export the metrics, the easiest way is to install prometheus-net.AspNetCore
package and register the pre-built middleware. If no other HTTP functionality is required, you can just do the following:
You can find a more detailed sample project on the GitHub repository. There are other ways to export the metrics, which can be found in the prometheus-net documentation.
Labels
By default, metrics are created just with the channelId
label, which contains the channel identifier. Although this is enough for differentiating channels, it is not enough for identifying the origin of the data. To extend the metrics with more labels, you can make use of the channel's data dictionary.
The metrics collector will automatically add all items with the prefix prometheus.label.
to the metrics. For example, if you want to add a uuid
label to the metrics, you can do the following:
public class SampleIdentityHandler : ChannelHandler<IdentityInformation>
{
public override Task ExecuteAsync( IChannelContext context, IdentityInformation data )
{
// ...
/*
This adds an `uuid` label to the metrics.
The label will be included in all metrics except `channels_active_total`.
*/
context.Channel.Data["prometheus.label.uuid"] = data.UUId;
return Task.CompletedTask;
}
}
Note
Labels are not used with the channels_active_total
metric.