From f7846954fc62a223fb18ff5ee096ccac83def949 Mon Sep 17 00:00:00 2001 From: James Bebbington Date: Sat, 4 Jul 2020 14:31:17 +1000 Subject: [PATCH] Rename host metrics to more consistent names based on the recently merged otep, and update function names accordingly --- .../hostmetrics_receiver_test.go | 48 ++++++++-------- .../scraper/cpuscraper/cpu_metadata.go | 8 +-- .../scraper/cpuscraper/cpu_scraper.go | 10 ++-- .../scraper/cpuscraper/cpu_scraper_linux.go | 18 +++--- .../scraper/cpuscraper/cpu_scraper_others.go | 10 ++-- .../scraper/cpuscraper/cpu_scraper_test.go | 56 +++++++++---------- .../scraper/diskscraper/disk_metadata.go | 26 ++++----- .../scraper/diskscraper/disk_scraper.go | 18 +++--- .../scraper/diskscraper/disk_scraper_test.go | 6 +- .../filesystemscraper/filesystem_metadata.go | 16 ++---- .../filesystemscraper/filesystem_scraper.go | 10 ++-- .../filesystem_scraper_others.go | 6 +- .../filesystem_scraper_test.go | 34 +++++------ .../filesystem_scraper_unix.go | 14 ++--- .../scraper/loadscraper/load_metadata.go | 24 +++----- .../scraper/loadscraper/load_scraper.go | 6 +- .../scraper/loadscraper/load_scraper_test.go | 6 +- .../scraper/memoryscraper/memory_metadata.go | 8 +-- .../scraper/memoryscraper/memory_scraper.go | 10 ++-- .../memoryscraper/memory_scraper_linux.go | 14 ++--- .../memoryscraper/memory_scraper_others.go | 6 +- .../memoryscraper/memory_scraper_test.go | 26 ++++----- .../networkscraper/network_metadata.go | 40 +++++-------- .../scraper/networkscraper/network_scraper.go | 14 ++--- .../networkscraper/network_scraper_test.go | 16 +++--- .../processscraper/process_metadata.go | 24 +++----- .../scraper/processscraper/process_scraper.go | 32 +++++------ .../processscraper/process_scraper_linux.go | 8 +-- ...ers_1.go => process_scraper_notwindows.go} | 0 ..._others_2.go => process_scraper_others.go} | 6 +- .../processscraper/process_scraper_test.go | 12 ++-- .../processscraper/process_scraper_windows.go | 6 +- .../virtualmemory_metadata.go | 24 +++----- .../virtualmemory_scraper_others.go | 6 +- .../virtualmemory_scraper_test.go | 6 +- .../virtualmemory_scraper_windows.go | 4 +- 36 files changed, 268 insertions(+), 310 deletions(-) rename receiver/hostmetricsreceiver/internal/scraper/processscraper/{process_scraper_others_1.go => process_scraper_notwindows.go} (100%) rename receiver/hostmetricsreceiver/internal/scraper/processscraper/{process_scraper_others_2.go => process_scraper_others.go} (71%) diff --git a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go index e9133bb4881..4b7d69dab27 100644 --- a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go +++ b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go @@ -41,36 +41,36 @@ import ( ) var standardMetrics = []string{ - "host/cpu/usage", - "host/memory/used", - "host/disk/bytes", - "host/disk/ops", - "host/disk/time", - "host/filesystem/used", - "host/load/1m", - "host/load/5m", - "host/load/15m", - "host/network/packets", - "host/network/dropped_packets", - "host/network/errors", - "host/network/bytes", - "host/network/tcp_connections", - "host/swap/paging", - "host/swap/usage", + "system.cpu.time", + "system.memory.usage", + "system.disk.io", + "system.disk.ops", + "system.disk.time", + "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.network.errors", + "system.network.io", + "system.network.tcp_connections", + "system.swap.paging_ops", + "system.swap.usage", } var resourceMetrics = []string{ - "process/cpu/usage", - "process/memory/usage", - "process/disk/bytes", + "process.cpu.time", + "process.memory.usage", + "process.disk.io", } var systemSpecificMetrics = map[string][]string{ - "linux": {"host/filesystem/inodes/used", "host/swap/page_faults"}, - "darwin": {"host/filesystem/inodes/used", "host/swap/page_faults"}, - "freebsd": {"host/filesystem/inodes/used", "host/swap/page_faults"}, - "openbsd": {"host/filesystem/inodes/used", "host/swap/page_faults"}, - "solaris": {"host/filesystem/inodes/used", "host/swap/page_faults"}, + "linux": {"system.filesystem.inodes.usage", "system.swap.page_faults"}, + "darwin": {"system.filesystem.inodes.usage", "system.swap.page_faults"}, + "freebsd": {"system.filesystem.inodes.usage", "system.swap.page_faults"}, + "openbsd": {"system.filesystem.inodes.usage", "system.swap.page_faults"}, + "solaris": {"system.filesystem.inodes.usage", "system.swap.page_faults"}, } var factories = map[string]internal.ScraperFactory{ diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_metadata.go index 338a52909f7..14e7b4dcabf 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_metadata.go @@ -40,14 +40,12 @@ const ( // descriptors -var metricCPUSecondsDescriptor = createMetricCPUSecondsDescriptor() - -func createMetricCPUSecondsDescriptor() pdata.MetricDescriptor { +var cpuTimeDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/cpu/usage") + descriptor.SetName("system.cpu.time") descriptor.SetDescription("Total CPU seconds broken down by different states.") descriptor.SetUnit("s") descriptor.SetType(pdata.MetricTypeMonotonicDouble) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go index c4c16bc7d7e..9f6d961dcab 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go @@ -65,23 +65,23 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.MetricSlice, error) } metrics.Resize(1) - initializeCPUSecondsMetric(metrics.At(0), s.startTime, cpuTimes) + initializeCPUTimeMetric(metrics.At(0), s.startTime, cpuTimes) return metrics, nil } -func initializeCPUSecondsMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, cpuTimes []cpu.TimesStat) { - metricCPUSecondsDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeCPUTimeMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, cpuTimes []cpu.TimesStat) { + cpuTimeDescriptor.CopyTo(metric.MetricDescriptor()) ddps := metric.DoubleDataPoints() ddps.Resize(len(cpuTimes) * cpuStatesLen) for i, cpuTime := range cpuTimes { - appendCPUStateTimes(ddps, i*cpuStatesLen, startTime, cpuTime) + appendCPUTimeStateDataPoints(ddps, i*cpuStatesLen, startTime, cpuTime) } } const gopsCPUTotal string = "cpu-total" -func initializeCPUSecondsDataPoint(dataPoint pdata.DoubleDataPoint, startTime pdata.TimestampUnixNano, cpuLabel string, stateLabel string, value float64) { +func initializeCPUTimeDataPoint(dataPoint pdata.DoubleDataPoint, startTime pdata.TimestampUnixNano, cpuLabel string, stateLabel string, value float64) { labelsMap := dataPoint.LabelsMap() // ignore cpu label if reporting "total" cpu usage if cpuLabel != gopsCPUTotal { diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_linux.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_linux.go index 75d3a6e1a14..88f18917aa9 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_linux.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_linux.go @@ -24,13 +24,13 @@ import ( const cpuStatesLen = 8 -func appendCPUStateTimes(ddps pdata.DoubleDataPointSlice, startIdx int, startTime pdata.TimestampUnixNano, cpuTime cpu.TimesStat) { - initializeCPUSecondsDataPoint(ddps.At(startIdx+0), startTime, cpuTime.CPU, userStateLabelValue, cpuTime.User) - initializeCPUSecondsDataPoint(ddps.At(startIdx+1), startTime, cpuTime.CPU, systemStateLabelValue, cpuTime.System) - initializeCPUSecondsDataPoint(ddps.At(startIdx+2), startTime, cpuTime.CPU, idleStateLabelValue, cpuTime.Idle) - initializeCPUSecondsDataPoint(ddps.At(startIdx+3), startTime, cpuTime.CPU, interruptStateLabelValue, cpuTime.Irq) - initializeCPUSecondsDataPoint(ddps.At(startIdx+4), startTime, cpuTime.CPU, niceStateLabelValue, cpuTime.Nice) - initializeCPUSecondsDataPoint(ddps.At(startIdx+5), startTime, cpuTime.CPU, softIRQStateLabelValue, cpuTime.Softirq) - initializeCPUSecondsDataPoint(ddps.At(startIdx+6), startTime, cpuTime.CPU, stealStateLabelValue, cpuTime.Steal) - initializeCPUSecondsDataPoint(ddps.At(startIdx+7), startTime, cpuTime.CPU, waitStateLabelValue, cpuTime.Iowait) +func appendCPUTimeStateDataPoints(ddps pdata.DoubleDataPointSlice, startIdx int, startTime pdata.TimestampUnixNano, cpuTime cpu.TimesStat) { + initializeCPUTimeDataPoint(ddps.At(startIdx+0), startTime, cpuTime.CPU, userStateLabelValue, cpuTime.User) + initializeCPUTimeDataPoint(ddps.At(startIdx+1), startTime, cpuTime.CPU, systemStateLabelValue, cpuTime.System) + initializeCPUTimeDataPoint(ddps.At(startIdx+2), startTime, cpuTime.CPU, idleStateLabelValue, cpuTime.Idle) + initializeCPUTimeDataPoint(ddps.At(startIdx+3), startTime, cpuTime.CPU, interruptStateLabelValue, cpuTime.Irq) + initializeCPUTimeDataPoint(ddps.At(startIdx+4), startTime, cpuTime.CPU, niceStateLabelValue, cpuTime.Nice) + initializeCPUTimeDataPoint(ddps.At(startIdx+5), startTime, cpuTime.CPU, softIRQStateLabelValue, cpuTime.Softirq) + initializeCPUTimeDataPoint(ddps.At(startIdx+6), startTime, cpuTime.CPU, stealStateLabelValue, cpuTime.Steal) + initializeCPUTimeDataPoint(ddps.At(startIdx+7), startTime, cpuTime.CPU, waitStateLabelValue, cpuTime.Iowait) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_others.go index 9464b3802c7..204f66f4b87 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_others.go @@ -24,9 +24,9 @@ import ( const cpuStatesLen = 4 -func appendCPUStateTimes(ddps pdata.DoubleDataPointSlice, startIdx int, startTime pdata.TimestampUnixNano, cpuTime cpu.TimesStat) { - initializeCPUSecondsDataPoint(ddps.At(startIdx+0), startTime, cpuTime.CPU, userStateLabelValue, cpuTime.User) - initializeCPUSecondsDataPoint(ddps.At(startIdx+1), startTime, cpuTime.CPU, systemStateLabelValue, cpuTime.System) - initializeCPUSecondsDataPoint(ddps.At(startIdx+2), startTime, cpuTime.CPU, idleStateLabelValue, cpuTime.Idle) - initializeCPUSecondsDataPoint(ddps.At(startIdx+3), startTime, cpuTime.CPU, interruptStateLabelValue, cpuTime.Irq) +func appendCPUTimeStateDataPoints(ddps pdata.DoubleDataPointSlice, startIdx int, startTime pdata.TimestampUnixNano, cpuTime cpu.TimesStat) { + initializeCPUTimeDataPoint(ddps.At(startIdx+0), startTime, cpuTime.CPU, userStateLabelValue, cpuTime.User) + initializeCPUTimeDataPoint(ddps.At(startIdx+1), startTime, cpuTime.CPU, systemStateLabelValue, cpuTime.System) + initializeCPUTimeDataPoint(ddps.At(startIdx+2), startTime, cpuTime.CPU, idleStateLabelValue, cpuTime.Idle) + initializeCPUTimeDataPoint(ddps.At(startIdx+3), startTime, cpuTime.CPU, interruptStateLabelValue, cpuTime.Irq) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go index f81de196844..07bc2c944f2 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go @@ -34,14 +34,14 @@ func TestScrapeMetrics_MinimalData(t *testing.T) { assert.Equal(t, 1, metrics.Len()) // for cpu seconds metric, expect a datapoint for each state label, including at least 4 standard states - hostCPUTimeMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricCPUSecondsDescriptor, hostCPUTimeMetric.MetricDescriptor()) - assert.GreaterOrEqual(t, hostCPUTimeMetric.DoubleDataPoints().Len(), 4) - internal.AssertDoubleMetricLabelDoesNotExist(t, hostCPUTimeMetric, 0, cpuLabelName) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 0, stateLabelName, userStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 1, stateLabelName, systemStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 2, stateLabelName, idleStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 3, stateLabelName, interruptStateLabelValue) + cpuTimeMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, cpuTimeDescriptor, cpuTimeMetric.MetricDescriptor()) + assert.GreaterOrEqual(t, cpuTimeMetric.DoubleDataPoints().Len(), 4) + internal.AssertDoubleMetricLabelDoesNotExist(t, cpuTimeMetric, 0, cpuLabelName) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 0, stateLabelName, userStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 1, stateLabelName, systemStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 2, stateLabelName, idleStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 3, stateLabelName, interruptStateLabelValue) }) } @@ -55,14 +55,14 @@ func TestScrapeMetrics_AllData(t *testing.T) { assert.Equal(t, 1, metrics.Len()) // for cpu seconds metric, expect a datapoint for each state label & core combination with at least 4 standard states - hostCPUTimeMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricCPUSecondsDescriptor, hostCPUTimeMetric.MetricDescriptor()) - assert.GreaterOrEqual(t, hostCPUTimeMetric.DoubleDataPoints().Len(), runtime.NumCPU()*4) - internal.AssertDoubleMetricLabelExists(t, hostCPUTimeMetric, 0, cpuLabelName) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 0, stateLabelName, userStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 1, stateLabelName, systemStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 2, stateLabelName, idleStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 3, stateLabelName, interruptStateLabelValue) + cpuTimeMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, cpuTimeDescriptor, cpuTimeMetric.MetricDescriptor()) + assert.GreaterOrEqual(t, cpuTimeMetric.DoubleDataPoints().Len(), runtime.NumCPU()*4) + internal.AssertDoubleMetricLabelExists(t, cpuTimeMetric, 0, cpuLabelName) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 0, stateLabelName, userStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 1, stateLabelName, systemStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 2, stateLabelName, idleStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 3, stateLabelName, interruptStateLabelValue) }) } @@ -73,18 +73,18 @@ func TestScrapeMetrics_Linux(t *testing.T) { createScraperAndValidateScrapedMetrics(t, &Config{}, func(t *testing.T, metrics pdata.MetricSlice) { // for cpu seconds metric, expect a datapoint for all 8 state labels - hostCPUTimeMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricCPUSecondsDescriptor, hostCPUTimeMetric.MetricDescriptor()) - assert.Equal(t, 8, hostCPUTimeMetric.DoubleDataPoints().Len()) - internal.AssertDoubleMetricLabelDoesNotExist(t, hostCPUTimeMetric, 0, cpuLabelName) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 0, stateLabelName, userStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 1, stateLabelName, systemStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 2, stateLabelName, idleStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 3, stateLabelName, interruptStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 4, stateLabelName, niceStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 5, stateLabelName, softIRQStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 6, stateLabelName, stealStateLabelValue) - internal.AssertDoubleMetricLabelHasValue(t, hostCPUTimeMetric, 7, stateLabelName, waitStateLabelValue) + cpuTimeMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, cpuTimeDescriptor, cpuTimeMetric.MetricDescriptor()) + assert.Equal(t, 8, cpuTimeMetric.DoubleDataPoints().Len()) + internal.AssertDoubleMetricLabelDoesNotExist(t, cpuTimeMetric, 0, cpuLabelName) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 0, stateLabelName, userStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 1, stateLabelName, systemStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 2, stateLabelName, idleStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 3, stateLabelName, interruptStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 4, stateLabelName, niceStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 5, stateLabelName, softIRQStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 6, stateLabelName, stealStateLabelValue) + internal.AssertDoubleMetricLabelHasValue(t, cpuTimeMetric, 7, stateLabelName, waitStateLabelValue) }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go index 2145e8e1423..f0ea78aaf97 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go @@ -34,38 +34,32 @@ const ( // descriptors -var metricDiskBytesDescriptor = createMetricDiskBytesDescriptor() - -func createMetricDiskBytesDescriptor() pdata.MetricDescriptor { +var diskIODescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/disk/bytes") + descriptor.SetName("system.disk.io") descriptor.SetDescription("Disk bytes transferred.") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} - -var metricDiskOpsDescriptor = createMetricDiskOpsDescriptor() +}() -func createMetricDiskOpsDescriptor() pdata.MetricDescriptor { +var diskOpsDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/disk/ops") + descriptor.SetName("system.disk.ops") descriptor.SetDescription("Disk operations count.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} +}() -var metricDiskTimeDescriptor = createMetricDiskTimeDescriptor() - -func createMetricDiskTimeDescriptor() pdata.MetricDescriptor { +var diskTimeDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/disk/time") + descriptor.SetName("system.disk.time") descriptor.SetDescription("Time spent in disk operations.") descriptor.SetUnit("ms") - descriptor.SetType(pdata.MetricTypeInt64) + descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper.go index f09fd74f1db..7aa7b0779e5 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper.go @@ -65,14 +65,14 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.MetricSlice, error) } metrics.Resize(3) - initializeMetricDiskBytes(metrics.At(0), ioCounters, s.startTime) - initializeMetricDiskOps(metrics.At(1), ioCounters, s.startTime) - initializeMetricDiskTime(metrics.At(2), ioCounters, s.startTime) + initializeDiskIOMetric(metrics.At(0), ioCounters, s.startTime) + initializeDiskOpsMetric(metrics.At(1), ioCounters, s.startTime) + initializeDiskTimeMetric(metrics.At(2), ioCounters, s.startTime) return metrics, nil } -func initializeMetricDiskBytes(metric pdata.Metric, ioCounters map[string]disk.IOCountersStat, startTime pdata.TimestampUnixNano) { - metricDiskBytesDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeDiskIOMetric(metric pdata.Metric, ioCounters map[string]disk.IOCountersStat, startTime pdata.TimestampUnixNano) { + diskIODescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2 * len(ioCounters)) @@ -85,8 +85,8 @@ func initializeMetricDiskBytes(metric pdata.Metric, ioCounters map[string]disk.I } } -func initializeMetricDiskOps(metric pdata.Metric, ioCounters map[string]disk.IOCountersStat, startTime pdata.TimestampUnixNano) { - metricDiskOpsDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeDiskOpsMetric(metric pdata.Metric, ioCounters map[string]disk.IOCountersStat, startTime pdata.TimestampUnixNano) { + diskOpsDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2 * len(ioCounters)) @@ -99,8 +99,8 @@ func initializeMetricDiskOps(metric pdata.Metric, ioCounters map[string]disk.IOC } } -func initializeMetricDiskTime(metric pdata.Metric, ioCounters map[string]disk.IOCountersStat, startTime pdata.TimestampUnixNano) { - metricDiskTimeDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeDiskTimeMetric(metric pdata.Metric, ioCounters map[string]disk.IOCountersStat, startTime pdata.TimestampUnixNano) { + diskTimeDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2 * len(ioCounters)) diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_test.go index 834d49a0b32..129e33d1a8b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_test.go @@ -33,9 +33,9 @@ func TestScrapeMetrics(t *testing.T) { assert.Equal(t, 3, metrics.Len()) // for each disk metric, expect a read & write datapoint for at least one drive - assertDiskMetricMatchesDescriptorAndHasReadAndWriteDataPoints(t, metrics.At(0), metricDiskBytesDescriptor) - assertDiskMetricMatchesDescriptorAndHasReadAndWriteDataPoints(t, metrics.At(1), metricDiskOpsDescriptor) - assertDiskMetricMatchesDescriptorAndHasReadAndWriteDataPoints(t, metrics.At(2), metricDiskTimeDescriptor) + assertDiskMetricMatchesDescriptorAndHasReadAndWriteDataPoints(t, metrics.At(0), diskIODescriptor) + assertDiskMetricMatchesDescriptorAndHasReadAndWriteDataPoints(t, metrics.At(1), diskOpsDescriptor) + assertDiskMetricMatchesDescriptorAndHasReadAndWriteDataPoints(t, metrics.At(2), diskTimeDescriptor) }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go index 5eb8a52d8b4..ae5075b70a7 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go @@ -35,26 +35,22 @@ const ( // descriptors -var metricFilesystemUsedDescriptor = createMetricFilesystemUsedDescriptor() - -func createMetricFilesystemUsedDescriptor() pdata.MetricDescriptor { +var fileSystemUsageDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/filesystem/used") + descriptor.SetName("system.filesystem.usage") descriptor.SetDescription("Filesystem bytes used.") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeInt64) return descriptor -} - -var metricFilesystemINodesUsedDescriptor = createMetricFilesystemINodesUsedDescriptor() +}() -func createMetricFilesystemINodesUsedDescriptor() pdata.MetricDescriptor { +var fileSystemINodesUsageDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/filesystem/inodes/used") + descriptor.SetName("system.filesystem.inodes.usage") descriptor.SetDescription("FileSystem operations count.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeInt64) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go index 39f5b47f2be..08ff50d43d1 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go @@ -80,7 +80,7 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.MetricSlice, error) if len(usages) > 0 { metrics.Resize(1 + systemSpecificMetricsLen) - initializeMetricFileSystemUsed(metrics.At(0), usages) + initializeFileSystemUsageMetric(metrics.At(0), usages) appendSystemSpecificMetrics(metrics, 1, usages) } @@ -91,17 +91,17 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.MetricSlice, error) return metrics, nil } -func initializeMetricFileSystemUsed(metric pdata.Metric, deviceUsages []*deviceUsage) { - metricFilesystemUsedDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeFileSystemUsageMetric(metric pdata.Metric, deviceUsages []*deviceUsage) { + fileSystemUsageDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(fileSystemStatesLen * len(deviceUsages)) for i, deviceUsage := range deviceUsages { - appendFileSystemUsedStateDataPoints(idps, i*fileSystemStatesLen, deviceUsage) + appendFileSystemUsageStateDataPoints(idps, i*fileSystemStatesLen, deviceUsage) } } -func initializeFileSystemUsedDataPoint(dataPoint pdata.Int64DataPoint, deviceLabel string, stateLabel string, value int64) { +func initializeFileSystemUsageDataPoint(dataPoint pdata.Int64DataPoint, deviceLabel string, stateLabel string, value int64) { labelsMap := dataPoint.LabelsMap() labelsMap.Insert(deviceLabelName, deviceLabel) labelsMap.Insert(stateLabelName, stateLabel) diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_others.go index 42bcb39ef7b..98dfa418c23 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_others.go @@ -22,9 +22,9 @@ import ( const fileSystemStatesLen = 2 -func appendFileSystemUsedStateDataPoints(idps pdata.Int64DataPointSlice, startIdx int, deviceUsage *deviceUsage) { - initializeFileSystemUsedDataPoint(idps.At(startIdx+0), deviceUsage.deviceName, usedLabelValue, int64(deviceUsage.usage.Used)) - initializeFileSystemUsedDataPoint(idps.At(startIdx+1), deviceUsage.deviceName, freeLabelValue, int64(deviceUsage.usage.Free)) +func appendFileSystemUsageStateDataPoints(idps pdata.Int64DataPointSlice, startIdx int, deviceUsage *deviceUsage) { + initializeFileSystemUsageDataPoint(idps.At(startIdx+0), deviceUsage.deviceName, usedLabelValue, int64(deviceUsage.usage.Used)) + initializeFileSystemUsageDataPoint(idps.At(startIdx+1), deviceUsage.deviceName, freeLabelValue, int64(deviceUsage.usage.Free)) } const systemSpecificMetricsLen = 0 diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go index 5102d960808..11110655d56 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go @@ -34,15 +34,15 @@ func TestScrapeMetrics(t *testing.T) { assert.GreaterOrEqual(t, metrics.Len(), 1) // for filesystem used metric, expect a used & free datapoint for at least one drive - hostFileSystemUsedMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricFilesystemUsedDescriptor, hostFileSystemUsedMetric.MetricDescriptor()) - assert.GreaterOrEqual(t, hostFileSystemUsedMetric.Int64DataPoints().Len(), 2) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemUsedMetric, 0, stateLabelName, usedLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemUsedMetric, 1, stateLabelName, freeLabelValue) + fileSystemUsageMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, fileSystemUsageDescriptor, fileSystemUsageMetric.MetricDescriptor()) + assert.GreaterOrEqual(t, fileSystemUsageMetric.Int64DataPoints().Len(), 2) + internal.AssertInt64MetricLabelHasValue(t, fileSystemUsageMetric, 0, stateLabelName, usedLabelValue) + internal.AssertInt64MetricLabelHasValue(t, fileSystemUsageMetric, 1, stateLabelName, freeLabelValue) }) } -func TestScrapeMetrics_Unux(t *testing.T) { +func TestScrapeMetrics_Unix(t *testing.T) { if !isUnix() { return } @@ -52,19 +52,19 @@ func TestScrapeMetrics_Unux(t *testing.T) { assert.Equal(t, 2, metrics.Len()) // for filesystem used metric, expect a used, free & reserved datapoint for at least one drive - hostFileSystemUsedMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricFilesystemUsedDescriptor, hostFileSystemUsedMetric.MetricDescriptor()) - assert.GreaterOrEqual(t, hostFileSystemUsedMetric.Int64DataPoints().Len(), 3) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemUsedMetric, 0, stateLabelName, usedLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemUsedMetric, 1, stateLabelName, freeLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemUsedMetric, 2, stateLabelName, reservedLabelValue) + fileSystemUsageMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, fileSystemUsageDescriptor, fileSystemUsageMetric.MetricDescriptor()) + assert.GreaterOrEqual(t, fileSystemUsageMetric.Int64DataPoints().Len(), 3) + internal.AssertInt64MetricLabelHasValue(t, fileSystemUsageMetric, 0, stateLabelName, usedLabelValue) + internal.AssertInt64MetricLabelHasValue(t, fileSystemUsageMetric, 1, stateLabelName, freeLabelValue) + internal.AssertInt64MetricLabelHasValue(t, fileSystemUsageMetric, 2, stateLabelName, reservedLabelValue) // for filesystem inodes used metric, expect a used, free & reserved datapoint for at least one drive - hostFileSystemINodesUsedMetric := metrics.At(1) - internal.AssertDescriptorEqual(t, metricFilesystemINodesUsedDescriptor, hostFileSystemINodesUsedMetric.MetricDescriptor()) - assert.GreaterOrEqual(t, hostFileSystemINodesUsedMetric.Int64DataPoints().Len(), 2) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemINodesUsedMetric, 0, stateLabelName, usedLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostFileSystemINodesUsedMetric, 1, stateLabelName, freeLabelValue) + fileSystemINodesUsageMetric := metrics.At(1) + internal.AssertDescriptorEqual(t, fileSystemINodesUsageDescriptor, fileSystemINodesUsageMetric.MetricDescriptor()) + assert.GreaterOrEqual(t, fileSystemINodesUsageMetric.Int64DataPoints().Len(), 2) + internal.AssertInt64MetricLabelHasValue(t, fileSystemINodesUsageMetric, 0, stateLabelName, usedLabelValue) + internal.AssertInt64MetricLabelHasValue(t, fileSystemINodesUsageMetric, 1, stateLabelName, freeLabelValue) }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_unix.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_unix.go index eb903bebeee..1a4381addf8 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_unix.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_unix.go @@ -22,23 +22,23 @@ import ( const fileSystemStatesLen = 3 -func appendFileSystemUsedStateDataPoints(idps pdata.Int64DataPointSlice, startIdx int, deviceUsage *deviceUsage) { - initializeFileSystemUsedDataPoint(idps.At(startIdx+0), deviceUsage.deviceName, usedLabelValue, int64(deviceUsage.usage.Used)) - initializeFileSystemUsedDataPoint(idps.At(startIdx+1), deviceUsage.deviceName, freeLabelValue, int64(deviceUsage.usage.Free)) - initializeFileSystemUsedDataPoint(idps.At(startIdx+2), deviceUsage.deviceName, reservedLabelValue, int64(deviceUsage.usage.Total-deviceUsage.usage.Used-deviceUsage.usage.Free)) +func appendFileSystemUsageStateDataPoints(idps pdata.Int64DataPointSlice, startIdx int, deviceUsage *deviceUsage) { + initializeFileSystemUsageDataPoint(idps.At(startIdx+0), deviceUsage.deviceName, usedLabelValue, int64(deviceUsage.usage.Used)) + initializeFileSystemUsageDataPoint(idps.At(startIdx+1), deviceUsage.deviceName, freeLabelValue, int64(deviceUsage.usage.Free)) + initializeFileSystemUsageDataPoint(idps.At(startIdx+2), deviceUsage.deviceName, reservedLabelValue, int64(deviceUsage.usage.Total-deviceUsage.usage.Used-deviceUsage.usage.Free)) } const systemSpecificMetricsLen = 1 func appendSystemSpecificMetrics(metrics pdata.MetricSlice, startIdx int, deviceUsages []*deviceUsage) { metric := metrics.At(startIdx) - metricFilesystemINodesUsedDescriptor.CopyTo(metric.MetricDescriptor()) + fileSystemINodesUsageDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2 * len(deviceUsages)) for idx, deviceUsage := range deviceUsages { startIndex := 2 * idx - initializeFileSystemUsedDataPoint(idps.At(startIndex+0), deviceUsage.deviceName, usedLabelValue, int64(deviceUsage.usage.InodesUsed)) - initializeFileSystemUsedDataPoint(idps.At(startIndex+1), deviceUsage.deviceName, freeLabelValue, int64(deviceUsage.usage.InodesFree)) + initializeFileSystemUsageDataPoint(idps.At(startIndex+0), deviceUsage.deviceName, usedLabelValue, int64(deviceUsage.usage.InodesUsed)) + initializeFileSystemUsageDataPoint(idps.At(startIndex+1), deviceUsage.deviceName, freeLabelValue, int64(deviceUsage.usage.InodesFree)) } } diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go index d5fb53ccec4..f174e184637 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go @@ -20,38 +20,32 @@ import ( // descriptors -var metric1MLoadDescriptor = createMetric1MLoadDescriptor() - -func createMetric1MLoadDescriptor() pdata.MetricDescriptor { +var loadAvg1MDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/load/1m") + descriptor.SetName("system.cpu.load_average.1m") descriptor.SetDescription("Average CPU Load over 1 minute.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeDouble) return descriptor -} - -var metric5MLoadDescriptor = createMetric5MLoadDescriptor() +}() -func createMetric5MLoadDescriptor() pdata.MetricDescriptor { +var loadAvg5mDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/load/5m") + descriptor.SetName("system.cpu.load_average.5m") descriptor.SetDescription("Average CPU Load over 5 minutes.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeDouble) return descriptor -} - -var metric15MLoadDescriptor = createMetric15MLoadDescriptor() +}() -func createMetric15MLoadDescriptor() pdata.MetricDescriptor { +var loadAvg15mDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/load/15m") + descriptor.SetName("system.cpu.load_average.15m") descriptor.SetDescription("Average CPU Load over 15 minutes.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeDouble) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go index 7eae557c1db..e3c7dece2a4 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go @@ -58,9 +58,9 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.MetricSlice, error) } metrics.Resize(3) - initializeLoadMetric(metrics.At(0), metric1MLoadDescriptor, avgLoadValues.Load1) - initializeLoadMetric(metrics.At(1), metric5MLoadDescriptor, avgLoadValues.Load5) - initializeLoadMetric(metrics.At(2), metric15MLoadDescriptor, avgLoadValues.Load15) + initializeLoadMetric(metrics.At(0), loadAvg1MDescriptor, avgLoadValues.Load1) + initializeLoadMetric(metrics.At(1), loadAvg5mDescriptor, avgLoadValues.Load5) + initializeLoadMetric(metrics.At(2), loadAvg15mDescriptor, avgLoadValues.Load15) return metrics, nil } diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go index a8c50ad8909..ec6bdd1392c 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go @@ -34,9 +34,9 @@ func TestScrapeMetrics(t *testing.T) { assert.Equal(t, 3, metrics.Len()) // expect a single datapoint for 1m, 5m & 15m load metrics - assertMetricHasSingleDatapoint(t, metrics.At(0), metric1MLoadDescriptor) - assertMetricHasSingleDatapoint(t, metrics.At(1), metric5MLoadDescriptor) - assertMetricHasSingleDatapoint(t, metrics.At(2), metric15MLoadDescriptor) + assertMetricHasSingleDatapoint(t, metrics.At(0), loadAvg1MDescriptor) + assertMetricHasSingleDatapoint(t, metrics.At(1), loadAvg5mDescriptor) + assertMetricHasSingleDatapoint(t, metrics.At(2), loadAvg15mDescriptor) }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_metadata.go index 1c6c71302b1..a43a0c86d15 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_metadata.go @@ -35,14 +35,12 @@ const ( // descriptors -var metricMemoryUsedDescriptor = createMetricMemoryUsedDescriptor() - -func createMetricMemoryUsedDescriptor() pdata.MetricDescriptor { +var memoryUsageDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/memory/used") + descriptor.SetName("system.memory.usage") descriptor.SetDescription("Bytes of memory in use.") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeInt64) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go index 0ffc96a43be..c59fc92f353 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go @@ -57,19 +57,19 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.MetricSlice, error) } metrics.Resize(1) - initializeMetricMemoryUsed(metrics.At(0), memInfo) + initializeMemoryUsageMetric(metrics.At(0), memInfo) return metrics, nil } -func initializeMetricMemoryUsed(metric pdata.Metric, memInfo *mem.VirtualMemoryStat) { - metricMemoryUsedDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeMemoryUsageMetric(metric pdata.Metric, memInfo *mem.VirtualMemoryStat) { + memoryUsageDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(memStatesLen) - appendMemoryUsedStates(idps, memInfo) + appendMemoryUsageStateDataPoints(idps, memInfo) } -func initializeMemoryUsedDataPoint(dataPoint pdata.Int64DataPoint, stateLabel string, value int64) { +func initializeMemoryUsageDataPoint(dataPoint pdata.Int64DataPoint, stateLabel string, value int64) { labelsMap := dataPoint.LabelsMap() labelsMap.Insert(stateLabelName, stateLabel) dataPoint.SetTimestamp(pdata.TimestampUnixNano(uint64(time.Now().UnixNano()))) diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go index ba337ae88c7..1fa0f2d3fff 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go @@ -24,11 +24,11 @@ import ( const memStatesLen = 6 -func appendMemoryUsedStates(idps pdata.Int64DataPointSlice, memInfo *mem.VirtualMemoryStat) { - initializeMemoryUsedDataPoint(idps.At(0), usedStateLabelValue, int64(memInfo.Used)) - initializeMemoryUsedDataPoint(idps.At(1), freeStateLabelValue, int64(memInfo.Free)) - initializeMemoryUsedDataPoint(idps.At(2), bufferedStateLabelValue, int64(memInfo.Buffers)) - initializeMemoryUsedDataPoint(idps.At(3), cachedStateLabelValue, int64(memInfo.Cached)) - initializeMemoryUsedDataPoint(idps.At(4), slabReclaimableStateLabelValue, int64(memInfo.SReclaimable)) - initializeMemoryUsedDataPoint(idps.At(5), slabUnreclaimableStateLabelValue, int64(memInfo.SUnreclaim)) +func appendMemoryUsageStateDataPoints(idps pdata.Int64DataPointSlice, memInfo *mem.VirtualMemoryStat) { + initializeMemoryUsageDataPoint(idps.At(0), usedStateLabelValue, int64(memInfo.Used)) + initializeMemoryUsageDataPoint(idps.At(1), freeStateLabelValue, int64(memInfo.Free)) + initializeMemoryUsageDataPoint(idps.At(2), bufferedStateLabelValue, int64(memInfo.Buffers)) + initializeMemoryUsageDataPoint(idps.At(3), cachedStateLabelValue, int64(memInfo.Cached)) + initializeMemoryUsageDataPoint(idps.At(4), slabReclaimableStateLabelValue, int64(memInfo.SReclaimable)) + initializeMemoryUsageDataPoint(idps.At(5), slabUnreclaimableStateLabelValue, int64(memInfo.SUnreclaim)) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go index 24309027088..0cc0a63b910 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go @@ -26,7 +26,7 @@ const availableStateLabelValue = "available" const memStatesLen = 2 -func appendMemoryUsedStates(idps pdata.Int64DataPointSlice, memInfo *mem.VirtualMemoryStat) { - initializeMemoryUsedDataPoint(idps.At(0), usedStateLabelValue, int64(memInfo.Used)) - initializeMemoryUsedDataPoint(idps.At(1), availableStateLabelValue, int64(memInfo.Available)) +func appendMemoryUsageStateDataPoints(idps pdata.Int64DataPointSlice, memInfo *mem.VirtualMemoryStat) { + initializeMemoryUsageDataPoint(idps.At(0), usedStateLabelValue, int64(memInfo.Used)) + initializeMemoryUsageDataPoint(idps.At(1), availableStateLabelValue, int64(memInfo.Available)) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go index dd8c10be513..71773820be3 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go @@ -34,10 +34,10 @@ func TestScrapeMetrics(t *testing.T) { assert.Equal(t, 1, metrics.Len()) // for memory used metric, expect a datapoint for each state label, including at least 2 states, one of which is 'Used' - hostMemoryUsedMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricMemoryUsedDescriptor, hostMemoryUsedMetric.MetricDescriptor()) - assert.GreaterOrEqual(t, hostMemoryUsedMetric.Int64DataPoints().Len(), 2) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 0, stateLabelName, usedStateLabelValue) + memoryUsageMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, memoryUsageDescriptor, memoryUsageMetric.MetricDescriptor()) + assert.GreaterOrEqual(t, memoryUsageMetric.Int64DataPoints().Len(), 2) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 0, stateLabelName, usedStateLabelValue) }) } @@ -51,15 +51,15 @@ func TestScrapeMetrics_Linux(t *testing.T) { assert.Equal(t, 1, metrics.Len()) // for memory used metric, expect a datapoint for all 6 state labels - hostMemoryUsedMetric := metrics.At(0) - internal.AssertDescriptorEqual(t, metricMemoryUsedDescriptor, hostMemoryUsedMetric.MetricDescriptor()) - assert.Equal(t, 6, hostMemoryUsedMetric.Int64DataPoints().Len()) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 0, stateLabelName, usedStateLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 1, stateLabelName, freeStateLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 2, stateLabelName, bufferedStateLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 3, stateLabelName, cachedStateLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 4, stateLabelName, slabReclaimableStateLabelValue) - internal.AssertInt64MetricLabelHasValue(t, hostMemoryUsedMetric, 5, stateLabelName, slabUnreclaimableStateLabelValue) + memoryUsageMetric := metrics.At(0) + internal.AssertDescriptorEqual(t, memoryUsageDescriptor, memoryUsageMetric.MetricDescriptor()) + assert.Equal(t, 6, memoryUsageMetric.Int64DataPoints().Len()) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 0, stateLabelName, usedStateLabelValue) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 1, stateLabelName, freeStateLabelValue) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 2, stateLabelName, bufferedStateLabelValue) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 3, stateLabelName, cachedStateLabelValue) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 4, stateLabelName, slabReclaimableStateLabelValue) + internal.AssertInt64MetricLabelHasValue(t, memoryUsageMetric, 5, stateLabelName, slabUnreclaimableStateLabelValue) }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go index 756b002eec6..3003110db93 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go @@ -34,62 +34,52 @@ const ( // descriptors -var metricNetworkPacketsDescriptor = createMetricNetworkPacketsDescriptor() - -func createMetricNetworkPacketsDescriptor() pdata.MetricDescriptor { +var networkPacketsDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/network/packets") + descriptor.SetName("system.network.packets") descriptor.SetDescription("The number of packets transferred.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} - -var metricNetworkDroppedPacketsDescriptor = createMetricNetworkDroppedPacketsDescriptor() +}() -func createMetricNetworkDroppedPacketsDescriptor() pdata.MetricDescriptor { +var networkDroppedPacketsDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/network/dropped_packets") + descriptor.SetName("system.network.dropped_packets") descriptor.SetDescription("The number of packets dropped.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} - -var metricNetworkErrorsDescriptor = createMetricNetworkErrorsDescriptor() +}() -func createMetricNetworkErrorsDescriptor() pdata.MetricDescriptor { +var networkErrorsDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/network/errors") + descriptor.SetName("system.network.errors") descriptor.SetDescription("The number of errors encountered") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} +}() -var metricNetworkBytesDescriptor = createMetricNetworkBytesDescriptor() - -func createMetricNetworkBytesDescriptor() pdata.MetricDescriptor { +var networkIODescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/network/bytes") + descriptor.SetName("system.network.io") descriptor.SetDescription("The number of bytes transmitted and received") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} - -var metricNetworkTCPConnectionDescriptor = createMetricNetworkTCPConnectionDescriptor() +}() -func createMetricNetworkTCPConnectionDescriptor() pdata.MetricDescriptor { +var networkTCPConnectionsDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/network/tcp_connections") + descriptor.SetName("system.network.tcp_connections") descriptor.SetDescription("The number of tcp connections") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeInt64) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go index d1c924b27c9..3a66e68d76d 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go @@ -93,10 +93,10 @@ func scrapeAndAppendNetworkCounterMetrics(metrics pdata.MetricSlice, startTime p startIdx := metrics.Len() metrics.Resize(startIdx + 4) - initializeNetworkMetric(metrics.At(startIdx+0), metricNetworkPacketsDescriptor, startTime, networkStats.PacketsSent, networkStats.PacketsRecv) - initializeNetworkMetric(metrics.At(startIdx+1), metricNetworkDroppedPacketsDescriptor, startTime, networkStats.Dropout, networkStats.Dropin) - initializeNetworkMetric(metrics.At(startIdx+2), metricNetworkErrorsDescriptor, startTime, networkStats.Errout, networkStats.Errin) - initializeNetworkMetric(metrics.At(startIdx+3), metricNetworkBytesDescriptor, startTime, networkStats.BytesSent, networkStats.BytesRecv) + initializeNetworkMetric(metrics.At(startIdx+0), networkPacketsDescriptor, startTime, networkStats.PacketsSent, networkStats.PacketsRecv) + initializeNetworkMetric(metrics.At(startIdx+1), networkDroppedPacketsDescriptor, startTime, networkStats.Dropout, networkStats.Dropin) + initializeNetworkMetric(metrics.At(startIdx+2), networkErrorsDescriptor, startTime, networkStats.Errout, networkStats.Errin) + initializeNetworkMetric(metrics.At(startIdx+3), networkIODescriptor, startTime, networkStats.BytesSent, networkStats.BytesRecv) return nil } @@ -140,19 +140,19 @@ func getConnectionStatusCounts(connections []net.ConnectionStat) map[string]int6 } func initializeNetworkTCPConnectionsMetric(metric pdata.Metric, connectionStateCounts map[string]int64) { - metricNetworkTCPConnectionDescriptor.CopyTo(metric.MetricDescriptor()) + networkTCPConnectionsDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(len(connectionStateCounts)) i := 0 for connectionState, count := range connectionStateCounts { - initializeTCPConnectionsDataPoint(idps.At(i), connectionState, count) + initializeNetworkTCPConnectionsDataPoint(idps.At(i), connectionState, count) i++ } } -func initializeTCPConnectionsDataPoint(dataPoint pdata.Int64DataPoint, stateLabel string, value int64) { +func initializeNetworkTCPConnectionsDataPoint(dataPoint pdata.Int64DataPoint, stateLabel string, value int64) { labelsMap := dataPoint.LabelsMap() labelsMap.Insert(stateLabelName, stateLabel) dataPoint.SetTimestamp(pdata.TimestampUnixNano(uint64(time.Now().UnixNano()))) diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go index 52eca592b11..02db61ed67e 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go @@ -33,16 +33,16 @@ func TestScrapeMetrics(t *testing.T) { assert.Equal(t, 5, metrics.Len()) // for network packets, dropped packets, errors, & bytes metrics, expect a transmit & receive datapoint - assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(0), metricNetworkPacketsDescriptor) - assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(1), metricNetworkDroppedPacketsDescriptor) - assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(2), metricNetworkErrorsDescriptor) - assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(3), metricNetworkBytesDescriptor) + assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(0), networkPacketsDescriptor) + assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(1), networkDroppedPacketsDescriptor) + assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(2), networkErrorsDescriptor) + assertNetworkMetricMatchesDescriptorAndHasTransmitAndReceiveDataPoints(t, metrics.At(3), networkIODescriptor) // for tcp connections metric, expect at least one datapoint with a state label - hostNetworkTCPConnectionsMetric := metrics.At(4) - internal.AssertDescriptorEqual(t, metricNetworkTCPConnectionDescriptor, hostNetworkTCPConnectionsMetric.MetricDescriptor()) - internal.AssertInt64MetricLabelExists(t, hostNetworkTCPConnectionsMetric, 0, stateLabelName) - assert.GreaterOrEqual(t, hostNetworkTCPConnectionsMetric.Int64DataPoints().Len(), 1) + networkTCPConnectionsMetric := metrics.At(4) + internal.AssertDescriptorEqual(t, networkTCPConnectionsDescriptor, networkTCPConnectionsMetric.MetricDescriptor()) + internal.AssertInt64MetricLabelExists(t, networkTCPConnectionsMetric, 0, stateLabelName) + assert.GreaterOrEqual(t, networkTCPConnectionsMetric.Int64DataPoints().Len(), 1) }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go index 9ea72be6c0b..a68a07dea05 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go @@ -46,38 +46,32 @@ const ( // descriptors -var metricCPUUsageDescriptor = createMetricCPUUsageDescriptor() - -func createMetricCPUUsageDescriptor() pdata.MetricDescriptor { +var cpuTimeDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("process/cpu/usage") + descriptor.SetName("process.cpu.time") descriptor.SetDescription("Total CPU seconds broken down by different states.") descriptor.SetUnit("s") descriptor.SetType(pdata.MetricTypeMonotonicDouble) return descriptor -} - -var metricMemoryUsageDescriptor = createMetricMemoryUsageDescriptor() +}() -func createMetricMemoryUsageDescriptor() pdata.MetricDescriptor { +var memoryUsageDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("process/memory/usage") + descriptor.SetName("process.memory.usage") descriptor.SetDescription("Bytes of memory in use.") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeInt64) return descriptor -} - -var metricDiskBytesDescriptor = createMetricDiskBytesDescriptor() +}() -func createMetricDiskBytesDescriptor() pdata.MetricDescriptor { +var diskIODescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("process/disk/bytes") + descriptor.SetName("process.disk.io") descriptor.SetDescription("Disk bytes transferred.") descriptor.SetUnit("bytes") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go index 6f3b4bd2655..13d23bd3b14 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go @@ -100,7 +100,7 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.ResourceMetricsSlice ilms.Resize(1) metrics := ilms.At(0).Metrics() - if err = scrapeAndAppendCPUUsageMetric(metrics, s.startTime, md.handle); err != nil { + if err = scrapeAndAppendCPUTimeMetric(metrics, s.startTime, md.handle); err != nil { errs = append(errs, errors.Wrapf(err, "error reading cpu times for process %q (pid %v)", md.executable.name, md.pid)) } @@ -108,7 +108,7 @@ func (s *scraper) ScrapeMetrics(ctx context.Context) (pdata.ResourceMetricsSlice errs = append(errs, errors.Wrapf(err, "error reading memory info for process %q (pid %v)", md.executable.name, md.pid)) } - if err = scrapeAndAppendDiskBytesMetric(metrics, s.startTime, md.handle); err != nil { + if err = scrapeAndAppendDiskIOMetric(metrics, s.startTime, md.handle); err != nil { errs = append(errs, errors.Wrapf(err, "error reading disk usage for process %q (pid %v)", md.executable.name, md.pid)) } } @@ -176,7 +176,7 @@ func (s *scraper) getProcessMetadata() ([]*processMetadata, error) { return metadata, nil } -func scrapeAndAppendCPUUsageMetric(metrics pdata.MetricSlice, startTime pdata.TimestampUnixNano, handle processHandle) error { +func scrapeAndAppendCPUTimeMetric(metrics pdata.MetricSlice, startTime pdata.TimestampUnixNano, handle processHandle) error { times, err := handle.Times() if err != nil { return err @@ -184,19 +184,19 @@ func scrapeAndAppendCPUUsageMetric(metrics pdata.MetricSlice, startTime pdata.Ti startIdx := metrics.Len() metrics.Resize(startIdx + 1) - initializeCPUUsageMetric(metrics.At(startIdx), startTime, times) + initializeCPUTimeMetric(metrics.At(startIdx), startTime, times) return nil } -func initializeCPUUsageMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, times *cpu.TimesStat) { - metricCPUUsageDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeCPUTimeMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, times *cpu.TimesStat) { + cpuTimeDescriptor.CopyTo(metric.MetricDescriptor()) ddps := metric.DoubleDataPoints() ddps.Resize(cpuStatesLen) - appendCPUStateTimes(ddps, startTime, times) + appendCPUTimeStateDataPoints(ddps, startTime, times) } -func initializeCPUUsageDataPoint(dataPoint pdata.DoubleDataPoint, startTime pdata.TimestampUnixNano, value float64, stateLabel string) { +func initializeCPUTimeDataPoint(dataPoint pdata.DoubleDataPoint, startTime pdata.TimestampUnixNano, value float64, stateLabel string) { labelsMap := dataPoint.LabelsMap() labelsMap.Insert(stateLabelName, stateLabel) dataPoint.SetStartTime(startTime) @@ -217,7 +217,7 @@ func scrapeAndAppendMemoryUsageMetric(metrics pdata.MetricSlice, handle processH } func initializeMemoryUsageMetric(metric pdata.Metric, mem *process.MemoryInfoStat) { - metricMemoryUsageDescriptor.CopyTo(metric.MetricDescriptor()) + memoryUsageDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(1) @@ -229,7 +229,7 @@ func initializeMemoryUsageDataPoint(dataPoint pdata.Int64DataPoint, value int64) dataPoint.SetValue(value) } -func scrapeAndAppendDiskBytesMetric(metrics pdata.MetricSlice, startTime pdata.TimestampUnixNano, handle processHandle) error { +func scrapeAndAppendDiskIOMetric(metrics pdata.MetricSlice, startTime pdata.TimestampUnixNano, handle processHandle) error { io, err := handle.IOCounters() if err != nil { return err @@ -237,20 +237,20 @@ func scrapeAndAppendDiskBytesMetric(metrics pdata.MetricSlice, startTime pdata.T startIdx := metrics.Len() metrics.Resize(startIdx + 1) - initializeDiskBytesMetric(metrics.At(startIdx), startTime, io) + initializeDiskIOMetric(metrics.At(startIdx), startTime, io) return nil } -func initializeDiskBytesMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, io *process.IOCountersStat) { - metricDiskBytesDescriptor.CopyTo(metric.MetricDescriptor()) +func initializeDiskIOMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, io *process.IOCountersStat) { + diskIODescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2) - initializeDiskBytesDataPoint(idps.At(0), startTime, int64(io.ReadBytes), readDirectionLabelValue) - initializeDiskBytesDataPoint(idps.At(1), startTime, int64(io.WriteBytes), writeDirectionLabelValue) + initializeDiskIODataPoint(idps.At(0), startTime, int64(io.ReadBytes), readDirectionLabelValue) + initializeDiskIODataPoint(idps.At(1), startTime, int64(io.WriteBytes), writeDirectionLabelValue) } -func initializeDiskBytesDataPoint(dataPoint pdata.Int64DataPoint, startTime pdata.TimestampUnixNano, value int64, directionLabel string) { +func initializeDiskIODataPoint(dataPoint pdata.Int64DataPoint, startTime pdata.TimestampUnixNano, value int64, directionLabel string) { labelsMap := dataPoint.LabelsMap() labelsMap.Insert(directionLabelName, directionLabel) dataPoint.SetStartTime(startTime) diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_linux.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_linux.go index 06bc85f787d..4b990010de7 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_linux.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_linux.go @@ -24,8 +24,8 @@ import ( const cpuStatesLen = 3 -func appendCPUStateTimes(ddps pdata.DoubleDataPointSlice, startTime pdata.TimestampUnixNano, cpuTime *cpu.TimesStat) { - initializeCPUUsageDataPoint(ddps.At(0), startTime, cpuTime.User, userStateLabelValue) - initializeCPUUsageDataPoint(ddps.At(1), startTime, cpuTime.System, systemStateLabelValue) - initializeCPUUsageDataPoint(ddps.At(2), startTime, cpuTime.Iowait, waitStateLabelValue) +func appendCPUTimeStateDataPoints(ddps pdata.DoubleDataPointSlice, startTime pdata.TimestampUnixNano, cpuTime *cpu.TimesStat) { + initializeCPUTimeDataPoint(ddps.At(0), startTime, cpuTime.User, userStateLabelValue) + initializeCPUTimeDataPoint(ddps.At(1), startTime, cpuTime.System, systemStateLabelValue) + initializeCPUTimeDataPoint(ddps.At(2), startTime, cpuTime.Iowait, waitStateLabelValue) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others_1.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_notwindows.go similarity index 100% rename from receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others_1.go rename to receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_notwindows.go diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others_2.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others.go similarity index 71% rename from receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others_2.go rename to receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others.go index 88ec82a5b20..d9bc2deca24 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others_2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_others.go @@ -24,7 +24,7 @@ import ( const cpuStatesLen = 2 -func appendCPUStateTimes(ddps pdata.DoubleDataPointSlice, startTime pdata.TimestampUnixNano, cpuTime *cpu.TimesStat) { - initializeCPUUsageDataPoint(ddps.At(0), startTime, cpuTime.User, userStateLabelValue) - initializeCPUUsageDataPoint(ddps.At(1), startTime, cpuTime.System, systemStateLabelValue) +func appendCPUTimeStateDataPoints(ddps pdata.DoubleDataPointSlice, startTime pdata.TimestampUnixNano, cpuTime *cpu.TimesStat) { + initializeCPUTimeDataPoint(ddps.At(0), startTime, cpuTime.User, userStateLabelValue) + initializeCPUTimeDataPoint(ddps.At(1), startTime, cpuTime.System, systemStateLabelValue) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go index 35eded0f781..6e7fc9f32fe 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go @@ -75,8 +75,8 @@ func assertResourceAttributes(t *testing.T, resourceMetrics pdata.ResourceMetric } func assertCPUUsageMetricValid(t *testing.T, resourceMetrics pdata.ResourceMetricsSlice) { - cpuUsageMetric := getMetric(t, metricCPUUsageDescriptor, resourceMetrics) - internal.AssertDescriptorEqual(t, metricCPUUsageDescriptor, cpuUsageMetric.MetricDescriptor()) + cpuUsageMetric := getMetric(t, cpuTimeDescriptor, resourceMetrics) + internal.AssertDescriptorEqual(t, cpuTimeDescriptor, cpuUsageMetric.MetricDescriptor()) internal.AssertDoubleMetricLabelHasValue(t, cpuUsageMetric, 0, stateLabelName, userStateLabelValue) internal.AssertDoubleMetricLabelHasValue(t, cpuUsageMetric, 1, stateLabelName, systemStateLabelValue) if runtime.GOOS == "linux" { @@ -85,13 +85,13 @@ func assertCPUUsageMetricValid(t *testing.T, resourceMetrics pdata.ResourceMetri } func assertMemoryUsageMetricValid(t *testing.T, resourceMetrics pdata.ResourceMetricsSlice) { - memoryUsageMetric := getMetric(t, metricMemoryUsageDescriptor, resourceMetrics) - internal.AssertDescriptorEqual(t, metricMemoryUsageDescriptor, memoryUsageMetric.MetricDescriptor()) + memoryUsageMetric := getMetric(t, memoryUsageDescriptor, resourceMetrics) + internal.AssertDescriptorEqual(t, memoryUsageDescriptor, memoryUsageMetric.MetricDescriptor()) } func assertDiskBytesMetricValid(t *testing.T, resourceMetrics pdata.ResourceMetricsSlice) { - diskBytesMetric := getMetric(t, metricDiskBytesDescriptor, resourceMetrics) - internal.AssertDescriptorEqual(t, metricDiskBytesDescriptor, diskBytesMetric.MetricDescriptor()) + diskBytesMetric := getMetric(t, diskIODescriptor, resourceMetrics) + internal.AssertDescriptorEqual(t, diskIODescriptor, diskBytesMetric.MetricDescriptor()) internal.AssertInt64MetricLabelHasValue(t, diskBytesMetric, 0, directionLabelName, readDirectionLabelValue) internal.AssertInt64MetricLabelHasValue(t, diskBytesMetric, 1, directionLabelName, writeDirectionLabelValue) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_windows.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_windows.go index 9e9886a26cf..b4781d75e33 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_windows.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_windows.go @@ -27,9 +27,9 @@ import ( const cpuStatesLen = 2 -func appendCPUStateTimes(ddps pdata.DoubleDataPointSlice, startTime pdata.TimestampUnixNano, cpuTime *cpu.TimesStat) { - initializeCPUUsageDataPoint(ddps.At(0), startTime, cpuTime.User, userStateLabelValue) - initializeCPUUsageDataPoint(ddps.At(1), startTime, cpuTime.System, systemStateLabelValue) +func appendCPUTimeStateDataPoints(ddps pdata.DoubleDataPointSlice, startTime pdata.TimestampUnixNano, cpuTime *cpu.TimesStat) { + initializeCPUTimeDataPoint(ddps.At(0), startTime, cpuTime.User, userStateLabelValue) + initializeCPUTimeDataPoint(ddps.At(1), startTime, cpuTime.System, systemStateLabelValue) } func getProcessExecutable(proc processHandle) (*executableMetadata, error) { diff --git a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_metadata.go index 60b16c751af..ca38f74ab43 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_metadata.go @@ -49,38 +49,32 @@ const ( minorTypeLabelValue = "minor" ) -var metricSwapUsageDescriptor = createMetricSwapUsageDescriptor() - -func createMetricSwapUsageDescriptor() pdata.MetricDescriptor { +var swapUsageDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/swap/usage") + descriptor.SetName("system.swap.usage") descriptor.SetDescription("Swap (unix) or pagefile (windows) usage.") descriptor.SetUnit("pages") descriptor.SetType(pdata.MetricTypeInt64) return descriptor -} - -var metricPagingDescriptor = createMetricPagingDescriptor() +}() -func createMetricPagingDescriptor() pdata.MetricDescriptor { +var swapPagingDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/swap/paging") + descriptor.SetName("system.swap.paging_ops") descriptor.SetDescription("The number of paging operations.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} - -var metricPageFaultsDescriptor = createMetricPageFaultsDescriptor() +}() -func createMetricPageFaultsDescriptor() pdata.MetricDescriptor { +var swapPageFaultsDescriptor = func() pdata.MetricDescriptor { descriptor := pdata.NewMetricDescriptor() descriptor.InitEmpty() - descriptor.SetName("host/swap/page_faults") + descriptor.SetName("system.swap.page_faults") descriptor.SetDescription("The number of page faults.") descriptor.SetUnit("1") descriptor.SetType(pdata.MetricTypeMonotonicInt64) return descriptor -} +}() diff --git a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_others.go index 2220e4f44ce..8bfdfd501f6 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_others.go @@ -96,7 +96,7 @@ func (s *scraper) scrapeAndAppendSwapUsageMetric(metrics pdata.MetricSlice) erro } func initializeSwapUsageMetric(metric pdata.Metric, vmem *mem.VirtualMemoryStat) { - metricSwapUsageDescriptor.CopyTo(metric.MetricDescriptor()) + swapUsageDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(3) @@ -128,7 +128,7 @@ func (s *scraper) scrapeAndAppendPagingMetrics(metrics pdata.MetricSlice) error } func initializePagingMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, swap *mem.SwapMemoryStat) { - metricPagingDescriptor.CopyTo(metric.MetricDescriptor()) + swapPagingDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(4) @@ -148,7 +148,7 @@ func initializePagingDataPoint(dataPoint pdata.Int64DataPoint, startTime pdata.T } func initializePageFaultsMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, swap *mem.SwapMemoryStat) { - metricPageFaultsDescriptor.CopyTo(metric.MetricDescriptor()) + swapPageFaultsDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(1) diff --git a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_test.go index 46691aa87d5..7e08e4ed90b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_test.go @@ -46,7 +46,7 @@ func TestScrapeMetrics(t *testing.T) { } func assertSwapUsageMetricValid(t *testing.T, hostSwapUsageMetric pdata.Metric) { - internal.AssertDescriptorEqual(t, metricSwapUsageDescriptor, hostSwapUsageMetric.MetricDescriptor()) + internal.AssertDescriptorEqual(t, swapUsageDescriptor, hostSwapUsageMetric.MetricDescriptor()) // it's valid for a system to have no swap space / paging file, so if no data points were returned, do no validation if hostSwapUsageMetric.Int64DataPoints().Len() == 0 { @@ -75,7 +75,7 @@ func assertSwapUsageMetricValid(t *testing.T, hostSwapUsageMetric pdata.Metric) } func assertPagingMetricValid(t *testing.T, pagingMetric pdata.Metric) { - internal.AssertDescriptorEqual(t, metricPagingDescriptor, pagingMetric.MetricDescriptor()) + internal.AssertDescriptorEqual(t, swapPagingDescriptor, pagingMetric.MetricDescriptor()) // expect an in & out datapoint, for both major and minor paging types (windows does not currently support minor paging data) expectedDataPoints := 4 @@ -98,7 +98,7 @@ func assertPagingMetricValid(t *testing.T, pagingMetric pdata.Metric) { func assertPageFaultsMetricValid(t *testing.T, pageFaultsMetric pdata.Metric) { // expect a single datapoint for the page faults metric with minor type - internal.AssertDescriptorEqual(t, metricPageFaultsDescriptor, pageFaultsMetric.MetricDescriptor()) + internal.AssertDescriptorEqual(t, swapPageFaultsDescriptor, pageFaultsMetric.MetricDescriptor()) assert.Equal(t, 1, pageFaultsMetric.Int64DataPoints().Len()) internal.AssertInt64MetricLabelHasValue(t, pageFaultsMetric, 0, typeLabelName, minorTypeLabelValue) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_windows.go b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_windows.go index 385530abee1..24d9bb757a9 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_windows.go +++ b/receiver/hostmetricsreceiver/internal/scraper/virtualmemoryscraper/virtualmemory_scraper_windows.go @@ -129,7 +129,7 @@ func (s *scraper) scrapeAndAppendSwapUsageMetric(metrics pdata.MetricSlice) erro } func initializeSwapUsageMetric(metric pdata.Metric, pageFiles []*pageFileData) { - metricSwapUsageDescriptor.CopyTo(metric.MetricDescriptor()) + swapUsageDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2 * len(pageFiles)) @@ -175,7 +175,7 @@ func (s *scraper) scrapeAndAppendPagingMetric(metrics pdata.MetricSlice) error { } func initializePagingMetric(metric pdata.Metric, startTime pdata.TimestampUnixNano, reads float64, writes float64) { - metricPagingDescriptor.CopyTo(metric.MetricDescriptor()) + swapPagingDescriptor.CopyTo(metric.MetricDescriptor()) idps := metric.Int64DataPoints() idps.Resize(2)