A production-ready process monitoring and management tool built with .NET 9, featuring enterprise-grade security, comprehensive error handling, and robust scheduling capabilities.
Process Monitor is a sophisticated utility that automates process lifecycle management with features including:
- Scheduled process execution
- Continuous process monitoring
- Automatic process restart with retry logic
- Configuration hot-reload
- Comprehensive logging with Serilog
- Security validation and path whitelisting
- Performance monitoring
- Docker support
- Health checks
- Flexible Process Management: Start processes at specific times, run continuously, or schedule at intervals
- Retry Logic: Automatic retry with exponential backoff on process failures
- Concurrent Execution Control: Limit simultaneous process starts
- Process Count Management: Ensure specific number of instances are always running
- Path Validation: Whitelist-based executable path validation
- Argument Sanitization: Protection against command injection
- Digital Signature Verification: Optional executable signature checking
- Non-root Execution: Docker container runs as non-privileged user
- Structured Logging: Serilog with file and console sinks
- Performance Monitoring: CPU and memory usage tracking
- Health Checks: Configuration, process manager, and disk space checks
- Log Rotation: Automatic daily log rotation with retention
- Hot Reload: Automatic configuration reload on file changes
- Environment Variables: Override settings via environment variables
- JSON Schema Validation: Strongly-typed configuration with validation
- .NET 9.0 Runtime or SDK
- Windows, Linux, or macOS
- Docker (optional, for containerized deployment)
git clone https://github.com/MarketAlly/Process-Monitor.git
cd Process-Monitor
dotnet restore
dotnet build -c Releasedocker build -t marketally/processmonitor:latest .{
"ProcessMonitor": {
"MonitoringIntervalSeconds": 10,
"EnableDebugLogging": false,
"LogRetentionDays": 30,
"AllowedPaths": [
"C:\\Windows\\System32",
"C:\\Program Files"
],
"EnablePathValidation": true,
"EnablePerformanceMonitoring": true,
"MaxConcurrentStarts": 5
}
}{
"version": "1.0",
"processes": [
{
"name": "MyApp",
"path": "C:\\Program Files\\MyApp\\app.exe",
"count": 2,
"enable": true,
"interval": 30,
"time": "08:00",
"arguments": "--config production",
"workingDirectory": "C:\\Program Files\\MyApp",
"environmentVariables": {
"NODE_ENV": "production"
},
"maxRetries": 3,
"retryDelaySeconds": 5
}
]
}# Run with default configuration
dotnet MarketAlly.ProcessMonitor.dll
# Run with custom environment
dotnet MarketAlly.ProcessMonitor.dll --environment Production
# Override configuration via environment variables
ProcessMonitor__MonitoringIntervalSeconds=30 dotnet MarketAlly.ProcessMonitor.dll# Using docker-compose
docker-compose up -d
# Using docker run
docker run -d \
--name process-monitor \
-v $(pwd)/processlist.json:/app/processlist.json:ro \
-v $(pwd)/logs:/app/logs \
marketally/processmonitor:latest| Property | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Process identifier |
| path | string | Yes | Absolute path to executable |
| count | int | No | Number of instances to maintain (0-100) |
| enable | bool | Yes | Enable/disable monitoring |
| time | string | No | Start time in HH:mm format |
| interval | int | No | Repeat interval in minutes |
| arguments | string | No | Command line arguments |
| workingDirectory | string | No | Working directory path |
| environmentVariables | object | No | Environment variables |
| maxRetries | int | No | Maximum retry attempts (default: 3) |
| retryDelaySeconds | int | No | Delay between retries (default: 5) |
The application follows SOLID principles with a clean architecture:
├── Interfaces/ # Service contracts
├── Services/ # Service implementations
├── Models/ # Data models
├── Configuration/ # Configuration handling
├── Validators/ # Security and validation
├── Extensions/ # Extension methods
├── Exceptions/ # Custom exceptions
└── Tests/ # Unit and integration tests
- ProcessManager: Handles process lifecycle with retry logic
- ProcessScheduler: Manages scheduled tasks
- ConfigurationService: Hot-reload configuration management
- ProcessValidator: Security validation
- ProcessMonitorService: Main background service
- PerformanceMonitoringService: System metrics collection
# Run all tests
dotnet test
# Run with coverage
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
# Run specific test category
dotnet test --filter Category=Unit- ✅ Update
appsettings.Production.jsonwith production values - ✅ Configure allowed paths for your environment
- ✅ Set appropriate log retention period
- ✅ Enable performance monitoring if needed
- ✅ Configure health check endpoints
- ✅ Set up log aggregation (e.g., to Seq, ELK)
- ✅ Configure monitoring and alerting
- ✅ Review security settings
apiVersion: apps/v1
kind: Deployment
metadata:
name: process-monitor
spec:
replicas: 1
selector:
matchLabels:
app: process-monitor
template:
metadata:
labels:
app: process-monitor
spec:
containers:
- name: process-monitor
image: marketally/processmonitor:latest
volumeMounts:
- name: config
mountPath: /app/processlist.json
subPath: processlist.json
- name: logs
mountPath: /app/logs
volumes:
- name: config
configMap:
name: process-config
- name: logs
persistentVolumeClaim:
claimName: process-monitor-logs/health/ready- Readiness probe/health/live- Liveness probe
- Process count by name
- CPU and memory usage
- Scheduled task execution
- Error rates and retry counts
Logs are written to:
- Console (structured JSON in production)
- File:
logs/processmonitor-YYYYMMDD.log
- Path Whitelisting: Only executables in allowed paths can be started
- Argument Validation: Protection against shell injection
- File Permissions: Ensure proper permissions on configuration files
- Secrets Management: Use environment variables or secret stores for sensitive data
- Network Isolation: Run in isolated network when possible
Process fails to start
- Check path validation and whitelist
- Verify file permissions
- Check logs for detailed error messages
Configuration not reloading
- Ensure file watcher has permissions
- Check for file lock issues
- Verify JSON syntax
High memory usage
- Enable performance monitoring
- Check for process leaks
- Review retry settings
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE.txt file for details.
For issues and feature requests, please use the GitHub issue tracker.