dotnet-monitor can be easily configured to automatically collect dumps, traces and logs based on conditions detected within the monitored process. For example you could elect to capture a maximum of ten dumps over a sliding windows of 24 hours. Here is how I would define this in dotnet-monitor’s settings.json file (note the Limits section):

    "CollectionRules": {
      "LargeGCHeapSize": {
        "Trigger": {
          "Type": "EventCounter",
          "Settings": {
            "ProviderName": "System.Runtime",
            "CounterName": "gc-heap-size",
            "GreaterThan": 10
          }
        },
        "Limits": {
          "ActionCount": 10,
          "ActionCountSlidingWindowDuration": "1.00:00:00"
        },
        "Actions": [
          {
            "Type": "CollectGCDump",
            "Settings": {
              "Egress": "artifactStorage"
            }
          }
        ]
      }
    }

Up until recently the only way to see the state of the trigger was to look at dotnet-monitors logs, and even then you would only see if the trigger had been successfully started:

This picture shows the logs of dotnet monitor. Indicating that it

For my collection rule (“LargeGCHeapSize”) I could check the “state” by counting how many dumps have been created in the last 24 hours, however, our team had a customer request to provide a more intuitive way to query trigger state.

Thankfully our latest dotnet-monitor preview provides an endpoint to get the state of collection rules for a given process. To be clear this is just about viewing the current state via the API, this does not include functionality for enabling/disabling rules through the API, if you think that feature is important please let us know. Now when you navigate to the /collectionrules end point you get details about the trigger status and state reason as follows:

{
   "LargeGCHeapSize":
   {
      "state":"Running",
      "stateReason":"This collection rule is active and waiting for its triggering conditions to be satisfied."
   }
}

To get even more details I can navigate to the specific rule /collectionrules/LargeGCHeapSize and that gives this output:

{
   "lifetimeOccurrences":0,
   "slidingWindowOccurrences":0,
   "actionCountLimit":10,
   "actionCountSlidingWindowDurationLimit":"1.00:00:00",
   "slidingWindowDurationCountdown":null,
   "ruleFinishedCountdown":null,
   "state":"Running",
   "stateReason":"This collection rule is active and waiting for its triggering conditions to be satisfied."
}

Check out the latest preview if you want to try this new feature.



Comment Section