-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of host metrics network scraper
- Loading branch information
1 parent
51a6efd
commit a4c32d0
Showing
9 changed files
with
528 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ receivers: | |
report_per_cpu: true | ||
memory: | ||
disk: | ||
network: | ||
|
||
exporters: | ||
logging: | ||
|
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
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
28 changes: 28 additions & 0 deletions
28
receiver/hostmetricsreceiver/internal/scraper/networkscraper/config.go
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,28 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package networkscraper | ||
|
||
import "github.com/open-telemetry/opentelemetry-collector/receiver/hostmetricsreceiver/internal" | ||
|
||
// Config relating to Network Metric Scraper. | ||
type Config struct { | ||
internal.ConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct | ||
|
||
// If `true`, stats will be generated for the system as a whole _as well | ||
// as_ for each individual Network/core in the system and will be distinguished | ||
// by the `network` dimension. If `false`, stats will only be generated for | ||
// the system as a whole that will not include a `network` dimension. | ||
ReportPerNetwork bool `mapstructure:"report_per_network"` | ||
} |
53 changes: 53 additions & 0 deletions
53
receiver/hostmetricsreceiver/internal/scraper/networkscraper/factory.go
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,53 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package networkscraper | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/consumer" | ||
"github.com/open-telemetry/opentelemetry-collector/receiver/hostmetricsreceiver/internal" | ||
) | ||
|
||
// This file implements Factory for Network scraper. | ||
|
||
const ( | ||
// The value of "type" key in configuration. | ||
TypeStr = "network" | ||
) | ||
|
||
// Factory is the Factory for scraper. | ||
type Factory struct { | ||
} | ||
|
||
// CreateDefaultConfig creates the default configuration for the Scraper. | ||
func (f *Factory) CreateDefaultConfig() internal.Config { | ||
return &Config{ | ||
ReportPerNetwork: true, | ||
} | ||
} | ||
|
||
// CreateMetricsScraper creates a scraper based on provided config. | ||
func (f *Factory) CreateMetricsScraper( | ||
ctx context.Context, | ||
logger *zap.Logger, | ||
config internal.Config, | ||
consumer consumer.MetricsConsumer, | ||
) (internal.Scraper, error) { | ||
cfg := config.(*Config) | ||
return NewNetworkScraper(ctx, cfg, consumer) | ||
} |
33 changes: 33 additions & 0 deletions
33
receiver/hostmetricsreceiver/internal/scraper/networkscraper/factory_test.go
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,33 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package networkscraper | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestCreateMetricsScraper(t *testing.T) { | ||
factory := &Factory{} | ||
cfg := &Config{} | ||
|
||
scraper, err := factory.CreateMetricsScraper(context.Background(), zap.NewNop(), cfg, nil) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, scraper) | ||
} |
91 changes: 91 additions & 0 deletions
91
receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_constants.go
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,91 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package networkscraper | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector/consumer/pdata" | ||
) | ||
|
||
// disk metric constants | ||
|
||
const ( | ||
directionLabelName = "direction" | ||
stateLabelName = "state" | ||
) | ||
|
||
const ( | ||
receiveDirectionLabelValue = "receive" | ||
transmitDirectionLabelValue = "transmit" | ||
) | ||
|
||
var metricNetworkPacketsDescriptor = createMetricNetworkPacketsDescriptor() | ||
|
||
func createMetricNetworkPacketsDescriptor() pdata.MetricDescriptor { | ||
descriptor := pdata.NewMetricDescriptor() | ||
descriptor.InitEmpty() | ||
descriptor.SetName("host/network/packets") | ||
descriptor.SetDescription("The number of packets transferred.") | ||
descriptor.SetUnit("1") | ||
descriptor.SetType(pdata.MetricTypeCounterInt64) | ||
return descriptor | ||
} | ||
|
||
var metricNetworkDroppedPacketsDescriptor = createMetricNetworkDroppedPacketsDescriptor() | ||
|
||
func createMetricNetworkDroppedPacketsDescriptor() pdata.MetricDescriptor { | ||
descriptor := pdata.NewMetricDescriptor() | ||
descriptor.InitEmpty() | ||
descriptor.SetName("host/network/dropped_packets") | ||
descriptor.SetDescription("The number of packets dropped.") | ||
descriptor.SetUnit("1") | ||
descriptor.SetType(pdata.MetricTypeCounterInt64) | ||
return descriptor | ||
} | ||
|
||
var metricNetworkErrorsDescriptor = createMetricNetworkErrorsDescriptor() | ||
|
||
func createMetricNetworkErrorsDescriptor() pdata.MetricDescriptor { | ||
descriptor := pdata.NewMetricDescriptor() | ||
descriptor.InitEmpty() | ||
descriptor.SetName("host/network/errors") | ||
descriptor.SetDescription("The number of errors encountered") | ||
descriptor.SetUnit("1") | ||
descriptor.SetType(pdata.MetricTypeCounterInt64) | ||
return descriptor | ||
} | ||
|
||
var metricNetworkBytesDescriptor = createMetricNetworkBytesDescriptor() | ||
|
||
func createMetricNetworkBytesDescriptor() pdata.MetricDescriptor { | ||
descriptor := pdata.NewMetricDescriptor() | ||
descriptor.InitEmpty() | ||
descriptor.SetName("host/network/bytes") | ||
descriptor.SetDescription("The number of bytes transmitted and received") | ||
descriptor.SetUnit("bytes") | ||
descriptor.SetType(pdata.MetricTypeCounterInt64) | ||
return descriptor | ||
} | ||
|
||
var metricNetworkTCPConnectionDescriptor = createMetricNetworkTCPConnectionDescriptor() | ||
|
||
func createMetricNetworkTCPConnectionDescriptor() pdata.MetricDescriptor { | ||
descriptor := pdata.NewMetricDescriptor() | ||
descriptor.InitEmpty() | ||
descriptor.SetName("host/network/tcp_connections") | ||
descriptor.SetDescription("The number of tcp connections") | ||
descriptor.SetUnit("bytes") | ||
descriptor.SetType(pdata.MetricTypeGaugeInt64) | ||
return descriptor | ||
} |
Oops, something went wrong.