-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74b5a41
commit 6cd51aa
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/prometheus-net.Contrib/EventListeners/Adapters/PrometheusHttpClientCounterAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters