-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hostmetricsreceiver] add system uptime metric #35954
[hostmetricsreceiver] add system uptime metric #35954
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
return err | ||
} | ||
|
||
s.mb = metadata.NewMetricsBuilder(s.config.MetricsBuilderConfig, s.settings, metadata.WithStartTime(pcommon.Timestamp(bootTime*1e9))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice touch on start timestamp being set to boot time.
Heya @atoulme & @braydonk, based on this comment should I rename the scraper? Thanks for feedback! |
according to semantic convention, see discussion in: open-telemetry/semantic-conventions#1507
b182d27
to
5d9b9bb
Compare
Updated the metric to a gauge to align with the semantic convention, see discussion & reasoning in open-telemetry/semantic-conventions#1507 |
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add new uptime scraper to emit the `system.uptime` metric <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#31627 <!--Describe what testing was performed and which tests were added.--> #### Testing Unit test added. Also tested locally (Linux VM) with following config: ```yaml receivers: hostmetrics: scrapers: uptime: exporters: debug: verbosity: detailed service: pipelines: metrics: receivers: - hostmetrics exporters: - debug ``` <details><summary>Details</summary> <p> ```console $ make genotelcontribcol [...] $ make RUN_CONFIG=config-uptime.yaml run 2024-10-23T13:24:48.195+0200 info [email protected]/service.go:135 Setting up own telemetry... 2024-10-23T13:24:48.195+0200 info telemetry/metrics.go:70 Serving metrics {"address": "localhost:8888", "metrics level": "Normal"} 2024-10-23T13:24:48.195+0200 info builders/builders.go:26 Development component. May change in the future. {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:24:48.199+0200 info [email protected]/service.go:207 Starting otelcontribcol... {"Version": "0.112.0-dev", "NumCPU": 7} 2024-10-23T13:24:48.199+0200 info extensions/extensions.go:39 Starting extensions... 2024-10-23T13:24:48.199+0200 info [email protected]/service.go:230 Everything is ready. Begin running and processing data. 2024-10-23T13:24:49.202+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:24:49.202+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:24:49.202512199 +0000 UTC Value: 61287.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:25:49.206+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:25:49.206+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:25:49.206657828 +0000 UTC Value: 61347.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:26:49.205+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:26:49.205+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:26:49.2051249 +0000 UTC Value: 61407.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:27:49.210+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:27:49.210+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:27:49.21007371 +0000 UTC Value: 61467.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} ^C 2024-10-23T13:27:54.204+0200 info [email protected]/collector.go:328 Received signal from OS {"signal": "interrupt"} 2024-10-23T13:27:54.204+0200 info [email protected]/service.go:266 Starting shutdown... 2024-10-23T13:27:54.204+0200 info extensions/extensions.go:66 Stopping extensions... 2024-10-23T13:27:54.204+0200 info [email protected]/service.go:280 Shutdown complete. ``` </p> </details> <!--Describe the documentation added.--> #### Documentation Updated readme & generated scraper docs <!--Please delete paragraphs that you did not use before submitting.-->
Thank you for this feature @kevinnoel-be! I was out for too long and missed this one coming by, so was unable to get through my feedback that I maintain the scraper should be named |
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR makes some changes that I had hoped to suggest on #35954, however I was unable to make my comment in time before the PR was merged. The changes this PR makes are: * The `uptime` scraper is changed to be named `system` * The scraper is registered using the scraper name when adding to the scrapercontroller <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Amends the fix to #31627 (following a comment I made on #35932) <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation The documentation that was added for the `uptime` scraper was renamed accordingly, and the description adjusted. <!--Please delete paragraphs that you did not use before submitting.-->
…-telemetry#36123) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR makes some changes that I had hoped to suggest on open-telemetry#35954, however I was unable to make my comment in time before the PR was merged. The changes this PR makes are: * The `uptime` scraper is changed to be named `system` * The scraper is registered using the scraper name when adding to the scrapercontroller <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Amends the fix to open-telemetry#31627 (following a comment I made on open-telemetry#35932) <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation The documentation that was added for the `uptime` scraper was renamed accordingly, and the description adjusted. <!--Please delete paragraphs that you did not use before submitting.-->
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add new uptime scraper to emit the `system.uptime` metric <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#31627 <!--Describe what testing was performed and which tests were added.--> #### Testing Unit test added. Also tested locally (Linux VM) with following config: ```yaml receivers: hostmetrics: scrapers: uptime: exporters: debug: verbosity: detailed service: pipelines: metrics: receivers: - hostmetrics exporters: - debug ``` <details><summary>Details</summary> <p> ```console $ make genotelcontribcol [...] $ make RUN_CONFIG=config-uptime.yaml run 2024-10-23T13:24:48.195+0200 info [email protected]/service.go:135 Setting up own telemetry... 2024-10-23T13:24:48.195+0200 info telemetry/metrics.go:70 Serving metrics {"address": "localhost:8888", "metrics level": "Normal"} 2024-10-23T13:24:48.195+0200 info builders/builders.go:26 Development component. May change in the future. {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:24:48.199+0200 info [email protected]/service.go:207 Starting otelcontribcol... {"Version": "0.112.0-dev", "NumCPU": 7} 2024-10-23T13:24:48.199+0200 info extensions/extensions.go:39 Starting extensions... 2024-10-23T13:24:48.199+0200 info [email protected]/service.go:230 Everything is ready. Begin running and processing data. 2024-10-23T13:24:49.202+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:24:49.202+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:24:49.202512199 +0000 UTC Value: 61287.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:25:49.206+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:25:49.206+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:25:49.206657828 +0000 UTC Value: 61347.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:26:49.205+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:26:49.205+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:26:49.2051249 +0000 UTC Value: 61407.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:27:49.210+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:27:49.210+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:27:49.21007371 +0000 UTC Value: 61467.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} ^C 2024-10-23T13:27:54.204+0200 info [email protected]/collector.go:328 Received signal from OS {"signal": "interrupt"} 2024-10-23T13:27:54.204+0200 info [email protected]/service.go:266 Starting shutdown... 2024-10-23T13:27:54.204+0200 info extensions/extensions.go:66 Stopping extensions... 2024-10-23T13:27:54.204+0200 info [email protected]/service.go:280 Shutdown complete. ``` </p> </details> <!--Describe the documentation added.--> #### Documentation Updated readme & generated scraper docs <!--Please delete paragraphs that you did not use before submitting.-->
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add new uptime scraper to emit the `system.uptime` metric <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#31627 <!--Describe what testing was performed and which tests were added.--> #### Testing Unit test added. Also tested locally (Linux VM) with following config: ```yaml receivers: hostmetrics: scrapers: uptime: exporters: debug: verbosity: detailed service: pipelines: metrics: receivers: - hostmetrics exporters: - debug ``` <details><summary>Details</summary> <p> ```console $ make genotelcontribcol [...] $ make RUN_CONFIG=config-uptime.yaml run 2024-10-23T13:24:48.195+0200 info [email protected]/service.go:135 Setting up own telemetry... 2024-10-23T13:24:48.195+0200 info telemetry/metrics.go:70 Serving metrics {"address": "localhost:8888", "metrics level": "Normal"} 2024-10-23T13:24:48.195+0200 info builders/builders.go:26 Development component. May change in the future. {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:24:48.199+0200 info [email protected]/service.go:207 Starting otelcontribcol... {"Version": "0.112.0-dev", "NumCPU": 7} 2024-10-23T13:24:48.199+0200 info extensions/extensions.go:39 Starting extensions... 2024-10-23T13:24:48.199+0200 info [email protected]/service.go:230 Everything is ready. Begin running and processing data. 2024-10-23T13:24:49.202+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:24:49.202+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:24:49.202512199 +0000 UTC Value: 61287.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:25:49.206+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:25:49.206+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:25:49.206657828 +0000 UTC Value: 61347.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:26:49.205+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:26:49.205+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:26:49.2051249 +0000 UTC Value: 61407.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} 2024-10-23T13:27:49.210+0200 info Metrics {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1} 2024-10-23T13:27:49.210+0200 info ResourceMetrics #0 Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0 ScopeMetrics #0 ScopeMetrics SchemaURL: InstrumentationScope github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper 0.112.0-dev Metric #0 Descriptor: -> Name: system.uptime -> Description: The time the system has been running -> Unit: s -> DataType: Sum -> IsMonotonic: false -> AggregationTemporality: Cumulative NumberDataPoints #0 StartTimestamp: 2024-10-22 18:23:22 +0000 UTC Timestamp: 2024-10-23 11:27:49.21007371 +0000 UTC Value: 61467.000000 {"kind": "exporter", "data_type": "metrics", "name": "debug"} ^C 2024-10-23T13:27:54.204+0200 info [email protected]/collector.go:328 Received signal from OS {"signal": "interrupt"} 2024-10-23T13:27:54.204+0200 info [email protected]/service.go:266 Starting shutdown... 2024-10-23T13:27:54.204+0200 info extensions/extensions.go:66 Stopping extensions... 2024-10-23T13:27:54.204+0200 info [email protected]/service.go:280 Shutdown complete. ``` </p> </details> <!--Describe the documentation added.--> #### Documentation Updated readme & generated scraper docs <!--Please delete paragraphs that you did not use before submitting.-->
…-telemetry#36123) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR makes some changes that I had hoped to suggest on open-telemetry#35954, however I was unable to make my comment in time before the PR was merged. The changes this PR makes are: * The `uptime` scraper is changed to be named `system` * The scraper is registered using the scraper name when adding to the scrapercontroller <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Amends the fix to open-telemetry#31627 (following a comment I made on open-telemetry#35932) <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation The documentation that was added for the `uptime` scraper was renamed accordingly, and the description adjusted. <!--Please delete paragraphs that you did not use before submitting.-->
Description
Add new uptime scraper to emit the
system.uptime
metricLink to tracking issue
Fixes #31627
Testing
Unit test added. Also tested locally (Linux VM) with following config:
Details
Documentation
Updated readme & generated scraper docs