Skip to content

Commit

Permalink
Rename host metrics according to metrics spec
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington committed Dec 21, 2020
1 parent d47baee commit 3c5eee9
Show file tree
Hide file tree
Showing 33 changed files with 355 additions and 218 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/prometheus/common v0.15.0
github.com/prometheus/prometheus v1.8.2-0.20201105135750-00f16d1ac3a4
github.com/rs/cors v1.7.0
github.com/shirou/gopsutil v3.20.11+incompatible
github.com/shirou/gopsutil v3.20.12-0.20201210134652-afe0c04c5d5a+incompatible
github.com/soheilhy/cmux v0.1.4
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.1.1
Expand Down
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ The available scrapers are:
| filesystem | All | File System utilization metrics |
| memory | All | Memory utilization metrics |
| network | All | Network interface I/O metrics & TCP connection metrics |
| paging | All | Paging/Swap space utilization and I/O metrics
| processes | Linux | Process count metrics |
| swap | All | Swap space utilization and I/O metrics |
| process | Linux & Windows | Per process CPU, Memory, and Disk I/O metrics |

### Notes
Expand Down
4 changes: 2 additions & 2 deletions receiver/hostmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/loadscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/memoryscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/networkscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/swapscraper"
"go.opentelemetry.io/collector/receiver/scraperhelper"
)

Expand Down Expand Up @@ -82,7 +82,7 @@ func TestLoadConfig(t *testing.T) {
},
},
processesscraper.TypeStr: &processesscraper.Config{},
swapscraper.TypeStr: &swapscraper.Config{},
pagingscraper.TypeStr: &pagingscraper.Config{},
processscraper.TypeStr: &processscraper.Config{
Include: processscraper.MatchConfig{
Names: []string{"test2", "test3"},
Expand Down
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ receivers:
disk:
filesystem:
network:
paging:
processes:
swap:

exporters:
logging:
Expand Down
4 changes: 2 additions & 2 deletions receiver/hostmetricsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/loadscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/memoryscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/networkscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/swapscraper"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.opentelemetry.io/collector/receiver/scraperhelper"
)
Expand All @@ -56,8 +56,8 @@ var (
filesystemscraper.TypeStr: &filesystemscraper.Factory{},
memoryscraper.TypeStr: &memoryscraper.Factory{},
networkscraper.TypeStr: &networkscraper.Factory{},
pagingscraper.TypeStr: &pagingscraper.Factory{},
processesscraper.TypeStr: &processesscraper.Factory{},
swapscraper.TypeStr: &swapscraper.Factory{},
}

resourceScraperFactories = map[string]internal.ResourceScraperFactory{
Expand Down
52 changes: 26 additions & 26 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ import (
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/loadscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/memoryscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/networkscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/swapscraper"
"go.opentelemetry.io/collector/receiver/scraperhelper"
)

var standardMetrics = []string{
"system.cpu.time",
"system.memory.usage",
"system.cpu.load_average.1m",
"system.cpu.load_average.5m",
"system.cpu.load_average.15m",
"system.disk.io",
"system.disk.io_time",
"system.disk.ops",
"system.disk.operations",
"system.disk.operation_time",
"system.disk.pending_operations",
"system.filesystem.usage",
"system.cpu.load_average.1m",
"system.cpu.load_average.5m",
"system.cpu.load_average.15m",
"system.network.packets",
"system.network.dropped_packets",
"system.memory.usage",
"system.network.connections",
"system.network.dropped",
"system.network.errors",
"system.network.io",
"system.network.tcp_connections",
"system.swap.paging_ops",
"system.swap.usage",
"system.network.packets",
"system.paging.operations",
"system.paging.usage",
}

var resourceMetrics = []string{
Expand All @@ -72,11 +72,11 @@ var resourceMetrics = []string{
}

var systemSpecificMetrics = map[string][]string{
"linux": {"system.disk.merged", "system.filesystem.inodes.usage", "system.processes.running", "system.processes.blocked", "system.swap.page_faults"},
"darwin": {"system.filesystem.inodes.usage", "system.processes.running", "system.processes.blocked", "system.swap.page_faults"},
"freebsd": {"system.filesystem.inodes.usage", "system.processes.running", "system.processes.blocked", "system.swap.page_faults"},
"openbsd": {"system.filesystem.inodes.usage", "system.processes.running", "system.processes.blocked", "system.swap.page_faults"},
"solaris": {"system.filesystem.inodes.usage", "system.swap.page_faults"},
"linux": {"system.disk.merged", "system.filesystem.inodes.usage", "system.paging.faults", "system.processes.created", "system.processes.count"},
"darwin": {"system.filesystem.inodes.usage", "system.paging.faults", "system.processes.count"},
"freebsd": {"system.filesystem.inodes.usage", "system.paging.faults", "system.processes.count"},
"openbsd": {"system.filesystem.inodes.usage", "system.paging.faults", "system.processes.created", "system.processes.count"},
"solaris": {"system.filesystem.inodes.usage", "system.paging.faults"},
}

var factories = map[string]internal.ScraperFactory{
Expand All @@ -86,8 +86,8 @@ var factories = map[string]internal.ScraperFactory{
loadscraper.TypeStr: &loadscraper.Factory{},
memoryscraper.TypeStr: &memoryscraper.Factory{},
networkscraper.TypeStr: &networkscraper.Factory{},
pagingscraper.TypeStr: &pagingscraper.Factory{},
processesscraper.TypeStr: &processesscraper.Factory{},
swapscraper.TypeStr: &swapscraper.Factory{},
}

var resourceFactories = map[string]internal.ResourceScraperFactory{
Expand All @@ -111,8 +111,8 @@ func TestGatherMetrics_EndToEnd(t *testing.T) {
loadscraper.TypeStr: &loadscraper.Config{},
memoryscraper.TypeStr: &memoryscraper.Config{},
networkscraper.TypeStr: &networkscraper.Config{},
pagingscraper.TypeStr: &pagingscraper.Config{},
processesscraper.TypeStr: &processesscraper.Config{},
swapscraper.TypeStr: &swapscraper.Config{},
},
}

Expand Down Expand Up @@ -376,10 +376,10 @@ func Benchmark_ScrapeProcessesMetrics(b *testing.B) {
benchmarkScrapeMetrics(b, cfg)
}

func Benchmark_ScrapeSwapMetrics(b *testing.B) {
func Benchmark_ScrapePagingMetrics(b *testing.B) {
cfg := &Config{
ScraperControllerSettings: scraperhelper.DefaultScraperControllerSettings(""),
Scrapers: map[string]internal.Config{swapscraper.TypeStr: (&swapscraper.Factory{}).CreateDefaultConfig()},
Scrapers: map[string]internal.Config{pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig()},
}

benchmarkScrapeMetrics(b, cfg)
Expand Down Expand Up @@ -408,15 +408,19 @@ func Benchmark_ScrapeSystemMetrics(b *testing.B) {
loadscraper.TypeStr: (&loadscraper.Factory{}).CreateDefaultConfig(),
memoryscraper.TypeStr: (&memoryscraper.Factory{}).CreateDefaultConfig(),
networkscraper.TypeStr: (&networkscraper.Factory{}).CreateDefaultConfig(),
pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig(),
processesscraper.TypeStr: (&processesscraper.Factory{}).CreateDefaultConfig(),
swapscraper.TypeStr: (&swapscraper.Factory{}).CreateDefaultConfig(),
},
}

benchmarkScrapeMetrics(b, cfg)
}

func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) {
if runtime.GOOS != "linux" && runtime.GOOS != "windows" {
b.Skip("skipping test on non linux/windows")
}

cfg := &Config{
ScraperControllerSettings: scraperhelper.DefaultScraperControllerSettings(""),
Scrapers: map[string]internal.Config{
Expand All @@ -426,14 +430,10 @@ func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) {
loadscraper.TypeStr: &loadscraper.Config{},
memoryscraper.TypeStr: &memoryscraper.Config{},
networkscraper.TypeStr: &networkscraper.Config{},
pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig(),
processesscraper.TypeStr: &processesscraper.Config{},
swapscraper.TypeStr: &swapscraper.Config{},
},
}

if runtime.GOOS == "linux" || runtime.GOOS == "windows" {
cfg.Scrapers[processscraper.TypeStr] = &processscraper.Config{}
}

benchmarkScrapeMetrics(b, cfg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ var diskIODescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.disk.io")
metric.SetDescription("Disk bytes transferred.")
metric.SetUnit("bytes")
metric.SetUnit("By")
metric.SetDataType(pdata.MetricDataTypeIntSum)
sum := metric.IntSum()
sum.SetIsMonotonic(true)
sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
return metric
}()

var diskOpsDescriptor = func() pdata.Metric {
var diskOperationsDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.disk.ops")
metric.SetName("system.disk.operations")
metric.SetDescription("Disk operations count.")
metric.SetUnit("1")
metric.SetUnit("{operations}")
metric.SetDataType(pdata.MetricDataTypeIntSum)
sum := metric.IntSum()
sum.SetIsMonotonic(true)
Expand Down Expand Up @@ -86,7 +86,7 @@ var diskPendingOperationsDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.disk.pending_operations")
metric.SetDescription("The queue size of pending I/O operations.")
metric.SetUnit("1")
metric.SetUnit("{operations}")
metric.SetDataType(pdata.MetricDataTypeIntSum)
sum := metric.IntSum()
sum.SetIsMonotonic(false)
Expand All @@ -98,7 +98,7 @@ var diskMergedDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.disk.merged")
metric.SetDescription("The number of disk reads merged into single physical disk access operations.")
metric.SetUnit("1")
metric.SetUnit("{operations}")
metric.SetDataType(pdata.MetricDataTypeIntSum)
sum := metric.IntSum()
sum.SetIsMonotonic(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *scraper) scrape(_ context.Context) (pdata.MetricSlice, error) {
if len(ioCounters) > 0 {
metrics.Resize(metricsLen)
initializeDiskIOMetric(metrics.At(0), s.startTime, now, ioCounters)
initializeDiskOpsMetric(metrics.At(1), s.startTime, now, ioCounters)
initializeDiskOperationsMetric(metrics.At(1), s.startTime, now, ioCounters)
initializeDiskIOTimeMetric(metrics.At(2), s.startTime, now, ioCounters)
initializeDiskOperationTimeMetric(metrics.At(3), s.startTime, now, ioCounters)
initializeDiskPendingOperationsMetric(metrics.At(4), now, ioCounters)
Expand All @@ -120,8 +120,8 @@ func initializeDiskIOMetric(metric pdata.Metric, startTime, now pdata.TimestampU
}
}

func initializeDiskOpsMetric(metric pdata.Metric, startTime, now pdata.TimestampUnixNano, ioCounters map[string]disk.IOCountersStat) {
diskOpsDescriptor.CopyTo(metric)
func initializeDiskOperationsMetric(metric pdata.Metric, startTime, now pdata.TimestampUnixNano, ioCounters map[string]disk.IOCountersStat) {
diskOperationsDescriptor.CopyTo(metric)

idps := metric.IntSum().DataPoints()
idps.Resize(2 * len(ioCounters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestScrape(t *testing.T) {
assert.GreaterOrEqual(t, metrics.Len(), 4)

assertInt64DiskMetricValid(t, metrics.At(0), diskIODescriptor, true, test.expectedStartTime)
assertInt64DiskMetricValid(t, metrics.At(1), diskOpsDescriptor, true, test.expectedStartTime)
assertInt64DiskMetricValid(t, metrics.At(1), diskOperationsDescriptor, true, test.expectedStartTime)
assertDoubleDiskMetricValid(t, metrics.At(2), diskIOTimeDescriptor, false, test.expectedStartTime)
assertDoubleDiskMetricValid(t, metrics.At(3), diskOperationTimeDescriptor, true, test.expectedStartTime)
assertDiskPendingOperationsMetricValid(t, metrics.At(4))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *scraper) scrape(ctx context.Context) (pdata.MetricSlice, error) {
if len(logicalDiskCounterValues) > 0 {
metrics.Resize(metricsLen)
initializeDiskIOMetric(metrics.At(0), s.startTime, now, logicalDiskCounterValues)
initializeDiskOpsMetric(metrics.At(1), s.startTime, now, logicalDiskCounterValues)
initializeDiskOperationsMetric(metrics.At(1), s.startTime, now, logicalDiskCounterValues)
initializeDiskIOTimeMetric(metrics.At(2), s.startTime, now, logicalDiskCounterValues)
initializeDiskOperationTimeMetric(metrics.At(3), s.startTime, now, logicalDiskCounterValues)
initializeDiskPendingOperationsMetric(metrics.At(4), now, logicalDiskCounterValues)
Expand All @@ -141,8 +141,8 @@ func initializeDiskIOMetric(metric pdata.Metric, startTime, now pdata.TimestampU
}
}

func initializeDiskOpsMetric(metric pdata.Metric, startTime, now pdata.TimestampUnixNano, logicalDiskCounterValues []*perfcounters.CounterValues) {
diskOpsDescriptor.CopyTo(metric)
func initializeDiskOperationsMetric(metric pdata.Metric, startTime, now pdata.TimestampUnixNano, logicalDiskCounterValues []*perfcounters.CounterValues) {
diskOperationsDescriptor.CopyTo(metric)

idps := metric.IntSum().DataPoints()
idps.Resize(2 * len(logicalDiskCounterValues))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var fileSystemUsageDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.filesystem.usage")
metric.SetDescription("Filesystem bytes used.")
metric.SetUnit("bytes")
metric.SetUnit("By")
metric.SetDataType(pdata.MetricDataTypeIntSum)
sum := metric.IntSum()
sum.SetIsMonotonic(false)
Expand All @@ -54,7 +54,7 @@ var fileSystemINodesUsageDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.filesystem.inodes.usage")
metric.SetDescription("FileSystem iNodes used.")
metric.SetUnit("1")
metric.SetUnit("{inodes}")
metric.SetDataType(pdata.MetricDataTypeIntSum)
sum := metric.IntSum()
sum.SetIsMonotonic(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright The 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.

// +build linux

package networkscraper

var allTCPStates = []string{
"CLOSE_WAIT",
"CLOSE",
"CLOSING",
"DELETE",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"LAST_ACK",
"LISTEN",
"SYN_SENT",
"SYN_RECV",
"TIME_WAIT",
}

0 comments on commit 3c5eee9

Please sign in to comment.