Update README and installation scripts for Resource Monitor Service v2.1, enhancing web dashboard features and adjusting firewall configurations.

This commit is contained in:
Phoenix
2025-08-07 23:10:40 +08:00
parent 3d47fc1439
commit 96b6e3dcd9
4 changed files with 380 additions and 192 deletions
+160 -88
View File
@@ -1,9 +1,33 @@
# Resource Monitor Service for Unraid VM # Resource Monitor Service
A comprehensive system monitoring service specifically designed for Windows VMs running on Unraid servers. This service provides real-time monitoring of CPU, memory, GPU, disk, network, and system resources through a RESTful API. A comprehensive system monitoring service with a modern web dashboard for real-time resource monitoring. Originally designed for Windows VMs running on Unraid servers, now featuring a responsive web interface for easy monitoring and management.
## 🌟 New: Web Dashboard
Access the interactive web dashboard at `http://localhost:5000` featuring:
- **Real-time Monitoring**: Live updates every 15 seconds via SignalR
- **Responsive Design**: Mobile-friendly interface built with Tailwind CSS
- **Interactive Controls**: Toggle auto-refresh, show/hide sections, manual refresh
- **Game Detection**: Prominent game monitoring with process termination
- **Process Management**: View and terminate top processes
- **System Details**: Comprehensive system information and disk usage
- **Performance Charts**: Historical CPU and memory usage graphs
- **API Documentation**: Built-in Swagger/OpenAPI interface at `/swagger`
## 🚀 Features ## 🚀 Features
### Web Dashboard
- **Modern Interface**: Clean, responsive design with dark/light themes
- **Real-time Updates**: SignalR-powered live data updates
- **Auto-refresh Control**: Toggle between automatic and manual refresh modes
- **Game Detection Section**: Monitor running games with termination capability
- **Process Management**: View top processes with one-click termination
- **System Information**: Detailed hardware and software information
- **Disk Usage Visualization**: Visual disk space utilization
- **Performance Charts**: Historical data visualization with Chart.js
- **Mobile Responsive**: Works seamlessly on phones, tablets, and desktop
### Core Monitoring ### Core Monitoring
- **CPU Monitoring**: Per-core usage, frequency, temperature, and throttling detection - **CPU Monitoring**: Per-core usage, frequency, temperature, and throttling detection
- **Memory Monitoring**: RAM usage, available memory, committed memory, and paging - **Memory Monitoring**: RAM usage, available memory, committed memory, and paging
@@ -29,23 +53,30 @@ A comprehensive system monitoring service specifically designed for Windows VMs
## 📡 API Endpoints ## 📡 API Endpoints
The service runs on `http://localhost:5000` by default and provides the following endpoints: The service runs a web server on `http://localhost:5000` providing:
### Web Interface
- `GET /` - **Main Dashboard** - Interactive web interface for monitoring
- `GET /swagger` - **API Documentation** - Interactive API explorer and documentation
### REST API
All API endpoints are available at `http://localhost:5000/api/[endpoint]`:
### System Information ### System Information
- `GET /api/system-info` - Complete system information including VM details - `GET /api/resource/usage` - **Complete resource overview** - All monitoring data in one call
- `GET /api/vm/info` - VM-specific information (hypervisor, uptime, etc.) - `GET /api/resource/system-info` - Complete system information including VM details
- `GET /api/health` - Service health status and monitoring capabilities - `GET /api/resource/cpu` - Detailed CPU metrics with per-core data
- `GET /api/metrics` - Service metrics and performance overview - `GET /api/resource/memory` - Memory utilization and statistics
- `GET /api/config` - Current configuration settings - `GET /api/resource/gpu` - NVIDIA GPU usage, memory, temperature, fan speed, and power consumption
- `GET /api/resource/disks` - Disk I/O and space usage for all drives
- `GET /api/resource/network` - Network interface statistics
- `GET /api/resource/processes?count=10` - Top processes by CPU/memory usage with percentage data
### Resource Monitoring ### Process Management
- `GET /api/resource-usage` - Complete resource usage overview - `POST /api/resource/kill-process/{processId}` - **Terminate Process** - End any process by ID
- `GET /api/cpu-usage` - Detailed CPU metrics with per-core data
- `GET /api/memory-usage` - Memory utilization and statistics ### Real-time Updates
- `GET /api/gpu-usage` - NVIDIA GPU usage, memory, temperature, fan speed, and power consumption - **SignalR Hub**: `/resourceHub` - Real-time data updates every 15 seconds
- `GET /api/disk-usage` - Disk I/O and space usage for all drives
- `GET /api/network-usage` - Network interface statistics
- `GET /api/top-processes?count=10` - Top processes by CPU/memory usage with percentage data
### Game Detection ### Game Detection
- `GET /api/current-game` - Currently running game information - `GET /api/current-game` - Currently running game information
@@ -76,25 +107,97 @@ The service runs on `http://localhost:5000` by default and provides the followin
## 🛠️ Installation & Usage ## 🛠️ Installation & Usage
### Option 1: Console Application (Development/Testing) ### Option 1: Web Dashboard (Recommended)
```powershell ```powershell
cd C:\Work\DEV\ResourceUsageAPI cd C:\Work\DEV\ResourceUsageAPI
dotnet run --configuration Release dotnet run --configuration Release
``` ```
Then open your browser to `http://localhost:5000` for the interactive dashboard.
### Option 2: Windows Service (Production) ### Option 2: Windows Service (Production)
```powershell ```powershell
# Run as Administrator # Run as Administrator
cd C:\Work\DEV\ResourceUsageAPI\publish cd C:\Work\DEV\ResourceUsageAPI
.\install-service.bat .\install-service.ps1
``` ```
### Option 3: Standalone Executable ### Option 3: Linux Service (if running on Linux)
```bash
cd /path/to/ResourceUsageAPI
chmod +x install-service.sh
sudo ./install-service.sh
```
### Option 4: Standalone Executable
```powershell ```powershell
cd C:\Work\DEV\ResourceUsageAPI\publish cd C:\Work\DEV\ResourceUsageAPI
dotnet build --configuration Release
dotnet publish --configuration Release
cd bin\Release\net9.0-windows\publish
.\ResourceMonitorService.exe .\ResourceMonitorService.exe
``` ```
## 🎮 Web Dashboard Features
### Dashboard Overview
- **Resource Cards**: CPU, Memory, GPU, and Network usage with visual progress bars
- **Game Detection**: Prominent section showing currently running games
- **Auto-refresh Toggle**: Control automatic updates (15-second intervals)
- **Manual Refresh**: Force immediate data updates
- **Responsive Design**: Works on desktop, tablet, and mobile devices
### Interactive Sections
- **Processes**: View and terminate top CPU/memory consuming processes
- **Details**: System information, disk usage, and performance charts
- **Game Management**: Monitor and terminate running games
- **Real-time Charts**: Historical CPU and memory usage visualization
### Controls
- **Auto: ON/OFF** - Toggle automatic data updates
- **Processes** - Show/hide process management table
- **Details** - Show/hide system information and charts
- **Refresh** - Manually update all data immediately
## 📊 Service Management
### Starting and Stopping the Service
```powershell
# Start the service
Start-Service "ResourceMonitorService"
# Stop the service
Stop-Service "ResourceMonitorService"
# Get service status
Get-Service "ResourceMonitorService"
# Restart the service
Restart-Service "ResourceMonitorService"
```
### Development Mode
For development and testing:
```powershell
# Run in development mode with hot reload
dotnet run --environment Development
# Access the dashboard at http://localhost:5000
# Access Swagger API documentation at http://localhost:5000/swagger
```
### Troubleshooting
- **Service won't start**: Check the logs in the `logs/` directory
- **No GPU data**: Make sure you have an NVIDIA GPU and drivers installed
- **High CPU usage**: Adjust monitoring intervals in `appsettings.json`
- **Web dashboard not accessible**: Verify firewall settings and ensure port 5000 is available
- **Game detection issues**: Check if games are running from standard installation directories
- **API errors**: Verify endpoints using Swagger documentation at `/swagger`
- **Performance issues**: Consider increasing `UpdateIntervalMs` in configuration
## ⚙️ Configuration ## ⚙️ Configuration
Configuration is managed through `appsettings.json`: Configuration is managed through `appsettings.json`:
@@ -102,7 +205,7 @@ Configuration is managed through `appsettings.json`:
```json ```json
{ {
"MonitoringSettings": { "MonitoringSettings": {
"UpdateIntervalMs": 5000, "UpdateIntervalMs": 15000,
"EnableGpuMonitoring": true, "EnableGpuMonitoring": true,
"EnableDiskMonitoring": true, "EnableDiskMonitoring": true,
"EnableNetworkMonitoring": true, "EnableNetworkMonitoring": true,
@@ -123,18 +226,15 @@ Configuration is managed through `appsettings.json`:
"E:\\Games" "E:\\Games"
] ]
}, },
"AlertThresholds": { "Kestrel": {
"CpuUsageThreshold": 80.0, "Endpoints": {
"MemoryUsageThreshold": 85.0, "Http": {
"GpuUsageThreshold": 90.0, "Url": "http://localhost:5000"
"DiskUsageThreshold": 90.0,
"TemperatureThreshold": 80.0,
"AlertDurationSeconds": 30
}, },
"ApiSettings": { "Https": {
"RequireApiKey": false, "Url": "https://localhost:5001"
"AllowedOrigins": ["http://localhost:4200", "http://unraid:4200"], }
"BasePath": "/api" }
} }
} }
``` ```
@@ -331,68 +431,40 @@ The service supports real-time alert notifications via Telegram bot. To set up T
## 🔧 PowerShell Usage Examples ## 🔧 PowerShell Usage Examples
```powershell ```powershell
# Get system health # Access the web dashboard
$health = Invoke-RestMethod -Uri "http://localhost:5000/api/health" Start-Process "http://localhost:5000"
Write-Host "System Status: $($health.status)"
# Get CPU usage # Get complete resource overview
$cpu = Invoke-RestMethod -Uri "http://localhost:5000/api/cpu-usage" $resources = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/usage"
Write-Host "CPU Usage: $($cpu.usage)%" Write-Host "CPU: $($resources.cpu.usage.ToString('F1'))%"
Write-Host "Memory: $($resources.memory.usagePercentage.ToString('F1'))%"
Write-Host "GPU: $($resources.gpu.usage)%"
# Get GPU usage # Get system information
$gpu = Invoke-RestMethod -Uri "http://localhost:5000/api/gpu-usage" $systemInfo = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/system-info"
if ($gpu.isAvailable) { Write-Host "Machine: $($systemInfo.machineName)"
Write-Host "GPU: $($gpu.name)" Write-Host "OS: $($systemInfo.osVersion)"
Write-Host "GPU Usage: $($gpu.usage)%" Write-Host "CPU: $($systemInfo.cpuName)"
Write-Host "GPU Memory: $([math]::Round($gpu.memoryUsed / 1GB, 2))GB / $([math]::Round($gpu.memoryTotal / 1GB, 2))GB ($($gpu.memoryUsage)%)"
Write-Host "GPU Temperature: $($gpu.temperature)°C" # Get disk usage
} else { $disks = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/disks"
Write-Host "GPU not available: $($gpu.error)" foreach ($disk in $disks) {
$freeGB = [math]::Round($disk.freeSpace / 1GB, 1)
$totalGB = [math]::Round($disk.totalSize / 1GB, 1)
Write-Host "$($disk.driveLetter): $freeGB GB free of $totalGB GB"
} }
# Get current game (enhanced with root folder detection) # Get top processes
$game = Invoke-RestMethod -Uri "http://localhost:5000/api/current-game" $processes = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/processes?count=5"
if ($game) {
Write-Host "Currently playing: $($game.gameName)"
Write-Host "Platform: $($game.platform)"
Write-Host "Executable: $($game.executableName)"
if ($game.isFullscreen) {
Write-Host "Running in fullscreen mode"
}
} else {
Write-Host "No game currently detected"
}
# Get all detected games
$allGames = Invoke-RestMethod -Uri "http://localhost:5000/api/all-games"
Write-Host "Detected games on system:"
foreach ($gameItem in $allGames) {
Write-Host " $($gameItem.gameName) ($($gameItem.platform)) - Memory: $([math]::Round($gameItem.memoryUsage / 1MB, 0))MB"
}
# Get top processes by CPU usage
$processes = Invoke-RestMethod -Uri "http://localhost:5000/api/top-processes?count=5"
Write-Host "Top 5 processes by CPU usage:" Write-Host "Top 5 processes by CPU usage:"
foreach ($proc in $processes.value) { foreach ($proc in $processes) {
Write-Host " $($proc.name): $($proc.cpuUsage.ToString('F2'))% CPU, $($proc.memoryUsagePercentage.ToString('F2'))% Memory" if ($proc.cpuUsage) {
Write-Host " $($proc.name): $($proc.cpuUsage.ToString('F1'))% CPU"
}
} }
# Terminate a process (example - be careful!) # Terminate a process (example - be careful!)
$killRequest = @{ # Invoke-RestMethod -Uri "http://localhost:5000/api/resource/kill-process/1234" -Method Post
ProcessId = 1234
Force = $false
} | ConvertTo-Json
# Invoke-RestMethod -Uri "http://localhost:5000/api/process/kill" -Method Post -Body $killRequest -ContentType "application/json"
# Shutdown system with 60-second delay
$shutdownRequest = @{
Action = "shutdown"
DelaySeconds = 60
Message = "Scheduled maintenance shutdown"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:5000/api/system/shutdown" -Method Post -Body $shutdownRequest -ContentType "application/json"
``` ```
## 🚨 Known Warnings (Non-Critical) ## 🚨 Known Warnings (Non-Critical)
@@ -435,7 +507,7 @@ The service uses Serilog for structured logging:
## 📈 Performance ## 📈 Performance
- Lightweight background monitoring (5-second intervals by default) - Lightweight background monitoring (15-second intervals by default)
- Efficient memory usage with smart caching and cleanup of old process data - Efficient memory usage with smart caching and cleanup of old process data
- Non-blocking async operations - Non-blocking async operations
- Real-time CPU usage calculation for individual processes - Real-time CPU usage calculation for individual processes
+194
View File
@@ -0,0 +1,194 @@
#!/bin/bash
# Resource Monitor Service - Installation Script for Linux systemd service
SERVICE_NAME="resource-monitor"
SERVICE_DISPLAY_NAME="Resource Monitor Service v2.1"
SERVICE_DESCRIPTION="Monitors system resources with web dashboard"
INSTALL_PATH="/opt/resource-monitor"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
echo "=== Resource Monitor Service - Linux systemd Installer ==="
echo
# Check if running as root
if [[ $EUID -ne 0 ]]; then
echo "ERROR: This script must be run as root (use sudo)"
echo "Please run: sudo ./install-service-linux.sh"
exit 1
fi
# Function to uninstall service
uninstall_service() {
echo "Uninstalling Resource Monitor Service..."
# Stop the service
echo "Stopping service..."
systemctl stop $SERVICE_NAME 2>/dev/null
echo "Service stopped"
# Disable the service
echo "Disabling service..."
systemctl disable $SERVICE_NAME 2>/dev/null
echo "Service disabled"
# Remove service file
echo "Removing service file..."
rm -f $SERVICE_FILE
echo "Service file removed"
# Reload systemd
systemctl daemon-reload
# Optionally remove installation directory
read -p "Remove installation files from $INSTALL_PATH? (y/N): " removeFiles
if [[ "$removeFiles" == "y" || "$removeFiles" == "Y" ]]; then
rm -rf $INSTALL_PATH
echo "Installation files removed"
fi
echo "Uninstallation complete!"
exit 0
}
# Check for uninstall flag
if [[ "$1" == "--uninstall" || "$1" == "-u" ]]; then
uninstall_service
fi
echo "Installing Resource Monitor Service as systemd service..."
# Check if .NET is installed
if ! command -v dotnet &> /dev/null; then
echo "ERROR: .NET runtime is not installed"
echo "Please install .NET 8.0 or later runtime"
echo "See: https://docs.microsoft.com/en-us/dotnet/core/install/linux"
exit 1
fi
# Create installation directory
echo "Creating installation directory..."
mkdir -p "$INSTALL_PATH"
if [[ $? -ne 0 ]]; then
echo "ERROR: Failed to create installation directory"
exit 1
fi
echo "Installation directory created: $INSTALL_PATH"
# Build the service in release mode
echo "Building service..."
dotnet publish --configuration Release --output "$INSTALL_PATH"
if [[ $? -ne 0 ]]; then
echo "ERROR: Build failed"
exit 1
fi
echo "Service built successfully"
# Stop existing service if running
echo "Stopping existing service (if running)..."
systemctl stop $SERVICE_NAME 2>/dev/null || echo "No existing service found"
# Create systemd service file
echo "Creating systemd service file..."
cat > $SERVICE_FILE << EOF
[Unit]
Description=$SERVICE_DESCRIPTION
After=network.target
[Service]
Type=notify
ExecStart=/usr/bin/dotnet $INSTALL_PATH/ResourceMonitorService.dll
Restart=always
RestartSec=5
SyslogIdentifier=resource-monitor
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://localhost:5000
WorkingDirectory=$INSTALL_PATH
[Install]
WantedBy=multi-user.target
EOF
if [[ $? -ne 0 ]]; then
echo "ERROR: Failed to create service file"
exit 1
fi
echo "Service file created"
# Set proper permissions
chmod 644 $SERVICE_FILE
chown root:root $SERVICE_FILE
# Reload systemd
echo "Reloading systemd daemon..."
systemctl daemon-reload
# Enable the service
echo "Enabling service..."
systemctl enable $SERVICE_NAME
if [[ $? -ne 0 ]]; then
echo "ERROR: Failed to enable service"
exit 1
fi
echo "Service enabled"
# Start the service
echo "Starting service..."
systemctl start $SERVICE_NAME
if [[ $? -ne 0 ]]; then
echo "ERROR: Failed to start service"
echo "Check service status with: systemctl status $SERVICE_NAME"
exit 1
fi
echo "Service started successfully"
# Wait a moment and check service status
sleep 3
SERVICE_STATUS=$(systemctl is-active $SERVICE_NAME)
echo "Service Status: $SERVICE_STATUS"
# Configure firewall (if ufw is available)
if command -v ufw &> /dev/null; then
echo "Configuring firewall for web dashboard..."
ufw allow 5000/tcp comment "Resource Monitor Service"
echo "Firewall rule created for port 5000"
fi
echo
echo "=== Installation Complete ==="
echo "Service Name: $SERVICE_NAME"
echo "Installation Path: $INSTALL_PATH"
echo "Web Dashboard: http://localhost:5000"
echo "API Documentation: http://localhost:5000/swagger"
echo "API Health Check: http://localhost:5000/api/health"
echo
echo "The service is now running and will start automatically with the system."
echo "You can manage it using systemctl commands:"
echo " - Stop: sudo systemctl stop $SERVICE_NAME"
echo " - Start: sudo systemctl start $SERVICE_NAME"
echo " - Status: systemctl status $SERVICE_NAME"
echo " - Restart: sudo systemctl restart $SERVICE_NAME"
echo " - Logs: journalctl -u $SERVICE_NAME -f"
echo
echo "To uninstall: sudo ./install-service-linux.sh --uninstall"
# Test the web dashboard
echo
echo "Testing web dashboard..."
sleep 5
if command -v curl &> /dev/null; then
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/api/health)
if [[ "$RESPONSE" == "200" ]]; then
echo "Web Dashboard Test: SUCCESS"
echo
echo "🎉 Web Dashboard is ready at: http://localhost:5000"
echo "📖 API Documentation at: http://localhost:5000/swagger"
else
echo "Web Dashboard Test: FAILED (HTTP $RESPONSE)"
echo "The service may still be starting up. Wait a few minutes and try accessing:"
echo "http://localhost:5000"
fi
else
echo "curl not available for testing. Please check manually:"
echo "http://localhost:5000"
fi
+25 -17
View File
@@ -6,8 +6,8 @@ param(
) )
$SERVICE_NAME = "ResourceMonitorService" $SERVICE_NAME = "ResourceMonitorService"
$SERVICE_DISPLAY_NAME = "Resource Monitor Service v2.0" $SERVICE_DISPLAY_NAME = "Resource Monitor Service v2.1"
$SERVICE_DESCRIPTION = "Monitors VM resources for Unraid integration" $SERVICE_DESCRIPTION = "Monitors system resources with web dashboard for Unraid integration"
$INSTALL_PATH = "C:\Services\ResourceMonitor" $INSTALL_PATH = "C:\Services\ResourceMonitor"
Write-Host "=== Resource Monitor Service - Windows Service Installer ===" -ForegroundColor Cyan Write-Host "=== Resource Monitor Service - Windows Service Installer ===" -ForegroundColor Cyan
@@ -135,14 +135,18 @@ try {
Write-Host "WARNING: Failed to configure service recovery options" -ForegroundColor Yellow Write-Host "WARNING: Failed to configure service recovery options" -ForegroundColor Yellow
} }
# Configure firewall rule # Configure firewall rule for web dashboard
Write-Host "Configuring Windows Firewall..." Write-Host "Configuring Windows Firewall for web dashboard..."
try { try {
New-NetFirewallRule -DisplayName "Resource Monitor Service" -Direction Inbound -Protocol TCP -LocalPort 2414 -Action Allow -Profile Any -ErrorAction Stop # Remove old rule if it exists
Write-Host "Firewall rule created" -ForegroundColor Green Remove-NetFirewallRule -DisplayName "Resource Monitor Service" -ErrorAction SilentlyContinue
# Create new rule for port 5000 (web dashboard)
New-NetFirewallRule -DisplayName "Resource Monitor Service" -Direction Inbound -Protocol TCP -LocalPort 5000 -Action Allow -Profile Any -ErrorAction Stop
Write-Host "Firewall rule created for web dashboard (port 5000)" -ForegroundColor Green
} catch { } catch {
Write-Host "WARNING: Failed to create firewall rule. You may need to configure manually." -ForegroundColor Yellow Write-Host "WARNING: Failed to create firewall rule. You may need to configure manually." -ForegroundColor Yellow
Write-Host "Manual command: New-NetFirewallRule -DisplayName 'Resource Monitor Service' -Direction Inbound -Protocol TCP -LocalPort 2414 -Action Allow" -ForegroundColor Gray Write-Host "Manual command: New-NetFirewallRule -DisplayName 'Resource Monitor Service' -Direction Inbound -Protocol TCP -LocalPort 5000 -Action Allow" -ForegroundColor Gray
} }
# Start the service # Start the service
@@ -165,8 +169,9 @@ Write-Host
Write-Host "=== Installation Complete ===" -ForegroundColor Cyan Write-Host "=== Installation Complete ===" -ForegroundColor Cyan
Write-Host "Service Name: $SERVICE_NAME" -ForegroundColor White Write-Host "Service Name: $SERVICE_NAME" -ForegroundColor White
Write-Host "Installation Path: $INSTALL_PATH" -ForegroundColor White Write-Host "Installation Path: $INSTALL_PATH" -ForegroundColor White
Write-Host "Service URL: http://localhost:2414" -ForegroundColor White Write-Host "Web Dashboard: http://localhost:5000" -ForegroundColor Yellow
Write-Host "API Health Check: http://localhost:2414/api/health" -ForegroundColor White Write-Host "API Documentation: http://localhost:5000/swagger" -ForegroundColor Yellow
Write-Host "API Health Check: http://localhost:5000/api/health" -ForegroundColor White
Write-Host Write-Host
Write-Host "The service is now running and will start automatically with Windows." -ForegroundColor Green Write-Host "The service is now running and will start automatically with Windows." -ForegroundColor Green
Write-Host "You can manage it through Services.msc or using PowerShell commands:" -ForegroundColor White Write-Host "You can manage it through Services.msc or using PowerShell commands:" -ForegroundColor White
@@ -177,17 +182,20 @@ Write-Host " - Restart: Restart-Service -Name $SERVICE_NAME" -ForegroundColor G
Write-Host Write-Host
Write-Host "To uninstall: .\install-service.ps1 -Uninstall" -ForegroundColor Yellow Write-Host "To uninstall: .\install-service.ps1 -Uninstall" -ForegroundColor Yellow
# Test the API endpoint # Test the web dashboard
Write-Host Write-Host
Write-Host "Testing API endpoint..." -ForegroundColor Yellow Write-Host "Testing web dashboard..." -ForegroundColor Yellow
Start-Sleep -Seconds 5 Start-Sleep -Seconds 5
try { try {
$response = Invoke-RestMethod -Uri "http://localhost:2414/" -TimeoutSec 10 $response = Invoke-RestMethod -Uri "http://localhost:5000/api/health" -TimeoutSec 10
Write-Host "API Test Result: SUCCESS" -ForegroundColor Green Write-Host "Web Dashboard Test: SUCCESS" -ForegroundColor Green
Write-Host "Service Version: $($response.Service) v$($response.Version)" -ForegroundColor White Write-Host "Service Status: $($response.status)" -ForegroundColor White
Write-Host "Status: $($response.Status)" -ForegroundColor White Write-Host "Service Uptime: $($response.uptime)" -ForegroundColor White
Write-Host
Write-Host "🎉 Web Dashboard is ready at: http://localhost:5000" -ForegroundColor Green
Write-Host "📖 API Documentation at: http://localhost:5000/swagger" -ForegroundColor Green
} catch { } catch {
Write-Host "API Test Result: FAILED" -ForegroundColor Red Write-Host "Web Dashboard Test: FAILED" -ForegroundColor Red
Write-Host "The service may still be starting up. Wait a few minutes and try accessing:" -ForegroundColor Yellow Write-Host "The service may still be starting up. Wait a few minutes and try accessing:" -ForegroundColor Yellow
Write-Host "http://localhost:2414/api/health" -ForegroundColor White Write-Host "http://localhost:5000" -ForegroundColor White
} }
-86
View File
@@ -1,86 +0,0 @@
#!/bin/bash
# Resource Monitor Service - Installation Script for Windows Service
SERVICE_NAME="ResourceMonitorService"
SERVICE_DISPLAY_NAME="Resource Monitor Service v2.0"
SERVICE_DESCRIPTION="Monitors VM resources for Unraid integration"
INSTALL_PATH="C:\Services\ResourceMonitor"
echo "=== Resource Monitor Service - Windows Service Installer ==="
echo
# Check if running as administrator
if [[ ! $(id -u) -eq 0 ]]; then
echo "ERROR: This script must be run as Administrator"
echo "Please run PowerShell as Administrator and try again"
exit 1
fi
echo "Installing Resource Monitor Service as Windows Service..."
# Create installation directory
echo "Creating installation directory..."
mkdir -p "$INSTALL_PATH"
# Build the service in release mode
echo "Building service..."
dotnet publish --configuration Release --output "$INSTALL_PATH"
if [[ $? -ne 0 ]]; then
echo "ERROR: Build failed"
exit 1
fi
# Stop existing service if running
echo "Stopping existing service (if running)..."
sc stop "$SERVICE_NAME" 2>/dev/null
# Remove existing service if it exists
echo "Removing existing service (if exists)..."
sc delete "$SERVICE_NAME" 2>/dev/null
# Install the service
echo "Installing Windows Service..."
sc create "$SERVICE_NAME" \
binPath="\"$INSTALL_PATH\\ResourceMonitorService.exe\" --windows-service" \
DisplayName="$SERVICE_DISPLAY_NAME" \
Description="$SERVICE_DESCRIPTION" \
start=auto
if [[ $? -ne 0 ]]; then
echo "ERROR: Failed to create Windows Service"
exit 1
fi
# Configure service recovery options
echo "Configuring service recovery options..."
sc failure "$SERVICE_NAME" reset=300 actions=restart/5000/restart/5000/restart/10000
# Configure firewall rule
echo "Configuring Windows Firewall..."
powershell -Command "New-NetFirewallRule -DisplayName 'Resource Monitor Service' -Direction Inbound -Protocol TCP -LocalPort 2414 -Action Allow -Profile Any" 2>/dev/null
# Start the service
echo "Starting service..."
sc start "$SERVICE_NAME"
if [[ $? -eq 0 ]]; then
echo
echo "=== Installation Complete ==="
echo "Service Name: $SERVICE_NAME"
echo "Installation Path: $INSTALL_PATH"
echo "Service URL: http://localhost:2414"
echo "API Health Check: http://localhost:2414/api/health"
echo
echo "The service is now running and will start automatically with Windows."
echo "You can manage it through Services.msc or using sc commands:"
echo " - Stop: sc stop $SERVICE_NAME"
echo " - Start: sc start $SERVICE_NAME"
echo " - Status: sc query $SERVICE_NAME"
echo
echo "To uninstall: sc stop $SERVICE_NAME && sc delete $SERVICE_NAME"
else
echo "ERROR: Failed to start service"
echo "Check Windows Event Log for details"
exit 1
fi