Skip to content

Commit

Permalink
change uptime scraper to system scraper
Browse files Browse the repository at this point in the history
This PR makes some changes that I had hoped to suggest on the PR that
introduced the uptime scraper, however I was unable to make my comment
in time before the PR was merged.

* The `uptime` scraper is changed to be named `system`
* The scraper is registered using the scraper name when adding to the
  scrapercontroller
  • Loading branch information
braydonk committed Oct 31, 2024
1 parent 909b1d3 commit dfef285
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .chloggen/add-hostmetric-system-uptime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ change_type: enhancement
component: hostmetricsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add an uptime scraper in the hostmetrics receiver
note: Add the system.uptime metric in the hostmetrics receiver

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31627]

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

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
Expand Down
12 changes: 6 additions & 6 deletions receiver/hostmetricsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- end autogenerated section -->

The Host Metrics receiver generates metrics about the host system scraped
from various sources and host entity event as log. This is intended to be
from various sources and host entity event as log. This is intended to be
used when the collector is deployed as an agent.

## Getting Started
Expand Down Expand Up @@ -49,7 +49,7 @@ The available scrapers are:
| [paging] | All | Paging/Swap space utilization and I/O metrics |
| [processes] | Linux, Mac | Process count metrics |
| [process] | Linux, Windows, Mac | Per process CPU, Memory, and Disk I/O metrics |
| [uptime] | Linux, Windows, Mac | Uptime metric |
| [system] | Linux, Windows, Mac | Miscellaneous system metrics |

[cpu]: ./internal/scraper/cpuscraper/documentation.md
[disk]: ./internal/scraper/diskscraper/documentation.md
Expand All @@ -60,7 +60,7 @@ The available scrapers are:
[paging]: ./internal/scraper/pagingscraper/documentation.md
[processes]: ./internal/scraper/processesscraper/documentation.md
[process]: ./internal/scraper/processscraper/documentation.md
[uptime]: ./internal/scraper/uptimescraper/documentation.md
[system]: ./internal/scraper/systemscraper/documentation.md

### Notes

Expand Down Expand Up @@ -172,14 +172,14 @@ service:

Host metrics are collected from the Linux system directories on the filesystem.
You likely want to collect metrics about the host system and not the container.
This is achievable by following these steps:
This is achievable by following these steps:

#### 1. Bind mount the host filesystem

The simplest configuration is to mount the entire host filesystem when running
The simplest configuration is to mount the entire host filesystem when running
the container. e.g. `docker run -v /:/hostfs ...`.

You can also choose which parts of the host filesystem to mount, if you know
You can also choose which parts of the host filesystem to mount, if you know
exactly what you'll need. e.g. `docker run -v /proc:/hostfs/proc`.

#### 2. Configure `root_path`
Expand Down
6 changes: 3 additions & 3 deletions receiver/hostmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
)

func TestLoadConfig(t *testing.T) {
Expand Down Expand Up @@ -119,8 +119,8 @@ func TestLoadConfig(t *testing.T) {
cfg.SetEnvMap(common.EnvMap{})
return cfg
})(),
uptimescraper.TypeStr: (func() internal.Config {
cfg := (&uptimescraper.Factory{}).CreateDefaultConfig()
systemscraper.TypeStr: (func() internal.Config {
cfg := (&systemscraper.Factory{}).CreateDefaultConfig()
cfg.SetEnvMap(common.EnvMap{})
return cfg
})(),
Expand Down
4 changes: 2 additions & 2 deletions receiver/hostmetricsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
)

const (
Expand All @@ -46,7 +46,7 @@ var (
pagingscraper.TypeStr: &pagingscraper.Factory{},
processesscraper.TypeStr: &processesscraper.Factory{},
processscraper.TypeStr: &processscraper.Factory{},
uptimescraper.TypeStr: &uptimescraper.Factory{},
systemscraper.TypeStr: &systemscraper.Factory{},
}
)

Expand Down
1 change: 1 addition & 0 deletions receiver/hostmetricsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/prometheus/procfs v0.15.1
github.com/shirou/gopsutil/v4 v4.24.9
github.com/stretchr/testify v1.9.0
github.com/tj/assert v0.0.3
github.com/yusufpapurcu/wmi v1.2.4
go.opentelemetry.io/collector/component v0.112.0
go.opentelemetry.io/collector/confmap v1.18.0
Expand Down
4 changes: 4 additions & 0 deletions receiver/hostmetricsreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
)

var allMetrics = []string{
Expand Down Expand Up @@ -82,7 +82,7 @@ var factories = map[string]internal.ScraperFactory{
pagingscraper.TypeStr: &pagingscraper.Factory{},
processesscraper.TypeStr: &processesscraper.Factory{},
processscraper.TypeStr: &processscraper.Factory{},
uptimescraper.TypeStr: &uptimescraper.Factory{},
systemscraper.TypeStr: &systemscraper.Factory{},
}

type testEnv struct {
Expand Down Expand Up @@ -404,7 +404,7 @@ func Benchmark_ScrapeUptimeMetrics(b *testing.B) {

cfg := &Config{
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
Scrapers: map[string]internal.Config{uptimescraper.TypeStr: (&uptimescraper.Factory{}).CreateDefaultConfig()},
Scrapers: map[string]internal.Config{systemscraper.TypeStr: (&systemscraper.Factory{}).CreateDefaultConfig()},
}

benchmarkScrapeMetrics(b, cfg)
Expand Down Expand Up @@ -444,6 +444,7 @@ func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) {
networkscraper.TypeStr: &networkscraper.Config{},
pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig(),
processesscraper.TypeStr: &processesscraper.Config{},
systemscraper.TypeStr: &systemscraper.Config{},
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
)

// Config relating to Uptime Metric Scraper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

//go:generate mdatagen metadata.yaml

package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper"
package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# hostmetricsreceiver/uptime
# hostmetricsreceiver/system

**Parent Component:** hostmetrics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"context"
"errors"
"runtime"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
hostmeta "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
)

// This file implements Factory for Uptime scraper.
// This file implements Factory for System scraper.

const (
// TypeStr the value of "type" key in configuration.
TypeStr = "uptime"
TypeStr = "system"
)

var (
// scraperType is the component type used for the built scraper.
scraperType component.Type = component.MustNewType(TypeStr)
)

// Factory is the Factory for scraper.
Expand All @@ -47,7 +52,7 @@ func (f *Factory) CreateMetricsScraper(
uptimeScraper := newUptimeScraper(ctx, settings, cfg.(*Config))

return scraperhelper.NewScraper(
hostmeta.Type,
scraperType,
uptimeScraper.scrape,
scraperhelper.WithStart(uptimeScraper.start),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package systemscraper

import (
"context"
"testing"

"github.com/tj/assert"
"go.opentelemetry.io/collector/receiver/receivertest"
)

func TestCreateSystemScraper(t *testing.T) {
factory := &Factory{}
cfg := &Config{}

scraper, err := factory.CreateMetricsScraper(context.Background(), receivertest.NewNopSettings(), cfg)

assert.NoError(t, err)
assert.NotNil(t, scraper)
assert.Equal(t, scraperType.String(), scraper.ID().String())
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type: hostmetricsreceiver/uptime
type: hostmetricsreceiver/system

parent: hostmetrics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package uptimescraper
package systemscraper

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"context"
Expand All @@ -14,7 +14,7 @@ import (
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
)

// scraper for Uptime Metrics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package uptimescraper
package systemscraper

import (
"context"
Expand All @@ -14,7 +14,7 @@ import (
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata"
)

func TestScrape(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ receivers:
include:
names: ["test2", "test3"]
match_type: "regexp"
uptime:
system:

processors:
nop:
Expand Down

0 comments on commit dfef285

Please sign in to comment.