Location>code7788 >text

NET open source real-time monitoring system - WatchDog

Popularity:930 ℃/2024-08-27 11:22:10

preamble

As our system applications continue to iterate and become more complex during normal development, real-time monitoring of the application becomes more and more important. Real-time monitoring can not only help us quickly locate problems, but also take timely action when problems occur, reducing business interruption time.

NET open source real-time application monitoring system called WatchDog will be introduced in this article .

Projects

WatchDog is an open source (MIT License), free real-time application monitoring system designed for Core Web applications and APIs. We can log and view messages, events, HTTP requests and responses in your application in real time, as well as exceptions caught at runtime.

An efficient monitoring system not only improves the availability and reliability of the application , but also helps us to solve problems faster.WatchDog is an open source real-time application monitoring system designed for .NET applications , which provides a series of powerful features to help us monitor the status and performance of the application .

Functional Features

  • Real-time logging: The ability to log HTTP requests, responses, and runtime-caught exceptions in real time.
  • In-code logging: Support for logging messages and events in code.
  • Log View View: Provides an easy-to-use log viewing interface.
  • Log Search Function: Support for searching HTTP request and exception logs.
  • HTTP Log Filtering: HTTP logs can be filtered by HTTP method and status code.
  • Log View Authentication: Provides access control to the log view.
  • Automatic log cleaning: Supports automatic clearing of old log records.
  • Alarm notification: Supports sending alarm notifications via email, SMS and other methods to ensure that feedback can be received in a timely manner.
  • Flexible Configuration: It can be flexibly configured according to the application requirements and adapted to different monitoring needs.
  • Easy to integrateNET applications through simple API calls.

Project Technology Stack

  • back endNET Core or .NET 5 and above.
  • forward part of sth.: User interfaces built with front-end frameworks like React or Angular.
  • comprehensive database: Supports relational databases such as MySQL, PostgreSQL, and NoSQL databases such as MongoDB.
  • Official support for .NET 8NET 8: Added official support for .
  • Output Cache Support in .NET 8NET 8: Added support for using Output Cache in .
  • Using Regular Expression Blacklists: Added the ability to use regular expressions for blacklist filtering.

Working Principle

WatchDog implements real-time monitoring using SignalR and uses LiteDb as a MongoDB-like server-side database that requires no configuration, and also supports the use of external databases (e.g. MSSQL, MySQL, PostgreSQL, MongoDB).

1、NET version support

NET Core 3.1 and higher.

2、Download the source code

By downloading the source code, you can learn and apply it as shown below:

Installation and Configuration

1、WatchDog Installation

look for sth.The NuGet package is installed as shown below:

2、WatchDog service registration

In the Core Web API'smaybeRegister the WatchDog service in the

Logging from ILogger to WatchDog

It's also possible to convert the data from the .ILoggerlogging to WatchDog.

For .NET 6 and above

(opt =>  
{  
     = true;  
     = ;  
     = ;  
     = "mongodb://localhost:27017";  
});  
();  

For .NET Core 3.1

exist classCreateHostBuilder method to configure logging and add.AddWatchDogLogger()

(args)
 .ConfigureLogging( logging =>
 {
     ();
 })
 .ConfigureWebHostDefaults(webBuilder =>
 {
     <Startup>();
 });

3. Add an exception logger

Add the exception logger before the main WatchDog middleware, preferably placing it at the top of the middleware to catch possible early exceptions.

();

...

(opt => 
{ 
    = "admin"; 
    = "Qwerty@123"; 
   ...
 });

4. Setting up automatic log clearing (optional)

This feature automatically clears the log after a specific period of time.

take note of(coll.) ding dongIsAutoClearset totrueWhen the default purge schedule time is weekly.

To override the default settings, configure them as follows:

(opt => 
{ 
    = true;
    = ;
});

5. Setting up logging to an external database (optional)

Logging to a database such as SQL Server (MSSQL), MySQL, PostgreSQL or MongoDB can be configured as required.

  • Adding a database connection string: Provides the connection string for the database.
  • Selecting Database Driver Options: Select the appropriate driver based on the type of database being used.
(opt => 
{
    = true; 
    = "Server=localhost;Database=testDb;
   User Id=postgres;Password=root;"; 
    = ; 
});

6、Set the account password for accessing the log

(opt => 
{ 
    = "admin"; 
    = "Qwerty@123"; 
 });

Note: If your project uses permissions validation, the(); It should be in(), (), and() Add them in order after that.

7. Configuration notes and examples

  • blacklists: A list of routes, paths, or endpoints to ignore (should be a comma-separated string, as shown below).
  • serializer: Specify the type if the default global JSON serializer/converter is not used.
  • CORS strategy: If the project uses cross-origin resource sharing (CORS), specify the policy name.
  • Using the Output Cache: If the project uses Output caching. Function is only available for .NET 8 and above.
  • Using Regular Expression Blacklists: Enable the use of regular expressions to blacklist request routes, paths, or endpoints.

Sample Configuration

(opt => 
{ 
    = "admin"; 
    = "Qwerty@123"; 
   //Optional
    = "Test/testPost, api/auth/login"; 
   //Prevent logging for specified endpoints
    = ; 
   //If your project use a global json converter
    = "MyCorsPolicy";
    = true;
    = true;
 });

8. Record messages/events

("...Test Log...");
((model));
(, eventId: reference);

9, view logs and exceptions

Start the server and access/watchdog to view the log.

typical example

https:///watchdog
https://localhost:[your-port]/watchdog

Project Effect

1. WatchDog Login

2. WatchDog Log

3. Request log

4. Messages/events

Project Address

Github:/IzyPro/WatchDog

summarize

WatchDog is a powerful and easy to use open source real-time application monitoring system for . By using WatchDog, we can easily realize the real-time monitoring of .NET applications to improve the stability and reliability of the application . Hope this article can help you better understand and use WatchDog.

ultimate

If you found this article helpful, why not support it with a like? Your support is what keeps me motivated to continue sharing my knowledge. Feel free to leave a comment if you have any questions or need further help.

You can also join WeChat[DotNet Technician] community to share ideas and grow with other tech-loving peers!