Files
ResourceUsageAPI/DEPLOYMENT_GUIDE.md

6.2 KiB

ResourceMonitorService - Packaging and VM Deployment Guide

This guide explains how to package the ResourceMonitorService for release and deploy it to a VM.

📦 Packaging for Release

Quick Packaging

# Simple packaging - creates a ZIP file with all necessary components
.\create-package.ps1

# Specify version
.\create-package.ps1 -Version "2.1.1"

What Gets Packaged

The packaging script includes:

  • Compiled .NET binaries (Release build)
  • Installation scripts (install-service.ps1, start-service.bat)
  • Configuration files (appsettings.json)
  • Documentation files (README.md, etc.)
  • Deployment instructions (DEPLOYMENT.txt)

Output

  • Location: .\release-packages\
  • Format: ResourceMonitorService-v{VERSION}-{TIMESTAMP}.zip
  • Size: ~2.3 MB
  • Example: ResourceMonitorService-v2.1.0-20250807-2322.zip

🚀 VM Deployment Options

  1. Transfer the ZIP file to your VM:

    • Copy via RDP shared folders
    • Use network file share
    • Download from cloud storage
    • USB transfer
  2. On the VM:

    # Extract the ZIP file to a temporary directory
    Expand-Archive -Path "ResourceMonitorService-v2.1.0-*.zip" -DestinationPath "C:\Temp\ResourceMonitor"
    
    # Navigate to extracted directory
    cd "C:\Temp\ResourceMonitor"
    
    # Run installation as Administrator
    .\install-service.ps1
    
  3. Access the service:

    • Web Dashboard: http://VM-IP:5000
    • API Health: http://VM-IP:5000/api/health

Option 2: Automated Deployment (Advanced)

If your VM has PowerShell Remoting enabled:

# Deploy using WinRM (requires setup)
.\deploy-to-vm.ps1 -VMAddress "192.168.1.100" -UseWinRM

# Copy only (no auto-install)
.\deploy-to-vm.ps1 -VMAddress "192.168.1.100" -UseWinRM -CopyOnly

Option 3: Complete Build & Deploy

# Build, package, and deploy in one command
.\build-and-deploy.ps1 -VMAddress "192.168.1.100" -DeployToVM -UseWinRM

🔧 VM Prerequisites

Required Software

  • Windows 10/11 or Windows Server 2019+
  • .NET 9.0 Runtime (Download)
  • PowerShell 5.1+ (Built into Windows)

Administrator Privileges

The installation requires Administrator privileges to:

  • Create Windows Service
  • Configure firewall rules
  • Create directories in Program Files
  • Set service permissions

Network Requirements

  • Port 5000: Web Dashboard access
  • Port 5001: HTTPS access (optional)
  • Firewall rule is automatically created during installation

📋 Installation Process

The install-service.ps1 script automatically:

  1. Creates installation directory (C:\Services\ResourceMonitor)
  2. Copies all service files
  3. Registers Windows Service (ResourceMonitorService)
  4. Configures auto-start (starts with Windows)
  5. Creates firewall rule (port 5000)
  6. Starts the service
  7. Tests web dashboard availability

🎯 Post-Installation

Service Management

# Check service status
Get-Service ResourceMonitorService

# Start/Stop/Restart service
Start-Service ResourceMonitorService
Stop-Service ResourceMonitorService
Restart-Service ResourceMonitorService

# Uninstall service
.\install-service.ps1 -Uninstall

Access Points

  • Web Dashboard: http://VM-IP:5000
  • API Documentation: http://VM-IP:5000/swagger (if enabled)
  • Health Check: http://VM-IP:5000/api/health
  • Logs: C:\Services\ResourceMonitor\logs\

Configuration

Edit C:\Services\ResourceMonitor\appsettings.json to customize:

  • Monitoring intervals
  • Alert thresholds
  • Telegram notifications
  • API settings
  • Logging levels

🔍 Troubleshooting

Common Issues

Service won't start:

# Check Windows Event Log
Get-EventLog -LogName Application -Source "ResourceMonitorService" -Newest 10

# Check service logs
Get-Content "C:\Services\ResourceMonitor\logs\*.txt" -Tail 50

Port 5000 not accessible:

# Manually create firewall rule
New-NetFirewallRule -DisplayName "Resource Monitor Service" -Direction Inbound -Protocol TCP -LocalPort 5000 -Action Allow

# Check if port is listening
netstat -an | findstr :5000

.NET Runtime not found:

# Check .NET installation
dotnet --version
dotnet --list-runtimes

# Download from: https://dotnet.microsoft.com/download/dotnet/9.0

Log Locations

  • Service Logs: C:\Services\ResourceMonitor\logs\
  • Windows Event Log: Application > ResourceMonitorService
  • Installation Logs: Console output during installation

📝 File Structure

After installation, the service directory contains:

C:\Services\ResourceMonitor\
├── ResourceMonitorService.exe          # Main service executable
├── ResourceMonitorService.dll          # Application library
├── appsettings.json                     # Configuration file
├── appsettings.Development.json         # Development settings
├── install-service.ps1                 # Installation script
├── start-service.bat                   # Manual start script
├── DEPLOYMENT.txt                       # Deployment instructions
├── logs\                                # Log files directory
├── wwwroot\                             # Web dashboard files
│   ├── index.html
│   ├── css\
│   └── js\
└── [various .NET runtime files]

🚀 Quick Reference

Essential Commands

# Package for deployment
.\create-package.ps1

# Install on VM (as Administrator)
.\install-service.ps1

# Check service status
Get-Service ResourceMonitorService

# Access dashboard
Start-Process "http://localhost:5000"

# Uninstall
.\install-service.ps1 -Uninstall

Network Access

Replace localhost with your VM's IP address to access remotely:

  • http://192.168.1.100:5000 (Web Dashboard)
  • http://192.168.1.100:5000/api/health (Health Check)

🔗 Additional Resources

  • Main README: README.md
  • Web UI Guide: README_WebUI.md
  • Telegram Setup: TELEGRAM_SETUP.md
  • Project Repository: [GitHub/ResourceMonitorService]

For support or issues, check the troubleshooting section above or review the service logs.