# WinSupervisor
**Repository Path**: 51diysoft/WinSupervisor
## Basic Information
- **Project Name**: WinSupervisor
- **Description**: WinSupervisor是一款针对windows的守护进程监测程,防止进程掉线、中断等,并通过邮件、短信、钉钉等实现告警信息发送通知,提升平台运行稳定性;
主要功能:
1、进程异常后主动尝试重启进程 ;
2、进程异常后写入到指定的日志 /数据库等,支持mysql和sqlserver ;
3、邮件、短信、钉钉等实现告警信息发送通知;4、进程异常后打开新的程序等
- **Primary Language**: C#
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 1
- **Created**: 2025-10-30
- **Last Updated**: 2026-02-09
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# WinSupervisor Process Guardian
## Project Introduction
WinSupervisor is a professional Windows process guardian application designed to monitor the running status of critical processes and ensure their continuous stable operation. When a monitored process terminates abnormally, the system automatically attempts to restart it and sends alert notifications through multiple channels, greatly improving system stability and reliability.
## Core Features
### 1. Process Monitoring and Automatic Recovery
- Real-time monitoring of specified Windows processes' running status
- Automatic restart attempts when processes terminate abnormally
- Support for configuring maximum restart count limits to avoid infinite restart loops
- Support for setting restart interval times to optimize process startup strategies
### 2. Multi-channel Alert Notifications
- **Email Alerts**: Send email notifications via SMTP servers
- **SMS Alerts**: Support for configuring SMS APIs to send alert messages
- **DingTalk Alerts**: Send messages through DingTalk robots, supporting @ specific personnel or all members
### 3. Comprehensive Logging
- Detailed logging using NLog
- Records of process status changes, restart attempts, and alert sending status
- Support for recording process status information to databases (MySQL/SQL Server)
### 4. Flexible Configuration Management
- Manage monitored process lists through independent JSON configuration files
- Support for setting process paths, startup parameters, automatic restart strategies, etc. in the configuration
- Customizable monitoring interval times
## Technical Architecture
### Technology Stack
- **Development Language**: C#
- **Runtime Environment**: .NET Framework
- **Logging Framework**: NLog
- **JSON Processing**: Newtonsoft.Json
- **Data Access**: SqlSugar (supports MySQL and SQL Server)
- **Deployment Form**: Windows Service
### Core Classes and Functional Modules
1. **Service1**: Main Windows service class, responsible for service lifecycle management and scheduled task scheduling
2. **ProcessInfoDto**: Process information data transfer object, defines the various configurations required for process monitoring
3. **ConfigHelper**: Configuration management helper class for reading application configuration
4. **DingTalkRobot**: DingTalk robot communication class that implements DingTalk message sending functionality
## Installation and Deployment
### Environment Requirements
- Windows operating system
- .NET Framework (according to project compilation version requirements)
### Installation Steps
1. **Compile the Project**
- Open the `WinSupervisor守护进程服务.sln` solution using Visual Studio
- Compile to generate a Release version of the executable file
2. **Install the Windows Service**
- Run Command Prompt as administrator
- Execute the installation command:
```
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe [output directory]\Yywl.CqytSvc.exe
```
- Or directly run the `install安装服务命令.bat` file in the project (you need to modify the path in the script first)
3. **Start the Service**
- Find "WinSupervisor守护进程服务" in Windows Service Manager
- Right-click and select "Start"
4. **Verify Service Operation Status**
- Check if the service is running normally
- View log files to confirm that monitoring tasks have started execution
### Uninstall the Service
- Run Command Prompt as administrator
- Execute the uninstallation command:
```
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /u [output directory]\Yywl.CqytSvc.exe
```
## Configuration Instructions
### 1. Process Configuration (ProcessConfig.json)
The service reads monitoring process configuration from the `ProcessConfig.json` file in the application directory at startup. The configuration format is as follows:
```json
[
{
"ProcessName": "nginx.exe",
"ProcessPath": "C:\\iis_web\\nginx-1.22.1\\runNginx.bat",
"AutoRestart": true,
"StartArguments": "",
"MaxRestartCount": 0,
"RestartIntervalMs": 0
},
{
"ProcessName": "QQ.exe",
"ProcessPath": "C:\\Program Files\\Tencent\\QQ\\Bin\\QQ.exe",
"AutoRestart": true,
"StartArguments": "",
"MaxRestartCount": 5,
"RestartIntervalMs": 10000
}
]
```
Configuration item descriptions:
- `ProcessName`: Process name (without .exe suffix)
- `ProcessPath`: Complete path to the process executable file
- `AutoRestart`: Whether to automatically restart (true/false)
- `StartArguments`: Startup parameters
- `MaxRestartCount`: Maximum restart count limit (0 means no limit)
- `RestartIntervalMs`: Restart interval time (milliseconds)
### 2. Application Configuration (App.config)
Other system configurations are managed through the application configuration file, mainly including:
#### Monitoring Settings
```xml
```
#### Email Alert Configuration
```xml
```
#### SMS Alert Configuration
```xml
```
#### DingTalk Alert Configuration
```xml
```
## Usage Examples
### Monitoring Web Server Processes
For example, monitoring an Nginx server process:
1. Add configuration in `ProcessConfig.json`:
```json
{
"ProcessName": "nginx",
"ProcessPath": "C:\\nginx\\nginx.exe",
"AutoRestart": true,
"StartArguments": "",
"MaxRestartCount": 3,
"RestartIntervalMs": 5000
}
```
2. Configure email alerts:
Set `EnableEmailAlert` to `true` and configure SMTP server information.
3. Restart the service for configuration to take effect
### Advanced Configuration Example
For applications that require special startup parameters:
```json
{
"ProcessName": "myapp",
"ProcessPath": "C:\\Apps\\MyApp\\MyApp.exe",
"AutoRestart": true,
"StartArguments": "--config=app.config --port=8080",
"MaxRestartCount": 0,
"RestartIntervalMs": 0
}
```
## Log Viewing
The service generates log files in the `logs` folder under the application directory. You can view:
- Service operation status
- Process monitoring records
- Alert sending status
- Error information
## Common Issues
### 1. Service Cannot Start
- Check if you ran the installation command as administrator
- Confirm .NET Framework version compatibility
- View Windows Event Log for detailed error information
### 2. Process Cannot Auto-restart
- Check if `ProcessPath` is correct
- Confirm if the service account has sufficient permissions to start the process
- Check if `AutoRestart` configuration is set to `true`
### 3. Alert Notifications Not Received
- Verify if alert functions are enabled (`EnableEmailAlert` and other settings)
- Check if alert server configurations are correct
- View alert sending records and error information in log files
## Notes
1. After first installation, ensure that the `ProcessConfig.json` file exists and has the correct format
2. Sensitive information (such as SMTP passwords, DingTalk Webhook addresses) should be properly protected
3. It is recommended to regularly check log files to ensure the service is running normally
4. For critical systems, it is recommended to configure multiple alert methods to improve reliability
## License
[Add license information here]
## Contact Information
For questions or suggestions, please contact: [Author/Team contact information]