Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is dotnet monitor in .NET 6?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "what is dotnet monitor in .NET 6". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is dotnet monitor in .NET 6"?

one。 What is dotnet monitor?

Running .NET applications in different environments may make it difficult to collect diagnostic information (such as logs, traces, dump). Dotnet monitor is a tool that provides a unified way to collect these diagnostics, regardless of whether you are running on a desktop computer (desktop machine can be understood as our everyday computer) or in an kubernetes cluster.

There are two different mechanisms for collecting this diagnostic information:

HTTP API that collects diagnostic information as needed. You can call these HTTP API when your application encounters problems and wants to gather more information.

Triggers configured based on rules. You can configure rules to collect diagnostics when the required conditions are met, such as collecting process dumps (process dump) when CPU remains high for a period of time.

two。 Introduction

Dotnet monitor can be obtained through two different distribution mechanisms:

.net CLI tools

Container image obtained through Microsoft Container Registry (MCR)

.net CLI tools

The dotnet monitor CLI tool first needs to install .NET 6 SDK. If you don't have enough new SDK, you can get the installation package from the .NET download page to install it.

You can use the following command to get the latest version of dotnet monitor:

Dotnet tool install-g dotnet-monitor-- version 6.0.0

If you have already installed but want to update to the latest, you can run the following command:

Dotnet tool update-g dotnet-monitor-- version 6.0.0

Container image

Dotnet monitor container images are available on MCR. You can obtain the latest images by using the following command:

Docker pull mcr.microsoft.com/dotnet/monitor:6.0.0

III. HTTP API

Dotnet monitor exposes a HTTP API to query available processes, collect diagnostics, and check the status of the request information.

The following HTTP API is exposed:

/ processes- gets the details of the processes that can be discovered

/ dump- captures the process's dump without using the debugger

/ gcdump- captures the process's GC dump

/ trace- does not use profiler to track progress

/ metrics- takes a snapshot of the metrics of the default process in Prometheus exposition format

/ livemetrics- captures the real-time metrics stream of the process

/ logs- captures the log of the process

/ info- to get information about dotnet monitor

/ operations- gets the operation status and cancels the operation

The following example shows how to use dotnet monitor to start with the target process and log stream data from the Microsoft.AspNetCore.Server.Kestrel.Connections log level to Debug in 60 seconds.

PS > curl.exe-X POST "https://localhost:52323/logs?name=myWebApp&durationSeconds=60" `

-H "Accept: application/x-ndjson" `

-H "Content-Type: application/json" `

-- negotiate-u $(whoami) `

-d'{"filterSpecs": {"Microsoft.AspNetCore.Server.Kestrel.Connections": "Debug"}'

{"Timestamp": "2021-11-05 08Debug", "EventId": 39, "EventName": "ConnectionAccepted", "Category": "Microsoft.AspNetCore.Server.Kestrel.Connections", "Message": "Connection id u00220HMD06BUKL2CUu0022 accepted.", "State": {"Message": "Connection id u00220HMD06BUKL2CUu0022 accepted.", "ConnectionId": "0HMD06BUKL2CU", "{OriginalFormat}": "Connection id u0022 {ConnectionId} u0022 accepted."}

{"Timestamp": "2021-11-05 08Debug", "EventId": 1, "EventName": "ConnectionStart", "Category": "Microsoft.AspNetCore.Server.Kestrel.Connections", "Message": "Connection id u00220HMD06BUKL2CUu0022 started.", "State": {"Message": "Connection id u00220HMD06BUKL2CUu0022 started.", "ConnectionId": "0HMD06BUKL2CU", "{OriginalFormat}": "Connection id u0022 {ConnectionId} u0022 started."}

{"Timestamp": "2021-11-05 08Debug", "EventId": 9, "EventName": "ConnectionKeepAlive", "Category": "Microsoft.AspNetCore.Server.Kestrel.Connections", "Message": "Connection id u00220HMD06BUKL2CUu0022 completed keep alive response.", "State": {"Message": "Connection id u00220HMD06BUKL2CUu0022 completed keep alive response.", "ConnectionId": "0HMD06BUKL2CU", "{OriginalFormat}": "Connection id u0022 {ConnectionId} u0022 completed keep alive response." "Scopes": [{"ConnectionId": "0HMD06BUKL2CU"}, {"RequestId": "0HMD06BUKL2CU:00000002", "RequestPath": "/"}]}

As shown in the example above, you can use dotnet monitor to capture diagnostics on demand from the target process. In addition to logging, you can also collect traces, memory dumps, GC dumps, and metrics from the target process.

four。 Trigger

Dotnet monitor can be configured to automatically collect diagnostics based on conditions in the discovered process. When a new process is found, if the process data matches the rule, dotnet monitor attempts to apply the configured rule. The applied rule begins the process of monitoring the conditions described by the trigger. If this condition is met, it is assumed that the specified limit has not been reached to execute the action list.

Example: if dotnet monitor detects that CPU usage that lasts for more than one minute is more than 80%, it collects process dump and limits it to no more than 1 per hour.

{"CollectionRules": {"HighCpuRule": {"Filters": [{"Key": "ProcessName", "Value": "MyApp", "MatchType": "Exact"}], "Trigger": {"Type": "EventCounter", "Settings": {"ProviderName": "System.Runtime" "CounterName": "cpu-usage", "GreaterThan": 80, "SlidingWindowDuration": "00:01:00"}, "Limits": {"ActionCount": 1, "ActionCountSlidingWindowDuration": "1:00:00"}, "Actions": [{"Type": "CollectDump" "Settings": {"Type": "Triage", "Egress": "myBlobStorageAccount"} so far I believe you have a deeper understanding of "what is dotnet monitor in .NET 6", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report