From 96b6e3dcd93e8a62fcd8ed7d492840871af78bd2 Mon Sep 17 00:00:00 2001 From: Phoenix Date: Thu, 7 Aug 2025 23:10:40 +0800 Subject: [PATCH] Update README and installation scripts for Resource Monitor Service v2.1, enhancing web dashboard features and adjusting firewall configurations. --- README.md | 250 +++++++++++++++++++++++++-------------- install-service-linux.sh | 194 ++++++++++++++++++++++++++++++ install-service.ps1 | 42 ++++--- install-service.sh | 86 -------------- 4 files changed, 380 insertions(+), 192 deletions(-) create mode 100644 install-service-linux.sh delete mode 100644 install-service.sh diff --git a/README.md b/README.md index 7f26acf..effd15b 100644 --- a/README.md +++ b/README.md @@ -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 +### 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 - **CPU Monitoring**: Per-core usage, frequency, temperature, and throttling detection - **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 -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 -- `GET /api/system-info` - Complete system information including VM details -- `GET /api/vm/info` - VM-specific information (hypervisor, uptime, etc.) -- `GET /api/health` - Service health status and monitoring capabilities -- `GET /api/metrics` - Service metrics and performance overview -- `GET /api/config` - Current configuration settings +- `GET /api/resource/usage` - **Complete resource overview** - All monitoring data in one call +- `GET /api/resource/system-info` - Complete system information including VM details +- `GET /api/resource/cpu` - Detailed CPU metrics with per-core data +- `GET /api/resource/memory` - Memory utilization and statistics +- `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 -- `GET /api/resource-usage` - Complete resource usage overview -- `GET /api/cpu-usage` - Detailed CPU metrics with per-core data -- `GET /api/memory-usage` - Memory utilization and statistics -- `GET /api/gpu-usage` - NVIDIA GPU usage, memory, temperature, fan speed, and power consumption -- `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 +### Process Management +- `POST /api/resource/kill-process/{processId}` - **Terminate Process** - End any process by ID + +### Real-time Updates +- **SignalR Hub**: `/resourceHub` - Real-time data updates every 15 seconds ### Game Detection - `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 -### Option 1: Console Application (Development/Testing) +### Option 1: Web Dashboard (Recommended) ```powershell cd C:\Work\DEV\ResourceUsageAPI dotnet run --configuration Release ``` +Then open your browser to `http://localhost:5000` for the interactive dashboard. ### Option 2: Windows Service (Production) ```powershell # Run as Administrator -cd C:\Work\DEV\ResourceUsageAPI\publish -.\install-service.bat +cd C:\Work\DEV\ResourceUsageAPI +.\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 -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 ``` +## 🎮 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 is managed through `appsettings.json`: @@ -102,7 +205,7 @@ Configuration is managed through `appsettings.json`: ```json { "MonitoringSettings": { - "UpdateIntervalMs": 5000, + "UpdateIntervalMs": 15000, "EnableGpuMonitoring": true, "EnableDiskMonitoring": true, "EnableNetworkMonitoring": true, @@ -123,18 +226,15 @@ Configuration is managed through `appsettings.json`: "E:\\Games" ] }, - "AlertThresholds": { - "CpuUsageThreshold": 80.0, - "MemoryUsageThreshold": 85.0, - "GpuUsageThreshold": 90.0, - "DiskUsageThreshold": 90.0, - "TemperatureThreshold": 80.0, - "AlertDurationSeconds": 30 - }, - "ApiSettings": { - "RequireApiKey": false, - "AllowedOrigins": ["http://localhost:4200", "http://unraid:4200"], - "BasePath": "/api" + "Kestrel": { + "Endpoints": { + "Http": { + "Url": "http://localhost:5000" + }, + "Https": { + "Url": "https://localhost:5001" + } + } } } ``` @@ -331,68 +431,40 @@ The service supports real-time alert notifications via Telegram bot. To set up T ## 🔧 PowerShell Usage Examples ```powershell -# Get system health -$health = Invoke-RestMethod -Uri "http://localhost:5000/api/health" -Write-Host "System Status: $($health.status)" +# Access the web dashboard +Start-Process "http://localhost:5000" -# Get CPU usage -$cpu = Invoke-RestMethod -Uri "http://localhost:5000/api/cpu-usage" -Write-Host "CPU Usage: $($cpu.usage)%" +# Get complete resource overview +$resources = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/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 -$gpu = Invoke-RestMethod -Uri "http://localhost:5000/api/gpu-usage" -if ($gpu.isAvailable) { - Write-Host "GPU: $($gpu.name)" - Write-Host "GPU Usage: $($gpu.usage)%" - 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" -} else { - Write-Host "GPU not available: $($gpu.error)" +# Get system information +$systemInfo = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/system-info" +Write-Host "Machine: $($systemInfo.machineName)" +Write-Host "OS: $($systemInfo.osVersion)" +Write-Host "CPU: $($systemInfo.cpuName)" + +# Get disk usage +$disks = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/disks" +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) -$game = Invoke-RestMethod -Uri "http://localhost:5000/api/current-game" -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" +# Get top processes +$processes = Invoke-RestMethod -Uri "http://localhost:5000/api/resource/processes?count=5" Write-Host "Top 5 processes by CPU usage:" -foreach ($proc in $processes.value) { - Write-Host " $($proc.name): $($proc.cpuUsage.ToString('F2'))% CPU, $($proc.memoryUsagePercentage.ToString('F2'))% Memory" +foreach ($proc in $processes) { + if ($proc.cpuUsage) { + Write-Host " $($proc.name): $($proc.cpuUsage.ToString('F1'))% CPU" + } } # Terminate a process (example - be careful!) -$killRequest = @{ - 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" +# Invoke-RestMethod -Uri "http://localhost:5000/api/resource/kill-process/1234" -Method Post ``` ## 🚨 Known Warnings (Non-Critical) @@ -435,7 +507,7 @@ The service uses Serilog for structured logging: ## 📈 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 - Non-blocking async operations - Real-time CPU usage calculation for individual processes diff --git a/install-service-linux.sh b/install-service-linux.sh new file mode 100644 index 0000000..1527cbc --- /dev/null +++ b/install-service-linux.sh @@ -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 diff --git a/install-service.ps1 b/install-service.ps1 index 4ccecca..3a74177 100644 --- a/install-service.ps1 +++ b/install-service.ps1 @@ -6,8 +6,8 @@ param( ) $SERVICE_NAME = "ResourceMonitorService" -$SERVICE_DISPLAY_NAME = "Resource Monitor Service v2.0" -$SERVICE_DESCRIPTION = "Monitors VM resources for Unraid integration" +$SERVICE_DISPLAY_NAME = "Resource Monitor Service v2.1" +$SERVICE_DESCRIPTION = "Monitors system resources with web dashboard for Unraid integration" $INSTALL_PATH = "C:\Services\ResourceMonitor" 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 } -# Configure firewall rule -Write-Host "Configuring Windows Firewall..." +# Configure firewall rule for web dashboard +Write-Host "Configuring Windows Firewall for web dashboard..." try { - New-NetFirewallRule -DisplayName "Resource Monitor Service" -Direction Inbound -Protocol TCP -LocalPort 2414 -Action Allow -Profile Any -ErrorAction Stop - Write-Host "Firewall rule created" -ForegroundColor Green + # Remove old rule if it exists + 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 { 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 @@ -165,8 +169,9 @@ Write-Host Write-Host "=== Installation Complete ===" -ForegroundColor Cyan Write-Host "Service Name: $SERVICE_NAME" -ForegroundColor White Write-Host "Installation Path: $INSTALL_PATH" -ForegroundColor White -Write-Host "Service URL: http://localhost:2414" -ForegroundColor White -Write-Host "API Health Check: http://localhost:2414/api/health" -ForegroundColor White +Write-Host "Web Dashboard: http://localhost:5000" -ForegroundColor Yellow +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 "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 @@ -177,17 +182,20 @@ Write-Host " - Restart: Restart-Service -Name $SERVICE_NAME" -ForegroundColor G Write-Host Write-Host "To uninstall: .\install-service.ps1 -Uninstall" -ForegroundColor Yellow -# Test the API endpoint +# Test the web dashboard Write-Host -Write-Host "Testing API endpoint..." -ForegroundColor Yellow +Write-Host "Testing web dashboard..." -ForegroundColor Yellow Start-Sleep -Seconds 5 try { - $response = Invoke-RestMethod -Uri "http://localhost:2414/" -TimeoutSec 10 - Write-Host "API Test Result: SUCCESS" -ForegroundColor Green - Write-Host "Service Version: $($response.Service) v$($response.Version)" -ForegroundColor White - Write-Host "Status: $($response.Status)" -ForegroundColor White + $response = Invoke-RestMethod -Uri "http://localhost:5000/api/health" -TimeoutSec 10 + Write-Host "Web Dashboard Test: SUCCESS" -ForegroundColor Green + Write-Host "Service 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 { - 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 "http://localhost:2414/api/health" -ForegroundColor White + Write-Host "http://localhost:5000" -ForegroundColor White } diff --git a/install-service.sh b/install-service.sh deleted file mode 100644 index 4345dbc..0000000 --- a/install-service.sh +++ /dev/null @@ -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