### List Processes HTTP Request Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/processes-list.md This is an example of an HTTP GET request to list available processes. Ensure the Host header is set correctly and include an Authorization header with a valid token. ```http GET /processes HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Install prerelease dotnet monitor global tool Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/setup.md Install the latest prerelease version of the dotnet monitor global tool. This requires adding a specific package feed. ```cmd dotnet tool install -g dotnet-monitor --add-source https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet-tools/nuget/v3/index.json --prerelease ``` -------------------------------- ### Example Merged Configuration Output Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/view-merged-configuration.md This is an example of the JSON output you can expect when viewing the merged configuration. It details various settings like URLs, diagnostic port, metrics, storage, and authentication. ```json Tell us about your experience with dotnet monitor: https://aka.ms/dotnet-monitor-survey { "urls": "https://localhost:52323", "Kestrel": ":NOT PRESENT:", "CorsConfiguration": ":NOT PRESENT:", "DiagnosticPort": { "ConnectionMode": "Connect", "EndpointName": null }, "Metrics": { "Enabled": "True", "Endpoints": "http://*:52325", "IncludeDefaultProviders": "True", "MetricCount": "3", "Providers": { "0": { "CounterNames": { "0": "connections-per-second", "1": "total-connections" }, "ProviderName": "Microsoft-AspNetCore-Server-Kestrel" } }, }, "Storage": { "DumpTempFolder": "C:\\Users\\shirh\\AppData\\Local\\Temp\\" }, "Authentication": { "MonitorApiKey": { "Subject": "2c866b1a-38c5-4454-a686-1e022e38a7f6", "PublicKey": ":REDACTED:" } }, "Egress": ":NOT PRESENT:" } ``` -------------------------------- ### Sample HTTP Request for Get Operation Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/operations-get.md This sample demonstrates how to make an HTTP GET request to retrieve details of a specific operation. Ensure the Host and Authorization headers are correctly set. ```http GET /operations/67f07e40-5cca-4709-9062-26302c484f18 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### HTTP GET Request for Info Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/info.md This is an example of an HTTP GET request to the /info endpoint. Ensure the Host header matches the dotnet monitor's address. ```http GET /info HTTP/1.1 Host: localhost:52323 ``` -------------------------------- ### Start dotnet monitor Collection Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/localmachine.md Run this command in PowerShell or Command Prompt to start `dotnet monitor` and begin collecting data. Ensure your target process is running. ```cmd dotnet-monitor collect ``` -------------------------------- ### Install dotnet monitor global tool Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/setup.md Use this command to download the latest version of the dotnet monitor global tool. Ensure you have a .NET 3.1 or newer SDK installed. ```cmd dotnet tool install -g dotnet-monitor ``` -------------------------------- ### HTTP GET Request for Stacks Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/stacks.md This is an example of an HTTP GET request to capture call stacks for a specific process ID. Ensure the Authorization header is correctly set and the Accept header specifies the desired response format. ```http GET /stacks?pid=21632 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= Accept: application/json ``` -------------------------------- ### Sample HTTP Request using UID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/process-env.md Example of an HTTP GET request to retrieve the environment block of a process using its Unique ID (UID). Ensure the Host and Authorization headers are correctly set. ```http GET /env?uid=cd4da319-fa9e-4987-ac4e-e57b2aac248b HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Sample Trace Request using PID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/trace-get.md Example of a GET request to capture a trace using a process ID (pid), specifying HTTP and metrics profiles, and a duration of 60 seconds. ```http GET /trace?pid=21632&profile=http,metrics&durationSeconds=60 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Sample Trace Request using UID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/trace-get.md Example of a GET request to capture a trace using a unique process identifier (uid), specifying HTTP and metrics profiles, and a duration of 60 seconds. ```http GET /trace?uid=cd4da319-fa9e-4987-ac4e-e57b2aac248b&profile=http,metrics&durationSeconds=60 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Sample HTTP Request using PID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/process-env.md Example of an HTTP GET request to retrieve the environment block of a process using its Process ID (PID). Ensure the Host and Authorization headers are correctly set. ```http GET /env?pid=21632 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Sample HTTP Response for Successful Get Operation Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/operations-get.md This sample shows a successful HTTP response (200 OK) for a GET operation request. It includes details about the operation's status, resource location, and associated process. ```http HTTP/1.1 200 OK Content-Type: application/json { "resourceLocation": "https://example.blob.core.windows.net/dotnet-monitor/artifacts%2Fcore_20210721_062115", "error": null, "operationId": "67f07e40-5cca-4709-9062-26302c484f18", "createdDateTime": "2021-07-21T06:21:15.315861Z", "status": "Succeeded", "egressProviderName": "monitorBlob", "isStoppable": true, "process": { "pid":1, "uid":"95b0202a-4ed3-44a6-98f1-767d270ec783", "name":"dotnet-monitor-demo" }, "tags": [] } ``` -------------------------------- ### Request with include and exclude filters Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/exceptions-custom.md Example request demonstrating how to include exceptions from a specific type while excluding exceptions from a specific method. ```http POST /exceptions HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= Accept: application/x-ndjson { "Include": [ { "typeName": "MyClass" } ], "Exclude": [ { "methodName": "MyExceptionMethod" } ], } ``` -------------------------------- ### Example Authorization Header Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api-key-setup.md A valid `Authorization` header format for accessing the HTTP API using a Bearer token generated by the `generatekey` command. ```text Bearer eyJhbGciOiJFUffffffffffffCI6IkpXVCJ9.eyJhdWQiOiJodffffffffffffGh1Yi5jb20vZG90bmV0L2RvdG5ldC1tb25pdG9yIiwiaXNzIjoiaHR0cHM6Ly9naXRodWIuY29tL2RvdG5ldC9kb3RuZXQtbW9uaXRvci9nZW5lcmF0ZWtleStNb25pdG9yQXBpS2V5Iiwic3ViIjoiYWU1NDczYjYtOGRhZC00OThkLWI5MTUtNTNiOWM2ODQwMDBlIn0.RZffffffffffff_yIyApvFKcxFpDJ65HJZek1_dt7jCTCMEEEffffffffffffR08OyhZZHs46PopwAsf_6fdTLKB1UGvLr95volwEwIFnHjdvMfTJ9ffffffffffffAU ``` -------------------------------- ### HTTP GET Request for Metrics Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/metrics.md This is an example of an HTTP GET request to the /metrics endpoint. It is used to retrieve a snapshot of process metrics. ```http GET /metrics HTTP/1.1 Host: localhost:52325 ``` -------------------------------- ### Example settings.json Configuration Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api-key-setup.md A typical `settings.json` file structure for configuring the Monitor API Key. Ensure you use a unique key generated by the `generatekey` command. ```json { "$schema": "https://aka.ms/dotnet-monitor-schema", "Authentication": { "MonitorApiKey": { "Subject": "ae5473b6-8dad-498d-b915-ffffffffffff", "PublicKey": "eyffffffffffffFsRGF0YSI6e30sIkNydiI6IlAtMzg0IiwiS2V5T3BzIjpbXSwiS3R5IjoiRUMiLCJYIjoiTnhIRnhVZ19QM1dhVUZWVzk0U3dUY3FzVk5zNlFLYjZxc3AzNzVTRmJfQ3QyZHdpN0RWRl8tUTVheERtYlJuWSIsIlg1YyI6W10sIlkiOiJmMXBDdmNoUkVpTWEtc1h6SlZQaS02YmViMHdrZmxfdUZBN0Vka2dwcjF5N251Wmk2cy1NcHl5RzhKdVFSNWZOIiwiS2V5U2l6ZSI6Mzg0LCJIYXNQcml2YXRlS2V5IjpmYWxzZSwiQ3J5cHRvUHJvdmlkZXJGYWN0b3J5Ijp7IkNyeXB0b1Byb3ZpZGVyQ2FjaGUiOnt9LCJDYWNoZVNpZ25hdHVyZVByb3ZpZGVycyI6dHJ1ZSwiU2lnbmF0dXJlUHJvdmlkZXJPYmplY3RQb29sQ2FjaGffffffffffff19" } } } ``` -------------------------------- ### Build and Test dotnet-monitor on Windows Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/building.md Use these commands to clone, build, and test the repository on a Windows machine. ```cmd cd $HOME git clone https://github.com/dotnet/dotnet-monitor cd dotnet-monitor .\Build.cmd .\Test.cmd ``` -------------------------------- ### CPU Usage Trigger Shortcut Example (JSON) Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/collectionrules/triggershortcuts.md This JSON configuration demonstrates the CPUUsage trigger shortcut. It triggers when CPU usage is higher than 50% for a 1-minute window. ```json { "Trigger": { "Type": "CPUUsage" } } ``` -------------------------------- ### Get Environment Variable Action in Kubernetes ConfigMap Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/collection-rule-configuration.md Configure the `GetEnvironmentVariable` action using a Kubernetes ConfigMap. This example includes surrounding actions for context. ```yaml CollectionRules__RuleName__Actions__0__Name: "A" CollectionRules__RuleName__Actions__0__Type: "CollectTrace" CollectionRules__RuleName__Actions__0__Settings__Profile: "Cpu" CollectionRules__RuleName__Actions__0__Settings__Egress: "AzureBlob" CollectionRules__RuleName__Actions__1__Name: "GetEnvAction" CollectionRules__RuleName__Actions__1__Type: "GetEnvironmentVariable" CollectionRules__RuleName__Actions__1__Settings__Name: "Azure_SASToken" CollectionRules__RuleName__Actions__2__Name: "B" CollectionRules__RuleName__Actions__2__Type: "Execute" CollectionRules__RuleName__Actions__2__Settings__Path: "azcopy" CollectionRules__RuleName__Actions__2__Settings__Arguments: "$(Actions.A.EgressPath) https://Contoso.blob.core.windows.net/MyTraces/AwesomeAppTrace.nettrace?$(Actions.GetEnvAction.Value)" ``` -------------------------------- ### Get Environment Variable Action in Full JSON Action List Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/collection-rule-configuration.md This example shows the `GetEnvironmentVariable` action within a larger list of actions, providing context for its usage. ```json [{ "Name": "A", "Type": "CollectTrace", "Settings": { "Profile": "Cpu", "Egress": "AzureBlob" } },{ "Name": "GetEnvAction", "Type": "GetEnvironmentVariable", "Settings": { "Name": "Azure_SASToken" } },{ "Name": "B", "Type": "Execute", "Settings": { "Path": "azcopy", "Arguments": "$(Actions.A.EgressPath) https://Contoso.blob.core.windows.net/MyTraces/AwesomeAppTrace.nettrace?$(Actions.GetEnvAction.Value)" } }] ``` -------------------------------- ### Show Configuration Sources - .NET Monitor Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/view-merged-configuration.md Use this command to view the specific configuration providers that were loaded and used by .NET Monitor. This helps in understanding where each configuration setting originated. ```bash dotnet-monitor config show --show-sources ``` -------------------------------- ### Get Environment Variable Action in Kubernetes Environment Variables Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/collection-rule-configuration.md Set up the `GetEnvironmentVariable` action via Kubernetes environment variables. This example shows the full action list configuration. ```yaml - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Name value: "A" - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Type value: "CollectTrace" - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Settings__Profile value: "Cpu" - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Settings__Egress value: "AzureBlob" - name: DotnetMonitor_CollectionRules__RuleName__Actions__1__Name value: "GetEnvAction" - name: DotnetMonitor_CollectionRules__RuleName__Actions__1__Type value: "GetEnvironmentVariable" - name: DotnetMonitor_CollectionRules__RuleName__Actions__1__Settings__Name value: "Azure_SASToken" - name: DotnetMonitor_CollectionRules__RuleName__Actions__2__Name value: "B" - name: DotnetMonitor_CollectionRules__RuleName__Actions__2__Type value: "Execute" - name: DotnetMonitor_CollectionRules__RuleName__Actions__2__Settings__Path value: "azcopy" - name: DotnetMonitor_CollectionRules__RuleName__Actions__2__Settings__Arguments value: "$(Actions.A.EgressPath) https://Contoso.blob.core.windows.net/MyTraces/AwesomeAppTrace.nettrace?$(Actions.GetEnvAction.Value)" ``` -------------------------------- ### CPU Usage Trigger Shortcut Example (Kubernetes ConfigMap) Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/collectionrules/triggershortcuts.md This Kubernetes ConfigMap configuration utilizes the CPUUsage trigger shortcut. It simplifies the setup for monitoring high CPU usage. ```yaml CollectionRules__RuleName__Trigger__Type: "CPUUsage" ``` -------------------------------- ### Build and Test dotnet-monitor on Linux/macOS Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/building.md Use these commands to clone, build, and test the repository on Linux or macOS systems. ```bash cd $HOME git clone https://github.com/dotnet/dotnet-monitor cd dotnet-monitor ./build.sh ./test.sh ``` -------------------------------- ### List All Operations Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/operations-list.md This sample demonstrates how to list all operations without any specific filters. Ensure you include the Authorization header with a valid token. ```http GET /operations HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### API Key and Configuration Output Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api-key-setup.md This is an example of the output from the `generatekey` command, showing the Authorization header and JSON configuration. Note that the values are placeholders and will not work for actual authentication. ```yaml Tell us about your experience with dotnet monitor: https://aka.ms/dotnet-monitor-survey Generated ApiKey for dotnet-monitor; use the following header for authorization: Authorization: Bearer eyJhbGciOiJFUffffffffffffCI6IkpXVCJ9.eyJhdWQiOiJodffffffffffffGh1Yi5jb20vZG90bmV0L2RvdG5ldC1tb25pdG9yIiwiaXNzIjoiaHR0cHM6Ly9naXRodWIuY29tL2RvdG5ldC9kb3RuZXQtbW9uaXRvci9nZW5lcmF0ZWtleStNb25pdG9yQXBpS2V5Iiwic3ViIjoiYWU1NDczYjYtOGRhZC00OThkLWI5MTUtNTNiOWM2ODQwMDBlIn0.RZffffffffffff_yIyApvFKcxFpDJ65HJZek1_dt7jCTCMEEEffffffffffffR08OyhZZHs46PopwAsf_6fdTLKB1UGvLr95volwEwIFnHjdvMfTJ9ffffffffffffAU Settings in Json format: { "Authentication": { "MonitorApiKey": { "Subject": "ae5473b6-8dad-498d-b915-ffffffffffff", "PublicKey": "eyffffffffffffFsRGF0YSI6e30sIkNydiI6IlAtMzg0IiwiS2V5T3BzIjpbXSwiS3R5IjoiRUMiLCJYIjoiTnhIRnhVZ19QM1dhVUZWVzk0U3dUY3FzVk5zNlFLYjZxc3AzNzVTRmJfQ3QyZHdpN0RWRl8tUTVheERtYlJuWSIsIlg1YyI6W10sIlkiOiJmMXBDdmNoUkVpTWEtc1h6SlZQaS02YmViMHdrZmxfdUZBN0Vka2dwcjF5N251Wmk2cy1NcHl5RzhKdVFSNWZOIiwiS2V5U2l6ZSI6Mzg0LCJIYXNQcml2YXRlS2V5IjpmYWxzZSwiQ3J5cHRvUHJvdmlkZXJGYWN0b3J5Ijp7IkNyeXB0b1Byb3ZpZGVyQ2FjaGUiOnt9LCJDYWNoZVNpZ25hdHVyZVByb3ZpZGVycyI6dHJ1ZSwiU2lnbmF0dXJlUHJvdmlkZXJPYmplY3RQb29sQ2FjaGffffffffffff19" } } } ``` -------------------------------- ### Logs Configuration Example Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/definitions.md Shows how to configure log collection levels and filtering for specific categories. Set a category's level to null to use the default logLevel. ```json { "filterSpecs": { "Microsoft.AspNetCore.Hosting": "Information" }, "useAppFilters": false } ``` -------------------------------- ### Sample GC Dump Request by PID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/gcdump.md Example of an HTTP GET request to capture a GC dump using the process ID (pid). Ensure the Host and Authorization headers are correctly set. ```http GET /gcdump?pid=21632 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Run .NET Monitor in Docker with API Key Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api-key-setup.md Start the .NET Monitor container using environment variables for authentication. Replace `` and `` with values obtained from the `generatekey` command. ```bash docker run --rm -p 127.0.0.1:52323:52323/tcp --entrypoint dotnet-monitor --env DOTNETMONITOR_Authentication__MonitorApiKey__Subject= --env DOTNETMONITOR_Authentication__MonitorApiKey__PublicKey= mcr.microsoft.com/dotnet/monitor collect --urls http://+:52323 --metricUrls http://+:52325 ``` -------------------------------- ### HTTP POST Request for Custom Logs Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/logs-custom.md This example demonstrates how to make a POST request to capture custom logs. It includes query parameters for process identification and duration, along with a JSON body specifying filter criteria and whether to use application filters. ```http POST /logs?pid=21632&durationSeconds=60 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= { "filterSpecs": { "Microsoft.AspNetCore.Hosting": "Information" }, "useAppFilters": false } ``` ```http POST /logs?uid=cd4da319-fa9e-4987-ac4e-e57b2aac248b&durationSeconds=60 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= { "filterSpecs": { "Microsoft.AspNetCore.Hosting": "Information" }, "useAppFilters": false } ``` -------------------------------- ### Sample GC Dump Request by UID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/gcdump.md Example of an HTTP GET request to capture a GC dump using the unique runtime instance ID (uid). Ensure the Host and Authorization headers are correctly set. ```http GET /gcdump?uid=cd4da319-fa9e-4987-ac4e-e57b2aac248b HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Get Process Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/processes.md Gets detailed information about a specified process. ```APIDOC ## Get Process ### Description Gets detailed information about a specified process. ### Method GET ### Endpoint /processes/{processId} ### Parameters #### Path Parameters - **processId** (string) - Required - The ID of the process to retrieve information for. ### Response #### Success Response (200) - **pid** (integer) - The process ID. - **name** (string) - The name of the process. - **executablePath** (string) - The full path to the executable file. - **arguments** (string) - The command-line arguments used to start the process. - **runtimeVersion** (string) - The version of the .NET runtime the process is using. - **workingDirectory** (string) - The current working directory of the process. - **identityName** (string) - The identity name of the process. - **moduleName** (string) - The name of the main module of the process. #### Response Example ```json { "pid": 1234, "name": "MyApplication", "executablePath": "/usr/bin/dotnet", "arguments": "/path/to/MyApplication.dll", "runtimeVersion": "6.0.0", "workingDirectory": "/app", "identityName": "user", "moduleName": "MyApplication.dll" } ``` ``` -------------------------------- ### Sample HTTP GET Request by UID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/process-get.md This sample shows how to request process information using the unique runtime instance ID (uid). Ensure the Host header and Authorization are correctly set. ```http GET /process?uid=cd4da319-fa9e-4987-ac4e-e57b2aac248b HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Get Process Environment Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/processes.md Gets the environment block of a specified process. (.NET 5+ only) ```APIDOC ## Get Process Environment ### Description Gets the environment block of a specified process. This endpoint is available for .NET 5+ processes. For .NET Core 3.1, this is not supported. ### Method GET ### Endpoint /processes/{processId}/environment ### Parameters #### Path Parameters - **processId** (string) - Required - The ID of the process for which to retrieve the environment block. ### Response #### Success Response (200) - **environmentVariables** (object) - A collection of environment variables for the process. - **key** (string) - The name of the environment variable. - **value** (string) - The value of the environment variable. #### Response Example ```json { "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "PATH": "/usr/local/bin:/usr/bin:/bin" } } ``` ``` -------------------------------- ### HTTP GET Route for Dumps Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/dump.md This is the base HTTP GET route for capturing a managed dump. It supports various query parameters to specify the process and dump type. ```http GET /dump?pid={pid}&uid={uid}&name={name}&type={type}&egressProvider={egressProvider}&tags={tags} HTTP/1.1 ``` -------------------------------- ### Configure API Key via Environment Variables Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/configuration-sources.md Demonstrates how to set API key configuration using environment variables. Double underscores are used to denote hierarchical structure. ```bash export Authentication__MonitorApiKey__Subject="ae5473b6-8dad-498d-b915-ffffffffffff" export Authentication__MonitorApiKey__PublicKey="eyffffffffffffFsRGF0YSI6e30sIkNydiI6IlAtMzg0IiwiS2V5T3BzIjpbXSwiS3R5IjoiRUMiLCJYIjoiTnhIRnhVZ19QM1dhVUZWVzk0U3dUY3FzVk5zNlFLYjZxc3AzNzVTRmJfQ3QyZHdpN0RWRl8tUTVheERtYlJuWSIsIlg1YyI6W10sIlkiOiJmMXBDdmNoUkVpTWEtc1h6SlZQaS02YmViMHdrZmxfdUZBN0Vka2dwcjF5N251Wmk2cy1NcHl5RzhKdVFSNWZOIiwiS2V5U2l6ZSI6Mzg0LCJIYXNQcml2YXRlS2V5IjpmYWxzZSwiQ3J5cHRvUHJvdmlkZXJGYWN0b3J5Ijp7IkNyeXB0b1Byb3ZpZGVyQ2FjaGUiOnt9LCJDYWNoZVNpZ25hdHVyZVByb3ZpZGVycyI6dHJ1ZSwiU2lnbmF0dXJlUHJvdmlkZXJPYmplY3RQb29sQ2FjaGffffffffffff19" ``` -------------------------------- ### Configure API Key in JSON Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/configuration-sources.md Example of how to configure an API key using a JSON settings file. This is useful for setting up authentication for dotnet monitor. ```json { "Authentication": { "MonitorApiKey": { "Subject": "ae5473b6-8dad-498d-b915-ffffffffffff", "PublicKey": "eyffffffffffffFsRGF0YSI6e30sIkNydiI6IlAtMzg0IiwiS2V5T3BzIjpbXSwiS3R5IjoiRUMiLCJYIjoiTnhIRnhVZ19QM1dhVUZWVzk0U3dUY3FzVk5zNlFLYjZxc3AzNzVTRmJfQ3QyZHdpN0RWRl8tUTVheERtYlJuWSIsIlg1YyI6W10sIlkiOiJmMXBDdmNoUkVpTWEtc1h6SlZQaS02YmViMHdrZmxfdUZBN0Vka2dwcjF5N251Wmk2cy1NcHl5RzhKdVFSNWZOIiwiS2V5U2l6ZSI6Mzg0LCJIYXNQcml2YXRlS2V5IjpmYWxzZSwiQ3J5cHRvUHJvdmlkZXJGYWN0b3J5Ijp7IkNyeXB0b1Byb3ZpZGVyQ2FjaGUiOnt9LCJDYWNoZVNpZ25hdHVyZVByb3ZpZGVycyI6dHJ1ZSwiU2lnbmF0dXJlUHJvdmlkZXJPYmplY3RQb29sQ2FjaGffffffffffff19" } } } ``` -------------------------------- ### Sample HTTP Response for Process Information Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/process-get.md This is a sample successful response (200 OK) containing detailed information about a process, including its PID, UID, name, command line, operating system, and architecture. ```http HTTP/1.1 200 OK Content-Type: application/json { "pid": 21632, "uid": "cd4da319-fa9e-4987-ac4e-e57b2aac248b", "name": "dotnet", "commandLine": "\"C:\\Program Files\\dotnet\\dotnet.exe\" ConsoleApp1.dll", "operatingSystem": "Windows", "processArchitecture": "x64", "managedEntryPointAssemblyName": "ConsoleApp1" } ``` -------------------------------- ### Collect CPU Usage Metrics (JSON) Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/collection-rule-configuration.md Configure collection of live CPU usage metrics for the System.Runtime provider. Egresses collected metrics to a provider named 'TmpDir'. ```json { "UseDefaultProviders": false, "Providers": [ { "ProviderName": "System.Runtime", "CounterNames": [ "cpu-usage" ] } ], "Egress": "TmpDir" } ``` -------------------------------- ### GET Request for Stacks API Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/stacks.md Use this sample request to get the stack trace of a process. Ensure the `pid` parameter is set to the target process ID. The `Authorization` header is required. ```http GET /stacks?pid=21632 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= Accept: text/plain ``` -------------------------------- ### Sample HTTP GET Request by PID Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/process-get.md This sample demonstrates how to request process information using the process ID (pid). Ensure the Host header and Authorization are correctly set. ```http GET /process?pid=21632 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= ``` -------------------------------- ### Load Profiler Action Configuration Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/collection-rule-configuration.md Configure the loading of an ICorProfilerCallback implementation into a target process as a startup profiler. This action requires a 'Startup' trigger. ```json { "Path": "Profilers\\Profiler.dll", "Clsid": "55b9554d-6115-45a2-be1e-c80f7fa35369" } ``` ```yaml CollectionRules__RuleName__Actions__0__Settings__Path: "Profilers\\Profiler.dll" CollectionRules__RuleName__Actions__0__Settings__Clsid: "55b9554d-6115-45a2-be1e-c80f7fa35369" ``` ```yaml - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Settings__Path value: "Profilers\\Profiler.dll" - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Settings__Clsid value: "55b9554d-6115-45a2-be1e-c80f7fa35369" ``` -------------------------------- ### Get Processes via Dotnet Monitor API Source: https://github.com/dotnet/dotnet-monitor/blob/main/samples/AKS_Tutorial/README.md Makes a GET request to the /processes endpoint of the dotnet-monitor API to retrieve a list of running processes. Requires a Bearer token for authorization. Replace with your actual token. ```bash curl -v -H "Authorization: Bearer " http://localhost:52323/processes ``` -------------------------------- ### Docker Container Entrypoint (v7) Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/compatibility/7.0/README.md In .NET Monitor 7, the Docker container's entrypoint was simplified to just the executable, moving collection arguments to the CMD instruction. This allows for easier overriding of arguments. ```docker ENTRYPOINT [ "dotnet-monitor" ] CMD [ "collect", "--urls", "https://+:52323", "--metricUrls", "http://+:52325" ] ``` -------------------------------- ### Generate API Key for Settings File Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api-key-setup.md Run this command to generate a unique API key in JSON format. Copy the output into your `settings.json` file. ```bash dotnet monitor generatekey --output json ``` -------------------------------- ### Configure CollectTrace and Execute Actions with Dependency Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/collectionrules/collectionrules.md This JSON configuration demonstrates how to set up a CollectTrace action and an Execute action, where the Execute action's arguments depend on an output from the CollectTrace action. This is useful for passing information like egress paths to external executables. ```json { "Actions": [{ "Name": "A", "Type": "CollectTrace", "Settings": { "Profile": "Cpu", "Egress": "AzureBlob" } },{ "Name": "B", "Type": "Execute", "Settings": { "Path": "path-to-dotnet", "Arguments": "MyApp.dll $(Actions.A.EgressPath)" } }] } ``` -------------------------------- ### Example Azure Pipelines YAML for 1ES Managed Templates Source: https://github.com/dotnet/dotnet-monitor/blob/main/eng/common/template-guidance.md This example demonstrates how to configure an Azure Pipeline to use 1ES managed templates, specifically utilizing the `outputs` feature within `templateContext` to consolidate publish artifacts and reduce security scan overhead. This approach is only applicable when referencing `templates-official`. ```yaml extends: template: azure-pipelines/MicroBuild.1ES.Official.yml@MicroBuildTemplate parameters: stages: - stage: build jobs: - template: /eng/common/templates-official/jobs/jobs.yml@self parameters: # 1ES makes use of outputs to reduce security task injection overhead templateContext: outputs: - output: pipelineArtifact displayName: 'Publish logs from source' continueOnError: true condition: always() targetPath: $(Build.ArtifactStagingDirectory)/artifacts/log artifactName: Logs jobs: - job: Windows steps: - script: echo "friendly neighborhood" > artifacts/marvel/spiderman.txt # copy build outputs to artifact staging directory for publishing - task: CopyFiles@2 displayName: Gather build output inputs: SourceFolder: '$(System.DefaultWorkingDirectory)/artifacts/marvel' Contents: '**' TargetFolder: '$(Build.ArtifactStagingDirectory)/artifacts/marvel' ``` -------------------------------- ### /info Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/README.md Gets info about `dotnet monitor`. This endpoint was introduced in version 6.0. ```APIDOC ## GET /info ### Description Gets info about `dotnet monitor`. ### Method GET ### Endpoint /info ``` -------------------------------- ### Sample Info Response Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/info.md This is a sample JSON response for the /info endpoint, detailing the dotnet monitor version, runtime version, and enabled capabilities. ```json { "version": "6.0.0", "runtimeVersion": "6.0.0", "diagnosticPortMode": "Connect", "diagnosticPortName": null, "capabilities": [{"name":"exceptions","enabled":true},{"name":"parameters","enabled":true},{"name":"call_stacks","enabled":true},{"name":"metrics","enabled":true},{"name":"http_egress","enabled":true}] } ``` -------------------------------- ### CPU Usage Trigger Shortcut Example (Kubernetes Environment Variables) Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/collectionrules/triggershortcuts.md This configuration uses Kubernetes environment variables to implement the CPUUsage trigger shortcut. It provides a concise way to monitor CPU usage. ```yaml - name: DotnetMonitor_CollectionRules__RuleName__Trigger__Type value: "CPUUsage" ``` -------------------------------- ### Response with multiple exceptions Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/exceptions-custom.md Example response showing multiple exceptions, each with its own details. ```http HTTP/1.1 200 OK Content-Type: text/plain First chance exception at 2023-08-08T14:50:34.1039177Z System.InvalidOperationException: There was an invalid operation! at MyApp.MyClass.MyExceptionMethod1() at MyApp.MyClass.CallingMethod(System.String) at MyApp.MyClass.Main(System.String[]) First chance exception at 2023-08-08T14:50:34.1039177Z System.DivideByZeroException: You tried to divide by zero! at MyApp.MyClass.MyExceptionMethod2() at MyApp.MyClass.CallingMethod(System.String) at MyApp.MyClass.Main(System.String[]) ``` -------------------------------- ### /collectionrules Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/README.md Gets the current state of collection rules. This endpoint was introduced in version 6.3. ```APIDOC ## GET /collectionrules ### Description Gets the current state of collection rules. ### Method GET ### Endpoint /collectionrules ``` -------------------------------- ### Configure Live Metrics Collection Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/collection-rule-configuration.md Configure collection rules to gather live metrics for a process. This example shows collecting with default providers for a set duration and egressing the output. The 'Egress' property is required. ```json { "Egress": "TmpDir" } ``` ```yaml CollectionRules__RuleName__Actions__0__Settings__Egress: "TmpDir" ``` ```yaml - name: DotnetMonitor_CollectionRules__RuleName__Actions__0__Settings__Egress value: "TmpDir" ``` -------------------------------- ### Sample Request for Parameter Capture Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/parameters.md This sample demonstrates a POST request to the /parameters endpoint. It includes query parameters, authorization, accept header, and a JSON body specifying the methods to capture and a capture limit. ```http POST /parameters?pid=21632&durationSeconds=60 HTTP/1.1 Host: localhost:52323 Authorization: Bearer fffffffffffffffffffffffffffffffffffffffffff= Accept: application/x-ndjson { "methods": [ { "moduleName": "SampleWebApp.dll", "typeName": "SampleWebApp.Controllers.HomeController", "methodName": "Index" }, { "moduleName": "System.Private.CoreLib.dll", "typeName": "System.String", "methodName": "Concat" } ], "captureLimit": 2 } ``` -------------------------------- ### /processes Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/README.md Gets detailed information about discoverable processes. This endpoint was introduced in version 6.0. ```APIDOC ## GET /processes ### Description Gets detailed information about discoverable processes. ### Method GET ### Endpoint /processes ``` -------------------------------- ### /operations Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/README.md Gets egress operation status or cancels operations. This endpoint was introduced in version 6.0. ```APIDOC ## GET /operations ### Description Gets egress operation status or cancels operations. ### Method GET ### Endpoint /operations ``` -------------------------------- ### Match MyApp.dll Entry Point (Shorthand Kubernetes Environment Variables) Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/configuration/default-process-configuration.md Set environment variables in Kubernetes for shorthand configuration of the default process filter by 'ManagedEntryPointAssemblyName'. ```yaml - name: DotnetMonitor_DefaultProcess__Filters__0__ManagedEntryPointAssemblyName value: "MyApp" ``` -------------------------------- ### Get Trace Source: https://github.com/dotnet/dotnet-monitor/blob/main/documentation/api/trace.md Captures a diagnostic trace of a process based on a predefined set of trace profiles. ```APIDOC ## Get Trace ### Description Captures a diagnostic trace of a process based on a predefined set of trace profiles. ### Method GET ### Endpoint /api/trace ### Parameters #### Query Parameters - **profile** (string) - Required - The predefined trace profile to use (e.g., 'cpu-sampling', 'metrics'). - **duration-seconds** (integer) - Optional - The duration in seconds to capture the trace. ### Response #### Success Response (200) - **application/octet-stream** - The diagnostic trace in .nettrace format. ```