From 1bad34558a842a761eb65ad8bb9d64d4088f91ee Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Wed, 8 Feb 2023 16:27:42 -0800 Subject: [PATCH 01/14] draft --- .../ProcessMetrics.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs index 5835ce228c..1b5c84e38d 100644 --- a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs @@ -16,6 +16,7 @@ #nullable enable +using System; using System.Collections.Generic; using System.Diagnostics.Metrics; using System.Reflection; @@ -64,6 +65,15 @@ static ProcessMetrics() unit: "s", description: "Total CPU seconds broken down by different states."); + MeterInstance.CreateObservableUpDownCounter( + "process.processor.count", + () => + { + return Environment.ProcessorCount; + }, + unit: "{processors}", + description: "Processor count."); + MeterInstance.CreateObservableUpDownCounter( "process.threads", () => From 11d8df66a06f89b1995b30b692470e00ecda8525 Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Wed, 8 Feb 2023 16:41:40 -0800 Subject: [PATCH 02/14] test and description --- .../ProcessMetrics.cs | 4 ++-- .../ProcessMetricsTests.cs | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs index 1b5c84e38d..6fae5de94c 100644 --- a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs @@ -66,13 +66,13 @@ static ProcessMetrics() description: "Total CPU seconds broken down by different states."); MeterInstance.CreateObservableUpDownCounter( - "process.processor.count", + "process.processors", () => { return Environment.ProcessorCount; }, unit: "{processors}", - description: "Processor count."); + description: "Process processors count."); MeterInstance.CreateObservableUpDownCounter( "process.threads", diff --git a/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs b/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs index e63b89f1fe..236caadc9d 100644 --- a/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs +++ b/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs @@ -38,13 +38,15 @@ public void ProcessMetricsAreCaptured() meterProviderA.ForceFlush(MaxTimeToAllowForFlush); - Assert.True(exportedItemsA.Count == 4); + Assert.True(exportedItemsA.Count == 5); var physicalMemoryMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.usage"); Assert.NotNull(physicalMemoryMetric); var virtualMemoryMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.virtual"); Assert.NotNull(virtualMemoryMetric); var cpuTimeMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.time"); Assert.NotNull(cpuTimeMetric); + var processorCountMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.processors"); + Assert.NotNull(processorCountMetric); var threadMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.threads"); Assert.NotNull(threadMetric); @@ -66,8 +68,8 @@ public void ProcessMetricsAreCaptured() meterProviderB.ForceFlush(MaxTimeToAllowForFlush); - Assert.True(exportedItemsA.Count == 4); - Assert.True(exportedItemsB.Count == 4); + Assert.True(exportedItemsA.Count == 5); + Assert.True(exportedItemsB.Count == 5); } [Fact] @@ -142,23 +144,27 @@ public void ProcessMetricsAreCapturedWhenTasksOverlap() Task.WaitAll(tasks.ToArray()); - Assert.True(exportedItemsA.Count == 4); + Assert.True(exportedItemsA.Count == 5); var physicalMemoryMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.usage"); Assert.NotNull(physicalMemoryMetricA); var virtualMemoryMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.virtual"); Assert.NotNull(virtualMemoryMetricA); var cpuTimeMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.time"); Assert.NotNull(cpuTimeMetricA); + var processorCountMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.processors"); + Assert.NotNull(processorCountMetricA); var threadMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.threads"); Assert.NotNull(threadMetricA); - Assert.True(exportedItemsB.Count == 4); + Assert.True(exportedItemsB.Count == 5); var physicalMemoryMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.memory.usage"); Assert.NotNull(physicalMemoryMetricB); var virtualMemoryMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.memory.virtual"); Assert.NotNull(virtualMemoryMetricB); var cpuTimeMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.cpu.time"); Assert.NotNull(cpuTimeMetricB); + var processorCountMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.processors"); + Assert.NotNull(processorCountMetricB); var threadMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.threads"); Assert.NotNull(threadMetricB); } From a6e401c991031c0a82416c1f6349e13ebd14c57f Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Wed, 8 Feb 2023 16:47:47 -0800 Subject: [PATCH 03/14] readme --- .../README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 9481e7fb58..c36ca7c077 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -92,6 +92,20 @@ Gets the user processor time for this process. * [Process.PrivilegedProcessorTime](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.privilegedprocessortime): Gets the privileged processor time for this process. +### process.processors + +Process threads count. + +| Units | Instrument Type | Value Type | +|---------------|-------------------------|------------| +| `{processors}`| ObservableUpDownCounter | `Int32` | + +The API used to retrieve the value is: + +* [Process.processors](https://learn.microsoft.com/dotnet/api/system.environment.processorcount): +Gets the number of processors available +to the current process. + ### process.threads Process threads count. From a9ebd6cc2db04545d3d2e3ba904c323e95e3b6ce Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 13:40:10 -0800 Subject: [PATCH 04/14] comment --- src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs index 6fae5de94c..222eccaf8f 100644 --- a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs @@ -66,13 +66,13 @@ static ProcessMetrics() description: "Total CPU seconds broken down by different states."); MeterInstance.CreateObservableUpDownCounter( - "process.processors", + "process.cpu.count", () => { return Environment.ProcessorCount; }, unit: "{processors}", - description: "Process processors count."); + description: "The number of processors (CPU cores) available to the current process."); MeterInstance.CreateObservableUpDownCounter( "process.threads", From 6ceeeec6e2b8a4305b667fae58a1de8b34f56c56 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 13:56:34 -0800 Subject: [PATCH 05/14] changelog --- src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md index 1a4619c826..438feb2fcc 100644 --- a/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Added `process.cpu.count` metric. + ([#981](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/981)) + * Removed CPU utilization metric `process.cpu.utilization`. ([#972](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/972)) From 4c1564f2365743f8f4cbae1928293d2bc359e3ad Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 13:59:51 -0800 Subject: [PATCH 06/14] readme --- src/OpenTelemetry.Instrumentation.Process/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index c36ca7c077..09f7c00a9f 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -92,9 +92,9 @@ Gets the user processor time for this process. * [Process.PrivilegedProcessorTime](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.privilegedprocessortime): Gets the privileged processor time for this process. -### process.processors +### process.cpu.count -Process threads count. +Process processor (CPU cores) count. | Units | Instrument Type | Value Type | |---------------|-------------------------|------------| From c5ad08e3111c9fb45f994baab6bec8e05d7632be Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 14:03:05 -0800 Subject: [PATCH 07/14] s --- src/OpenTelemetry.Instrumentation.Process/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 09f7c00a9f..0a0c4f0094 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -94,7 +94,7 @@ Gets the privileged processor time for this process. ### process.cpu.count -Process processor (CPU cores) count. +Process processors (CPU cores) count. | Units | Instrument Type | Value Type | |---------------|-------------------------|------------| From 5bac1ad93ff15e7e6bd297fb40b382afca37ff63 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 14:13:58 -0800 Subject: [PATCH 08/14] test --- .../ProcessMetricsTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs b/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs index 236caadc9d..0ba48f3151 100644 --- a/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs +++ b/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs @@ -45,9 +45,9 @@ public void ProcessMetricsAreCaptured() Assert.NotNull(virtualMemoryMetric); var cpuTimeMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.time"); Assert.NotNull(cpuTimeMetric); - var processorCountMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.processors"); + var processorCountMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.count"); Assert.NotNull(processorCountMetric); - var threadMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.threads"); + var threadMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.count"); Assert.NotNull(threadMetric); exportedItemsA.Clear(); @@ -151,7 +151,7 @@ public void ProcessMetricsAreCapturedWhenTasksOverlap() Assert.NotNull(virtualMemoryMetricA); var cpuTimeMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.time"); Assert.NotNull(cpuTimeMetricA); - var processorCountMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.processors"); + var processorCountMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.count"); Assert.NotNull(processorCountMetricA); var threadMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.threads"); Assert.NotNull(threadMetricA); @@ -163,7 +163,7 @@ public void ProcessMetricsAreCapturedWhenTasksOverlap() Assert.NotNull(virtualMemoryMetricB); var cpuTimeMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.cpu.time"); Assert.NotNull(cpuTimeMetricB); - var processorCountMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.processors"); + var processorCountMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.cpu.count"); Assert.NotNull(processorCountMetricB); var threadMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.threads"); Assert.NotNull(threadMetricB); From 0b7ab9ac447f910d6c331f2ff77a40e5e5e4cd7b Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 14:15:02 -0800 Subject: [PATCH 09/14] Update src/OpenTelemetry.Instrumentation.Process/README.md Co-authored-by: Cijo Thomas --- src/OpenTelemetry.Instrumentation.Process/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 0a0c4f0094..e0d61f2f96 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -94,7 +94,7 @@ Gets the privileged processor time for this process. ### process.cpu.count -Process processors (CPU cores) count. +The number of processors (CPU cores) available to the current process. | Units | Instrument Type | Value Type | |---------------|-------------------------|------------| From 11d3ff3e88b38126d95b6b8ebb0745b060499439 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 19:53:35 -0800 Subject: [PATCH 10/14] Update src/OpenTelemetry.Instrumentation.Process/README.md Co-authored-by: Reiley Yang --- src/OpenTelemetry.Instrumentation.Process/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index e0d61f2f96..3c21cf3679 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -100,11 +100,7 @@ The number of processors (CPU cores) available to the current process. |---------------|-------------------------|------------| | `{processors}`| ObservableUpDownCounter | `Int32` | -The API used to retrieve the value is: - -* [Process.processors](https://learn.microsoft.com/dotnet/api/system.environment.processorcount): -Gets the number of processors available -to the current process. +The API used to retrieve the value is [System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount). ### process.threads From 5ab3d56a618bf1dda1f1342991b8ad31bd67acb0 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 13 Feb 2023 22:13:54 -0800 Subject: [PATCH 11/14] fix merge --- src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md index 280d11a7cd..5a65615f4f 100644 --- a/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Added `process.cpu.count` metric. + ([#981](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/981)) + ## 1.0.0-alpha.6 Released 2023-Feb-13 From 61aa2b2129a0a934fe863e32a6e5fec10a931395 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Wed, 15 Feb 2023 10:13:32 -0800 Subject: [PATCH 12/14] clarification --- src/OpenTelemetry.Instrumentation.Process/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 3c21cf3679..4905fb2401 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -102,6 +102,10 @@ The number of processors (CPU cores) available to the current process. The API used to retrieve the value is [System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount). +Note: +This metric is under [discussion](https://github.com/open-telemetry/opentelemetry-specification/issues/3200) +and not part of the [Process Metrics Spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md) at this time. + ### process.threads Process threads count. From bcec19e3afc0e00e791e9fc5345a2e07cf4cef71 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Wed, 15 Feb 2023 10:34:09 -0800 Subject: [PATCH 13/14] fix --- src/OpenTelemetry.Instrumentation.Process/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 4905fb2401..7e2d242703 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -103,8 +103,11 @@ The number of processors (CPU cores) available to the current process. The API used to retrieve the value is [System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount). Note: -This metric is under [discussion](https://github.com/open-telemetry/opentelemetry-specification/issues/3200) -and not part of the [Process Metrics Spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md) at this time. +This metric is under [discussion][1] and not part of the +[Process Metrics Spec][2] at this time. + +[1]: https://github.com/open-telemetry/opentelemetry-specification/issues/3200 +[2]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md ### process.threads From ffee59ea80f110c6483aaf5b40e69dbccbe5c7c2 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Wed, 15 Feb 2023 10:43:32 -0800 Subject: [PATCH 14/14] style --- src/OpenTelemetry.Instrumentation.Process/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 7e2d242703..b4432e3670 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -102,8 +102,8 @@ The number of processors (CPU cores) available to the current process. The API used to retrieve the value is [System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount). -Note: -This metric is under [discussion][1] and not part of the +> **Note** +> This metric is under [discussion][1] and not part of the [Process Metrics Spec][2] at this time. [1]: https://github.com/open-telemetry/opentelemetry-specification/issues/3200