Skip to content

Commit

Permalink
Http Client Counters
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksii-valuiskyi committed Dec 12, 2020
1 parent 74b5a41 commit 6cd51aa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using Prometheus.Contrib.Core;
using Prometheus.Contrib.EventListeners.Counters;

namespace Prometheus.Contrib.EventListeners.Adapters
{
internal class PrometheusHttpClientCounterAdapter : ICounterAdapter
{
public const string EventSourceName = "System.Net.Http";

internal readonly MeanCounter RequestsStarted = new MeanCounter("requests-started", "http_client_requests_started_total", "Requests Started");
internal readonly IncrementCounter RequestsStartedRate = new IncrementCounter("requests-started-rate", "http_client_requests_started_per_second", "Requests Started Rate");
internal readonly MeanCounter RequestsAborted = new MeanCounter("requests-aborted", "http_client_requests_aborted_total", "Total Requests Aborted");
internal readonly IncrementCounter RequestsAbortedRate = new IncrementCounter("requests-aborted-rate", "http_client_requests_aborted_per_second", "Requests Failed Rate");
internal readonly MeanCounter CurrentRequests = new MeanCounter("current-requests", "http_client_requests_current_total", "Current Requests");
internal readonly MeanCounter Http11ConnectionsCurrentTotal = new MeanCounter("http11-connections-current-total", "http_client_http11_connections_current_total", "Current Http 1.1 Connections");
internal readonly MeanCounter Http20ConnectionsCurrentTotal = new MeanCounter("http20-connections-current-total", "http_client_http20_connections_current_total", "Current Http 2.0 Connections");
internal readonly MeanCounter Http11RequestsQueueDuration = new MeanCounter("http11-requests-queue-duration", "http_client_http11_requests_queue_duration", "HTTP 1.1 Requests Queue Duration");
internal readonly MeanCounter Http20RequestsQueueDuration = new MeanCounter("http20-requests-queue-duration", "http_client_http20_requests_queue_duration", "HTTP 2.0 Requests Queue Duration");

private readonly Dictionary<string, BaseCounter> _counters;

public PrometheusHttpClientCounterAdapter()
{
_counters = CounterUtils.GenerateDictionary(this);
}

public void OnCounterEvent(IDictionary<string, object> eventPayload)
{
if (!eventPayload.TryGetValue("Name", out var counterName))
{
return;
}

if (!_counters.TryGetValue((string) counterName, out var counter))
return;

counter.TryReadEventCounterData(eventPayload);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class CountersEventListener : EventListener
[PrometheusGrpcClientCounterAdapter.EventSourceName] = new PrometheusGrpcClientCounterAdapter(),
[PrometheusEfCoreCounterAdapter.EventSourceName] = new PrometheusEfCoreCounterAdapter(),
[PrometheusKestrelCounterAdapter.EventSourceName] = new PrometheusKestrelCounterAdapter(),
[PrometheusHttpClientCounterAdapter.EventSourceName] = new PrometheusHttpClientCounterAdapter()
};

internal CountersEventListener(int refreshPeriodSeconds = 10)
Expand Down

0 comments on commit 6cd51aa

Please sign in to comment.