|
| 1 | +--- |
| 2 | +title: System.Net Metrics |
| 3 | +description: Review the metrics available for System.Net |
| 4 | +ms.topic: reference |
| 5 | +ms.date: 9/21/2023 |
| 6 | +--- |
| 7 | + |
| 8 | +# System.Net Metrics |
| 9 | + |
| 10 | +This article describes the networking metrics built-in for <xref:System.Net> produced using the |
| 11 | +<xref:System.Diagnostics.Metrics?displayProperty=nameWithType> API. For a listing of metrics based on the alternate [EventCounters](event-counters.md) API, |
| 12 | +see [here](available-counters.md). |
| 13 | + |
| 14 | +- [Meter: `System.Net.NameResolution`](#meter-systemnetnameresolution) - Metrics for DNS lookups |
| 15 | + * [Instrument: `dns.lookup.duration`](#instrument-dnslookupduration) |
| 16 | +- [Meter: `System.Net.Http`](#meter-systemnethttp) - Metrics for outbound networking requests using HttpClient |
| 17 | + * [Instrument: `http.client.open_connections`](#instrument-httpclientopen_connections) |
| 18 | + * [Instrument: `http.client.connection.duration`](#instrument-httpclientconnectionduration) |
| 19 | + * [Instrument: `http.client.request.duration`](#instrument-httpclientrequestduration) |
| 20 | + * [Instrument: `http.client.request.time_in_queue`](#instrument-httpclientrequesttime_in_queue) |
| 21 | + * [Instrument: `http.client.active_requests`](#instrument-httpclientactive_requests) |
| 22 | + |
| 23 | +## Meter: `System.Net.NameResolution` |
| 24 | + |
| 25 | +### Instrument: `dns.lookup.duration` |
| 26 | + |
| 27 | +| Name | Instrument Type | Unit | Description | |
| 28 | +| -------- | --------------- | ----------- | -------------- | |
| 29 | +| `dns.lookup.duration` | Histogram | `s` | Measures the time taken to perform a DNS lookup. | |
| 30 | + |
| 31 | +| Attribute | Type | Description | Examples | Presence | |
| 32 | +|---|---|---|---|---| |
| 33 | +| `dns.question.name` | string | The name being queried. | `www.example.com`; `dot.net` | Always | |
| 34 | +| `error.type` | string | A well-known error string or the full type name of an exception that occured. | `host_not_found`; `System.Net.Sockets.SocketException` | If an error occured | |
| 35 | + |
| 36 | +This metric measures the time take to make DNS requests. These requests can occur by calling methods on |
| 37 | +<xref:System.Net.Dns> or indirectly wihtin higher level APIs on types such as <xref:System.Net.Http.HttpClient>. |
| 38 | + |
| 39 | +Most errors when doing a DNS lookup throw a <xref:System.Net.Sockets.SocketException>. To better disambiguate the common error cases, SocketExceptions with specific <xref:System.Net.Sockets.SocketException.SocketErrorCode> |
| 40 | +are given explicit error names in `error.type`: |
| 41 | + |
| 42 | +| SocketErrorCode | `error.type` | |
| 43 | +| --------------- | ------------ | |
| 44 | +| <xref:System.Net.Sockets.SocketError.HostNotFound> | host_not_found | |
| 45 | +| <xref:System.Net.Sockets.SocketError.TryAgain> | try_again | |
| 46 | +| <xref:System.Net.Sockets.SocketError.AddressFamilyNotSupported> | address_family_not_supported | |
| 47 | +| <xref:System.Net.Sockets.SocketError.NoRecovery> | no_recovery | |
| 48 | + |
| 49 | +SocketExceptions with any other SocketError value are reported as `System.Net.Sockets.SocketException`. |
| 50 | + |
| 51 | +Available starting in: .NET 8 |
| 52 | + |
| 53 | +## Meter: `System.Net.Http` |
| 54 | + |
| 55 | +### Instrument: `http.client.open_connections` |
| 56 | + |
| 57 | +| Name | Instrument Type | Unit (UCUM) | Description | |
| 58 | +| -------- | --------------- | ----------- | -------------- | |
| 59 | +| `http.client.open_connections` | UpDownCounter | `{connection}` | Number of outbound HTTP connections that are currently active or idle on the client | |
| 60 | + |
| 61 | +| Attribute | Type | Description | Examples | Presence | |
| 62 | +|---|---|---|---|---| |
| 63 | +| `http.connection.state` | string | State of HTTP connection in the HTTP connection pool. | `active`; `idle` | Always | |
| 64 | +| `network.protocol.version` | string | Version of the application layer protocol used. | `1.1`; `2` | Always | |
| 65 | +| `server.address` | string | Host identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `example.com` | Always | |
| 66 | +| `server.port` | int | Port identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `80`; `8080`; `443` | If not default (`80` for `http` scheme, `443` for `https`) | |
| 67 | +| `network.peer.address` | string | Peer IP address of the socket connection. | `10.5.3.2` | Always | |
| 68 | +| `url.scheme` | string | The [URI scheme](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) component identifying the used protocol. | `http`; `https`; `ftp` | Always | |
| 69 | + |
| 70 | +<xref:System.Net.Http.HttpClient>, when configured to use the default <xref:System.Net.Http.SocketsHttpHandler>, maintains a cached pool of network connections for sending HTTP messages. This metric counts how many connections are currently |
| 71 | +in the pool. Active connections are handling active requests. Active connects could be transmitting data or awaiting the client or server. Idle connections aren't handling any |
| 72 | +requests, but are left open so that future requests can be handled more quickly. |
| 73 | + |
| 74 | +Available starting in: .NET 8 |
| 75 | + |
| 76 | +### Instrument: `http.client.connection.duration` |
| 77 | + |
| 78 | +| Name | Instrument Type | Unit (UCUM) | Description | |
| 79 | +| -------- | --------------- | ----------- | -------------- | |
| 80 | +| `http.client.connection.duration` | Histogram | `s` | The duration of successfully established outbound HTTP connections. | |
| 81 | + |
| 82 | +| Attribute | Type | Description | Examples | Presence | |
| 83 | +|---|---|---|---|---| |
| 84 | +| `network.protocol.version` | string | Version of the application layer protocol used. | `1.1`; `2` | Always | |
| 85 | +| `server.address` | string | Host identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `example.com` | Always | |
| 86 | +| `server.port` | int | Port identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `80`; `8080`; `443` | If not default (`80` for `http` scheme, `443` for `https`) | |
| 87 | +| `network.peer.address` | string | IP address of the socket connection. | `10.5.3.2` | Always | |
| 88 | +| `url.scheme` | string | The [URI scheme](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) component identifying the used protocol. | `http`; `https`; `ftp` | Always | |
| 89 | + |
| 90 | +This metric is only captured when <xref:System.Net.Http.HttpClient> is configured to use the default <xref:System.Net.Http.SocketsHttpHandler>. |
| 91 | + |
| 92 | +Available starting in: .NET 8 |
| 93 | + |
| 94 | +### Instrument: `http.client.request.duration` |
| 95 | + |
| 96 | +| Name | Instrument Type | Unit (UCUM) | Description | |
| 97 | +| -------- | --------------- | ----------- | -------------- | |
| 98 | +| `http.client.request.duration` | Histogram | `s` | The duration of outbound HTTP requests. | |
| 99 | + |
| 100 | +| Attribute | Type | Description | Examples | Presence | |
| 101 | +|---|---|---|---|---| |
| 102 | +| `http.error.reason` | string | Request failure reason: one of [HTTP Request errors](https://github.com/dotnet/runtime/blob/c430570a01c103bc7f117be573f37d8ce8a129b8/src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestError.cs), or a full exception type, or an HTTP 4xx/5xx status code. | `System.Threading.Tasks.TaskCanceledException`; `name_resolution_error`; `secure_connection_error` ; `404` | If request has failed. | |
| 103 | +| `http.request.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | Always | |
| 104 | +| `http.response.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | If one was received. | |
| 105 | +| `network.protocol.version` | string | Version of the application layer protocol used. | `1.1`; `2` | Always | |
| 106 | +| `server.address` | string | Host identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `example.com` | Always | |
| 107 | +| `server.port` | int | Port identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `80`; `8080`; `443` | If not default (`80` for `http` scheme, `443` for `https`) | |
| 108 | +| `url.scheme` | string | The [URI scheme](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) component identifying the used protocol. | `http`; `https`; `ftp` | Always | |
| 109 | + |
| 110 | +HTTP client request duration measures the time the underlying client handler takes to complete the request up to reading response headers from the network |
| 111 | +stream. It does not include the time spent reading the response body. |
| 112 | + |
| 113 | +Available starting in: .NET 8 |
| 114 | + |
| 115 | +### Instrument: `http.client.request.time_in_queue` |
| 116 | + |
| 117 | +| Name | Instrument Type | Unit (UCUM) | Description | |
| 118 | +| -------- | --------------- | ----------- | -------------- | |
| 119 | +| `http.client.request.time_in_queue` | Histogram | `s` | The amount of time requests spent on a queue waiting for an available connection. | |
| 120 | + |
| 121 | +| Attribute | Type | Description | Examples | Presence | |
| 122 | +|---|---|---|---|---| |
| 123 | +| `http.request.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | Always | |
| 124 | +| `network.protocol.version` | string | Version of the application layer protocol used. | `1.1`; `2` | Always | |
| 125 | +| `server.address` | string | Host identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `example.com` | Always | |
| 126 | +| `server.port` | int | Port identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `80`; `8080`; `443` | If not default (`80` for `http` scheme, `443` for `https`) | |
| 127 | +| `url.scheme` | string | The [URI scheme](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) component identifying the used protocol. | `http`; `https`; `ftp` | Always | |
| 128 | + |
| 129 | +<xref:System.Net.Http.HttpClient>, when configured to use the default <xref:System.Net.Http.SocketsHttpHandler>, sends HTTP requests using a pool of network connections. |
| 130 | +If all connections are already busy handling other requests, new requests are placed in a queue and wait until a network connection is available for use. This instrument |
| 131 | +measures the amount of time HTTP requests spend waiting in that queue, prior to anything being sent across the network. |
| 132 | + |
| 133 | +Available starting in: .NET 8 |
| 134 | + |
| 135 | +### Instrument: `http.client.active_requests` |
| 136 | + |
| 137 | +| Name | Instrument Type | Unit (UCUM) | Description | |
| 138 | +| -------- | --------------- | ----------- | -------------- | |
| 139 | +| `http.client.active_requests` | UpDownCounter | `{request}` | Number of active HTTP requests. | |
| 140 | + |
| 141 | +| Attribute | Type | Description | Examples | Presence | |
| 142 | +|---|---|---|---|---| |
| 143 | +| `http.request.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | Always | |
| 144 | +| `network.protocol.version` | string | Version of the application layer protocol used. | `1.1`; `2` | Always | |
| 145 | +| `server.address` | string | Host identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `example.com` | Always | |
| 146 | +| `server.port` | int | Port identifier of the ["URI origin"](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin) HTTP request is sent to. | `80`; `8080`; `443` | If not default (`80` for `http` scheme, `443` for `https`) | |
| 147 | +| `url.scheme` | string | The [URI scheme](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) component identifying the used protocol. | `http`; `https`; `ftp` | Always | |
| 148 | + |
| 149 | +This metric counts how many requests are considered active. Requests are active for the same time period that is measured by the [http.client.request.duration](#instrument-httpclientrequestduration) instrument. |
| 150 | + |
| 151 | +Available starting in: .NET 8 |
0 commit comments