Skip to content

Commit 13ae303

Browse files
authored
Socket stats (#59)
* Starting adding support for socket telemetry. Needed to refactor how sources are identified to support the new breed of telemetry classes. * Updating documentation around socket events, updating dashboard * Trying to make tests a bit more resilient
1 parent 956a033 commit 13ae303

26 files changed

+1147
-712
lines changed

docs/metrics-exposed-5.0.md

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,10 @@ Metrics that are included by default, regardless of what stats collectors are en
88

99
| Name | Type | Description | Labels |
1010
| ------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
11-
| `dotnet_build_info` | `Gauge` | Build information about prometheus\-net.DotNetRuntime and the environment | `version`, `target_framework`, `runtime_version`, `os_version`, `process_architecture`, `gc_mode` |
1211
| `dotnet_internal_recycle_count` | `Counter` | prometheus\-net.DotNetRuntime internal metric. Counts the number of times the underlying event listeners have been recycled | |
12+
| `dotnet_build_info` | `Gauge` | Build information about prometheus\-net.DotNetRuntime and the environment | `version`, `target_framework`, `runtime_version`, `os_version`, `process_architecture`, `gc_mode` |
1313
| `process_cpu_count` | `Gauge` | The number of processor cores available to this process. | |
1414

15-
## `.WithJitStats()`
16-
17-
Include metrics summarizing the volume of methods being compiled
18-
by the Just\-In\-Time compiler.
19-
20-
### `CaptureLevel.Counters`
21-
22-
| Name | Type | Description | Labels |
23-
| ------------------------- | --------- | ---------------------------------------------------- | ------ |
24-
| `dotnet_jit_il_bytes` | `Gauge` | Total bytes of IL compiled by the JIT compiler | |
25-
| `dotnet_jit_method_total` | `Counter` | Total number of methods compiled by the JIT compiler | |
26-
27-
### `CaptureLevel.Verbose`
28-
29-
Includes metrics generated by `CaptureLevel.Counters` plus:
30-
31-
| Name | Type | Description | Labels |
32-
| --------------------------------- | --------- | ------------------------------------------------------------------------------------------------- | --------- |
33-
| `dotnet_jit_cpu_ratio` | `Gauge` | The amount of total CPU time consumed spent JIT'ing | |
34-
| `dotnet_jit_method_total` | `Counter` | Total number of methods compiled by the JIT compiler, broken down by compilation for dynamic code | `dynamic` |
35-
| `dotnet_jit_method_seconds_total` | `Counter` | Total number of seconds spent in the JIT compiler, broken down by compilation for dynamic code | `dynamic` |
36-
3715
## `.WithGcStats()`
3816

3917
Include metrics recording the frequency and duration of garbage collections\/ pauses, heap sizes and
@@ -43,23 +21,23 @@ Include metrics recording the frequency and duration of garbage collections\/ pa
4321

4422
| Name | Type | Description | Labels |
4523
| ---------------------------------------- | --------- | ---------------------------------------------------------------------------------------------- | --------------- |
46-
| `dotnet_gc_allocated_bytes_total` | `Counter` | The total number of bytes allocated on the managed heap | |
4724
| `dotnet_gc_collection_count_total` | `Counter` | Counts the number of garbage collections that have occurred, broken down by generation number. | `gc_generation` |
25+
| `dotnet_gc_heap_size_bytes` | `Gauge` | The current size of all heaps (only updated after a garbage collection) | `gc_generation` |
26+
| `dotnet_gc_allocated_bytes_total` | `Counter` | The total number of bytes allocated on the managed heap | |
4827
| `dotnet_gc_memory_total_available_bytes` | `Gauge` | The upper limit on the amount of physical memory .NET can allocate to | |
4928
| `dotnet_gc_pause_ratio` | `Gauge` | The percentage of time the process spent paused for garbage collection | |
50-
| `dotnet_gc_heap_size_bytes` | `Gauge` | The current size of all heaps (only updated after a garbage collection) | `gc_generation` |
5129

5230
### `CaptureLevel.Informational`
5331

5432
Includes metrics generated by `CaptureLevel.Counters` plus:
5533

5634
| Name | Type | Description | Labels |
5735
| ------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
58-
| `dotnet_gc_pause_seconds` | `Histogram` | The amount of time execution was paused for garbage collection | |
5936
| `dotnet_gc_cpu_ratio` | `Gauge` | The percentage of process CPU time spent running garbage collections | |
60-
| `dotnet_gc_collection_count_total` | `Counter` | Counts the number of garbage collections that have occurred, broken down by generation number and the reason for the collection. | `gc_generation`, `gc_reason` |
61-
| `dotnet_gc_collection_seconds` | `Histogram` | The amount of time spent running garbage collections | `gc_generation`, `gc_type` |
6237
| `dotnet_gc_finalization_queue_length` | `Gauge` | The number of objects waiting to be finalized | |
38+
| `dotnet_gc_collection_seconds` | `Histogram` | The amount of time spent running garbage collections | `gc_generation`, `gc_type` |
39+
| `dotnet_gc_pause_seconds` | `Histogram` | The amount of time execution was paused for garbage collection | |
40+
| `dotnet_gc_collection_count_total` | `Counter` | Counts the number of garbage collections that have occurred, broken down by generation number and the reason for the collection. | `gc_generation`, `gc_reason` |
6341
| `dotnet_gc_pinned_objects` | `Gauge` | The number of pinned objects | |
6442

6543
### `CaptureLevel.Verbose`
@@ -70,24 +48,6 @@ Includes metrics generated by `CaptureLevel.Counters`, `CaptureLevel.Information
7048
| --------------------------------- | --------- | ------------------------------------------------------- | --------- |
7149
| `dotnet_gc_allocated_bytes_total` | `Counter` | The total number of bytes allocated on the managed heap | `gc_heap` |
7250

73-
## `.WithExceptionStats()`
74-
75-
Include metrics that measure the number of exceptions thrown.
76-
77-
### `CaptureLevel.Counters`
78-
79-
| Name | Type | Description | Labels |
80-
| ------------------------- | --------- | -------------------------- | ------ |
81-
| `dotnet_exceptions_total` | `Counter` | Count of exceptions thrown | |
82-
83-
### `CaptureLevel.Errors`
84-
85-
Includes metrics generated by `CaptureLevel.Counters` plus:
86-
87-
| Name | Type | Description | Labels |
88-
| ------------------------- | --------- | ----------------------------------------------- | ------ |
89-
| `dotnet_exceptions_total` | `Counter` | Count of exceptions thrown, broken down by type | `type` |
90-
9151
## `.WithContentionStats()`
9252

9353
Include metrics around volume of locks contended.
@@ -116,9 +76,9 @@ Include metrics around the size of the worker and IO thread pools and reasons
11676
| Name | Type | Description | Labels |
11777
| ------------------------------------ | ----------- | ----------------------------------------------------------------------------------------------------------------------------- | ------ |
11878
| `dotnet_threadpool_queue_length` | `Histogram` | Measures the queue length of the thread pool. Values greater than 0 indicate a backlog of work for the threadpool to process. | |
119-
| `dotnet_threadpool_timer_count` | `Gauge` | The number of timers active | |
120-
| `dotnet_threadpool_throughput_total` | `Counter` | The total number of work items that have finished execution in the thread pool | |
12179
| `dotnet_threadpool_num_threads` | `Gauge` | The number of active threads in the thread pool | |
80+
| `dotnet_threadpool_throughput_total` | `Counter` | The total number of work items that have finished execution in the thread pool | |
81+
| `dotnet_threadpool_timer_count` | `Gauge` | The number of timers active | |
12282

12383
### `CaptureLevel.Informational`
12484

@@ -128,3 +88,56 @@ Includes metrics generated by `CaptureLevel.Counters` plus:
12888
| ------------------------------------- | --------- | ------------------------------------------------------------------------------------------------- | ------------------- |
12989
| `dotnet_threadpool_io_num_threads` | `Gauge` | The number of active threads in the IO thread pool | |
13090
| `dotnet_threadpool_adjustments_total` | `Counter` | The total number of changes made to the size of the thread pool, labeled by the reason for change | `adjustment_reason` |
91+
92+
## `.WithJitStats()`
93+
94+
Include metrics summarizing the volume of methods being compiled
95+
by the Just\-In\-Time compiler.
96+
97+
### `CaptureLevel.Counters`
98+
99+
| Name | Type | Description | Labels |
100+
| ------------------------- | --------- | ---------------------------------------------------- | ------ |
101+
| `dotnet_jit_il_bytes` | `Gauge` | Total bytes of IL compiled by the JIT compiler | |
102+
| `dotnet_jit_method_total` | `Counter` | Total number of methods compiled by the JIT compiler | |
103+
104+
### `CaptureLevel.Verbose`
105+
106+
Includes metrics generated by `CaptureLevel.Counters` plus:
107+
108+
| Name | Type | Description | Labels |
109+
| --------------------------------- | --------- | ------------------------------------------------------------------------------------------------- | --------- |
110+
| `dotnet_jit_method_seconds_total` | `Counter` | Total number of seconds spent in the JIT compiler, broken down by compilation for dynamic code | `dynamic` |
111+
| `dotnet_jit_method_total` | `Counter` | Total number of methods compiled by the JIT compiler, broken down by compilation for dynamic code | `dynamic` |
112+
| `dotnet_jit_cpu_ratio` | `Gauge` | The amount of total CPU time consumed spent JIT'ing | |
113+
114+
## `.WithExceptionStats()`
115+
116+
Include metrics that measure the number of exceptions thrown.
117+
118+
### `CaptureLevel.Counters`
119+
120+
| Name | Type | Description | Labels |
121+
| ------------------------- | --------- | -------------------------- | ------ |
122+
| `dotnet_exceptions_total` | `Counter` | Count of exceptions thrown | |
123+
124+
### `CaptureLevel.Errors`
125+
126+
Includes metrics generated by `CaptureLevel.Counters` plus:
127+
128+
| Name | Type | Description | Labels |
129+
| ------------------------- | --------- | ----------------------------------------------- | ------ |
130+
| `dotnet_exceptions_total` | `Counter` | Count of exceptions thrown, broken down by type | `type` |
131+
132+
## `.WithSocketStats()`
133+
134+
Include metrics around established TCP connections and the volume of bytes sent\/ received over the network.
135+
136+
### `CaptureLevel.Counters`
137+
138+
| Name | Type | Description | Labels |
139+
| ------------------------------------------------------- | --------- | -------------------------------------------------------- | ------ |
140+
| `dotnet_sockets_connections_established_incoming_total` | `Counter` | The total number of incoming established TCP connections | |
141+
| `dotnet_sockets_connections_established_outgoing_total` | `Counter` | The total number of outgoing established TCP connections | |
142+
| `dotnet_sockets_bytes_received_total` | `Counter` | The total number of bytes received over the network | |
143+
| `dotnet_sockets_bytes_sent_total` | `Counter` | The total number of bytes sent over the network | |

examples/AspNetCoreExample/Controllers/SimulateController.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Linq.Expressions;
5+
using System.Net.Http;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Microsoft.AspNetCore.Mvc;
@@ -12,12 +13,20 @@ namespace AspNetCoreExample.Controllers
1213
[ApiController]
1314
public class SimulateController : ControllerBase
1415
{
16+
private readonly IHttpClientFactory _httpClientFactory;
17+
18+
public SimulateController(IHttpClientFactory httpClientFactory)
19+
{
20+
_httpClientFactory = httpClientFactory;
21+
}
22+
1523
[HttpGet]
1624
public async Task<ActionResult<IEnumerable<string>>> Get(
1725
bool simulateAlloc = true,
1826
bool simulateJit = true,
1927
bool simulateException = true,
20-
bool simulateBlocking = false)
28+
bool simulateBlocking = false,
29+
bool simulateOutgoingNetwork = true)
2130
{
2231
var r = new Random();
2332
if (simulateAlloc)
@@ -55,6 +64,12 @@ public async Task<ActionResult<IEnumerable<string>>> Get(
5564
Thread.Sleep(100);
5665
}
5766

67+
if (simulateOutgoingNetwork)
68+
{
69+
using var client = _httpClientFactory.CreateClient();
70+
using var _ = await client.GetAsync("https://httpstat.us/200");
71+
}
72+
5873
return new string[] {"value1" + r.Next(), "value2"+ r.Next()};
5974
}
6075

examples/AspNetCoreExample/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.Tracing;
34
using System.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;

examples/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ services:
6363
environment:
6464
- ASPNETCORE_URLS=http://+:5000
6565
# Additional vars that can be set to tweak behaviour
66-
#- Example__UseDefaultMetrics=true
66+
- Example__UseDefaultMetrics=true
6767
#- Example__EnableMetrics=false
6868
#- Example__UseDebuggingMetrics=true
6969
#- Example__RecycleEvery=00:10:00

0 commit comments

Comments
 (0)