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

[receivers/hostmetrics] add conntrack metrics #11769

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ These are the metrics available for this scraper.
| Name | Description | Unit | Type | Attributes |
| ---- | ----------- | ---- | ---- | ---------- |
| **system.network.connections** | The number of connections. | {connections} | Sum(Int) | <ul> <li>protocol</li> <li>state</li> </ul> |
| system.network.conntrack.count | The count of entries in conntrack table. | {entries} | Sum(Int) | <ul> </ul> |
| system.network.conntrack.max | The limit for entries in the conntrack table. | {entries} | Sum(Int) | <ul> </ul> |
| **system.network.dropped** | The number of packets dropped. (Deprecated) | {packets} | Sum(Int) | <ul> <li>device</li> <li>direction</li> </ul> |
| **system.network.dropped.receive** | The number of packets dropped on receive. | {packets} | Sum(Int) | <ul> <li>device</li> </ul> |
| **system.network.dropped.transmit** | The number of packets dropped on transmit. | {packets} | Sum(Int) | <ul> <li>device</li> </ul> |
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 @@ -159,3 +159,22 @@ metrics:
aggregation: cumulative
monotonic: false
attributes: [protocol, state]

system.network.conntrack.count:
enabled: false
description: The count of entries in conntrack table.
unit: "{entries}"
sum:
value_type: int
aggregation: cumulative
monotonic: false

system.network.conntrack.max:
enabled: false
description: The limit for entries in the conntrack table.
unit: "{entries}"
sum:
value_type: int
aggregation: cumulative
monotonic: false

codeboten marked this conversation as resolved.
Show resolved Hide resolved
dmitryax marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

package networkscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/networkscraper"

import (
"fmt"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
)

var allTCPStates = []string{
"CLOSE_WAIT",
"CLOSE",
Expand All @@ -31,3 +38,14 @@ var allTCPStates = []string{
"SYN_RECV",
"TIME_WAIT",
}

func (s *scraper) recordNetworkConntrackMetrics() error {
now := pcommon.NewTimestampFromTime(time.Now())
conntrack, err := s.conntrack()
if err != nil {
return fmt.Errorf("failed to read conntrack info: %w", err)
}
s.mb.RecordSystemNetworkConntrackCountDataPoint(now, conntrack[0].ConnTrackCount)
s.mb.RecordSystemNetworkConntrackMaxDataPoint(now, conntrack[0].ConnTrackMax)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ var allTCPStates = []string{
"SYN_RECEIVED",
"TIME_WAIT",
}

func (s *scraper) recordNetworkConntrackMetrics() error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,23 @@ type scraper struct {
bootTime func() (uint64, error)
ioCounters func(bool) ([]net.IOCountersStat, error)
connections func(string) ([]net.ConnectionStat, error)
conntrack func() ([]net.FilterStat, error)
emitMetricsWithDirectionAttribute bool
emitMetricsWithoutDirectionAttribute bool
}

// newNetworkScraper creates a set of Network related metrics
func newNetworkScraper(_ context.Context, settings component.ReceiverCreateSettings, cfg *Config) (*scraper, error) {
scraper := &scraper{settings: settings, config: cfg, bootTime: host.BootTime, ioCounters: net.IOCounters, connections: net.Connections}
scraper.emitMetricsWithDirectionAttribute = featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithDirectionAttributeFeatureGateID)
scraper.emitMetricsWithoutDirectionAttribute = featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithoutDirectionAttributeFeatureGateID)
scraper := &scraper{
settings: settings,
config: cfg,
bootTime: host.BootTime,
ioCounters: net.IOCounters,
connections: net.Connections,
conntrack: net.FilterCounters,
emitMetricsWithDirectionAttribute: featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithDirectionAttributeFeatureGateID),
emitMetricsWithoutDirectionAttribute: featuregate.GetRegistry().IsEnabled(internal.EmitMetricsWithoutDirectionAttributeFeatureGateID),
}

var err error

Expand Down Expand Up @@ -103,6 +111,11 @@ func (s *scraper) scrape(_ context.Context) (pmetric.Metrics, error) {
errors.AddPartial(connectionsMetricsLen, err)
}

err = s.recordNetworkConntrackMetrics()
if err != nil {
errors.AddPartial(connectionsMetricsLen, err)
}

return s.mb.Emit(), errors.Combine()
}

Expand Down
16 changes: 16 additions & 0 deletions unreleased/hostmetrics-conntrack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: hostmetrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adding connection tracking count and max metrics for linux"

# One or more tracking issues related to the change
issues: [ 11769 ]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: