dotnet-counters ObservableGauge of double incorrect values
Description
I tried to use the dotnet-counters to get some data while running inside the testhost (xUnit Test) that is testing a service inside my main project. For some reason the counters seem to ignore the NumberStyle or culture. At least thats what I think is happening. It could be helpful to know that my PC is set to german so the dot (.) and comma (,) are kind of switched 1.000,31 would be one-thousand-point-thirty-one (1,000.31)
My Test Code looks something like this
private void Setup()
{
var meter = new Meter("demo_meter");
meter.CreateObservableCounter("random", GetRadomMeasurement);
}
private Random rnd = new Random();
private Measurement<double> GetRadomMeasurement()
{
switch (rnd.Next(5))
{
case 0:
return new Measurement<double>(3.141, new KeyValuePair<string, object>("instance", "app"));
case 1:
return new Measurement<double>(42, new KeyValuePair<string, object>("instance", "app"));
case 2:
return new Measurement<double>(1.337, new KeyValuePair<string, object>("instance", "app"));
case 3:
return new Measurement<double>(800.85, new KeyValuePair<string, object>("instance", "app"));
case 4:
return new Measurement<double>(6.9, new KeyValuePair<string, object>("instance", "app"));
case 5:
return new Measurement<double>(10, new KeyValuePair<string, object>("instance", "app"));
default:
return new Measurement<double>(0, new KeyValuePair<string, object>("instance", "app"));
}
}
From my understanding using:
dotnet-counters monitor demo_meter -n testhost
should result in 3.141; 42; 1.337; 800.85; 6.9 or 10 but it doesnt instead i get: 799.513 38.859 -79.395
The same thing is happening when using
dotnet-counters collect demo_meter -n testhost -format csv
Timestamp,Provider,Counter Name,Counter Type,Mean/Increment
20.09.2022 18:26:13,demo_meter,random (Count / 1 sec)[instance=app],Rate,799513
20.09.2022 18:26:14,demo_meter,random (Count / 1 sec)[instance=app],Rate,-79395
20.09.2022 18:26:15,demo_meter,random (Count / 1 sec)[instance=app],Rate,-37590000000000000
20.09.2022 18:26:16,demo_meter,random (Count / 1 sec)[instance=app],Rate,7977090000000001
20.09.2022 18:26:17,demo_meter,random (Count / 1 sec)[instance=app],Rate,-799513
20.09.2022 18:26:18,demo_meter,random (Count / 1 sec)[instance=app],Rate,1804
20.09.2022 18:26:19,demo_meter,random (Count / 1 sec)[instance=app],Rate,38859
20.09.2022 18:26:20,demo_meter,random (Count / 1 sec)[instance=app],Rate,-351
20.09.2022 18:26:21,demo_meter,random (Count / 1 sec)[instance=app],Rate,351
20.09.2022 18:26:22,demo_meter,random (Count / 1 sec)[instance=app],Rate,-351
20.09.2022 18:26:23,demo_meter,random (Count / 1 sec)[instance=app],Rate,-37590000000000000
20.09.2022 18:26:24,demo_meter,random (Count / 1 sec)[instance=app],Rate,0
When using the dotnet-counters monitor -n testhost it seems to work jsut fine: GC Fragmentation display values like 4,63 (4.63 in US format)
Configuration
.NET 6.0.400 dotnet-counters 6.0.320703
Just to have some visuals:
This Measurement
resulted in:

@dramos020 would you mind taking a look?
You should be using an ObservableGauge if you are trying to measure the random values themselves. In your example you are using an ObservableCounter, which measures the rate of change. Can see more about the difference here: https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-instrumentation
Since this seems to be solved from the comment above, I'm going to close this issue. If you are still having this issue, feel free to open a new issue.