-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
80ee563
commit ddb671f
Showing
9 changed files
with
500 additions
and
4 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ receivers: | |
memory: | ||
disk: | ||
filesystem: | ||
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
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
// 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 | ||
} |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
// 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{} | ||
} | ||
|
||
// 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" | ||
) | ||
|
||
// network 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.