Custom metrics missing when using dotnet-monitor

Viewed 96

I am trying to set up the dotnet-monitor to get Prometheus style metrics on the metrics endpoint, but I cannot get my custom metrics reported through the API.

I made an application from the example in Collect metrics from .NET documentation. Using dotnet-counters monitor -p <ProcessID> HatCo.HatStore The result is the expected:

[HatCo.HatStore]
    hats-sold (Count / 1 sec)                          4    

Trying to get it through the dotnet-monitor does not include this counter, neither in the metrics or the livemetrics endpoint.

The settings.json (as described in the documentation) used by dotnet-monitor looks like this:

{
    "$schema": "https://aka.ms/dotnet-monitor-schema",
    "DefaultProcess": {
        "Filters": [{
            "Key": "ProcessName",
            "Value": "ToBeMeasured"
        }]
    },
    "Metrics": {
        "Providers": [
            {"ProviderName": "HatCo.HatStore"}
        ]
    }
}

And I have played with the parameter "IncludeDefaultProviders": false, which works as expected (the systemruntime metrics are not produced).

Do I need to register the "HatCo.HatStore" somewhere in the application?

1 Answers

According to the doc here

You need to add it like

{
  "Metrics": {
    "Providers": [
      {
        "ProviderName": "Microsoft-AspNetCore-Server-Kestrel",
        "CounterNames": [
          "connections-per-second",
          "total-connections"
        ]
      }
    ]
  }
}
Related