Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/hostmetrics] add udp connections #11046

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions receiver/hostmetricsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ The following feature gates control the transition process:
- **receiver.hostmetricsreceiver.emitMetricsWithoutDirectionAttribute**: controls if the new metrics without
`direction` attribute are emitted by the receiver.
- **receiver.hostmetricsreceiver.emitMetricsWithDirectionAttribute**: controls if the deprecated metrics with
`direction`
attribute are emitted by the receiver.
`direction` attribute are emitted by the receiver.

##### Transition schedule:

Expand Down Expand Up @@ -242,6 +241,64 @@ receivers:
- https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/11815
- https://github.com/open-telemetry/opentelemetry-specification/pull/2617

#### Transition from metrics with "protocol" attribute

Some host metrics reported are transitioning from being reported with a `protocol` attribute to being reported with the
protocol included in the metric name to adhere to the OpenTelemetry specification
(https://github.com/open-telemetry/opentelemetry-specification/pull/2675):

- `network` scraper metrics:
- `system.network.connections` will become:
- `system.network.tcp.connections`
- `system.network.udp.connections`

The following feature gates control the transition process:

- **receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute**: controls if the new metrics without
`protocol` attribute are emitted by the receiver.
- **receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute**: controls if the deprecated metrics with
`protocol` attribute are emitted by the receiver.

##### Transition schedule:

1. v0.58.0, August 2022:

- The new metrics are available for network scraper, but disabled by default, they can be enabled with the feature gates.
- The old metrics with `protocol` attribute are deprecated with a warning.
- `receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute` is enabled by default.
- `receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute` is disabled by default.

2. v0.60.0, September 2022:

- The new metrics are enabled by default, deprecated metrics disabled, they can be enabled with the feature gates.
- `receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute` is disabled by default.
- `receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute` is enabled by default.

3. v0.62.0, October 2022:

- The feature gates are removed.
- The new metrics without `protocol` attribute are always emitted.
- The deprecated metrics with `protocol` attribute are no longer available.

##### Usage:

To enable the new metrics without `protocol` attribute and disable the deprecated metrics, run OTel Collector with the
following arguments:

```sh
otelcol --feature-gates=-receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute,+receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute
```

It's also possible to emit both the deprecated and the new metrics:

```sh
otelcol --feature-gates=+receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute,+receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute
```

##### More information:

- https://github.com/open-telemetry/opentelemetry-specification/pull/2675

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol
Expand Down
23 changes: 23 additions & 0 deletions receiver/hostmetricsreceiver/internal/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
const (
EmitMetricsWithDirectionAttributeFeatureGateID = "receiver.hostmetricsreceiver.emitMetricsWithDirectionAttribute"
EmitMetricsWithoutDirectionAttributeFeatureGateID = "receiver.hostmetricsreceiver.emitMetricsWithoutDirectionAttribute"
EmitMetricsWithProtocolAttributeFeatureGateID = "receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute"
EmitMetricsWithoutProtocolAttributeFeatureGateID = "receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute"
)

var (
Expand All @@ -47,11 +49,32 @@ var (
"attribute. For more details, see: " +
"https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md#feature-gate-configurations",
}
emitMetricsWithProtocolAttributeFeatureGate = featuregate.Gate{
ID: EmitMetricsWithProtocolAttributeFeatureGateID,
Enabled: true,
Description: "Some process host metrics reported are transitioning from being reported with a protocol " +
"attribute to being reported with the protocol included in the metric name to adhere to the " +
"OpenTelemetry specification. This feature gate controls emitting the old metrics with the protocol " +
"attribute. For more details, see: " +
"https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md#feature-gate-configurations",
}

emitMetricsWithoutProtocolAttributeFeatureGate = featuregate.Gate{
ID: EmitMetricsWithoutProtocolAttributeFeatureGateID,
Enabled: false,
Description: "Some process host metrics reported are transitioning from being reported with a protcol " +
"attribute to being reported with the protocol included in the metric name to adhere to the " +
"OpenTelemetry specification. This feature gate controls emitting the new metrics without the protocol " +
"attribute. For more details, see: " +
"https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md#feature-gate-configurations",
}
)

func init() {
featuregate.GetRegistry().MustRegister(emitMetricsWithDirectionAttributeFeatureGate)
featuregate.GetRegistry().MustRegister(emitMetricsWithoutDirectionAttributeFeatureGate)
featuregate.GetRegistry().MustRegister(emitMetricsWithProtocolAttributeFeatureGate)
featuregate.GetRegistry().MustRegister(emitMetricsWithoutProtocolAttributeFeatureGate)
}

// ScraperFactory can create a MetricScraper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ These are the metrics available for this scraper.
| **system.network.packets** | The number of packets transferred. (Deprecated) | {packets} | Sum(Int) | <ul> <li>device</li> <li>direction</li> </ul> |
| **system.network.packets.receive** | The number of packets received. | {packets} | Sum(Int) | <ul> <li>device</li> </ul> |
| **system.network.packets.transmit** | The number of packets transmitted. | {packets} | Sum(Int) | <ul> <li>device</li> </ul> |
| **system.network.tcp.connections** | The number of TCP connections. | {connections} | Sum(Int) | <ul> <li>state</li> </ul> |
| **system.network.udp.connections** | The number of UDP connections. | {connections} | Sum(Int) | <ul> </ul> |

**Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default.
Any metric can be enabled or disabled with the following scraper configuration:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ metrics:
monotonic: true
attributes: [device]

# produced when receiver.hostmetricsreceiver.emitMetricsWithProtocolAttribute feature gate is enabled
system.network.connections:
enabled: true
description: The number of connections.
Expand All @@ -160,6 +161,27 @@ metrics:
monotonic: false
attributes: [protocol, state]

# produced when receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute feature gate is enabled
system.network.tcp.connections:
enabled: true
description: The number of TCP connections.
unit: "{connections}"
sum:
value_type: int
aggregation: cumulative
monotonic: false
attributes: [state]

# produced when receiver.hostmetricsreceiver.emitMetricsWithoutProtocolAttribute feature gate is enabled
system.network.udp.connections:
enabled: true
description: The number of UDP connections.
unit: "{connections}"
sum:
value_type: int
aggregation: cumulative
monotonic: false

system.network.conntrack.count:
enabled: false
description: The count of entries in conntrack table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type scraper struct {
conntrack func() ([]net.FilterStat, error)
emitMetricsWithDirectionAttribute bool
emitMetricsWithoutDirectionAttribute bool
emitMetricsWithProtocolAttribute bool
emitMetricsWithoutProtocolAttribute bool
}

// newNetworkScraper creates a set of Network related metrics
Expand All @@ -66,6 +68,8 @@ func newNetworkScraper(_ context.Context, settings component.ReceiverCreateSetti
conntrack: net.FilterCounters,
emitMetricsWithDirectionAttribute: featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithDirectionAttributeFeatureGateID),
emitMetricsWithoutDirectionAttribute: featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithoutDirectionAttributeFeatureGateID),
emitMetricsWithProtocolAttribute: featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithProtocolAttributeFeatureGateID),
emitMetricsWithoutProtocolAttribute: featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithoutProtocolAttributeFeatureGateID),
}

var err error
Expand Down Expand Up @@ -202,8 +206,16 @@ func (s *scraper) recordNetworkConnectionsMetrics() error {
}

tcpConnectionStatusCounts := getTCPConnectionStatusCounts(connections)
s.recordNetworkTCPConnectionsMetric(now, tcpConnectionStatusCounts)

s.recordNetworkConnectionsMetric(now, tcpConnectionStatusCounts)
if s.emitMetricsWithoutProtocolAttribute {
connections, err = s.connections("udp")
if err != nil {
return fmt.Errorf("failed to read UDP connections: %w", err)
}

s.mb.RecordSystemNetworkUDPConnectionsDataPoint(now, int64(len(connections)))
}
return nil
}

Expand All @@ -219,9 +231,14 @@ func getTCPConnectionStatusCounts(connections []net.ConnectionStat) map[string]i
return tcpStatuses
}

func (s *scraper) recordNetworkConnectionsMetric(now pcommon.Timestamp, connectionStateCounts map[string]int64) {
func (s *scraper) recordNetworkTCPConnectionsMetric(now pcommon.Timestamp, connectionStateCounts map[string]int64) {
for connectionState, count := range connectionStateCounts {
s.mb.RecordSystemNetworkConnectionsDataPoint(now, count, metadata.AttributeProtocolTcp, connectionState)
if s.emitMetricsWithProtocolAttribute {
s.mb.RecordSystemNetworkConnectionsDataPoint(now, count, metadata.AttributeProtocolTcp, connectionState)
}
if s.emitMetricsWithoutProtocolAttribute {
s.mb.RecordSystemNetworkTCPConnectionsDataPoint(now, count, connectionState)
}
}
}

Expand Down
Loading