Skip to content

Commit

Permalink
removed stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Ting committed Aug 19, 2022
1 parent aa9a818 commit 7185ba0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
21 changes: 0 additions & 21 deletions src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,13 @@
// limitations under the License.
// </copyright>

using System.Diagnostics.Metrics;
using System.Reflection;
using Diagnostics = System.Diagnostics;

namespace OpenTelemetry.Instrumentation.Process;

internal class ProcessMetrics
{
internal static readonly AssemblyName AssemblyName = typeof(ProcessMetrics).Assembly.GetName();
internal static readonly Meter MeterInstance = new(AssemblyName.Name, AssemblyName.Version.ToString());

private const string MetricPrefix = "process.dotnet.";

static ProcessMetrics()
{
// TODO: change to ObservableUpDownCounter
MeterInstance.CreateObservableGauge(
$"{MetricPrefix}physical.memory.usage",
() => (long)Diagnostics.Process.GetCurrentProcess().WorkingSet64,
unit: "bytes",
description: "The amount of physical memory allocated for the current process.");

// TODO: change to ObservableUpDownCounter
MeterInstance.CreateObservableGauge(
$"{MetricPrefix}virtual.memory.usage",
() => (long)Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64,
unit: "bytes",
description: "The amount of virtual memory allocated for the current process.");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System.Collections.Generic;
using System.Linq;
using OpenTelemetry.Metrics;
using Xunit;

namespace OpenTelemetry.Instrumentation.Process.Tests;

public class ProcessMetricsTests
{
private const int MaxTimeToAllowForFlush = 10000;
private const string MetricPrefix = "process.dotnet.";

[Fact]
public void ProcessMetricsAreCaptured()
{
var exportedItems = new List<Metric>();
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddProcessInstrumentation()
.AddInMemoryExporter(exportedItems)
.Build();

meterProvider.ForceFlush(MaxTimeToAllowForFlush);

Assert.True(exportedItems.Count == 2);
Assert.StartsWith(MetricPrefix, exportedItems[0].Name);
Assert.StartsWith(MetricPrefix, exportedItems[1].Name);

var metric1 = exportedItems.FirstOrDefault(i => i.Name == "process.dotnet.physical.memory.usage");
Assert.NotNull(metric1);

var metric2 = exportedItems.FirstOrDefault(i => i.Name == "process.dotnet.virtual.memory.usage");
Assert.NotNull(metric2);
}
}

0 comments on commit 7185ba0

Please sign in to comment.