diff --git a/Configuration/MonitoringSettings.cs b/Configuration/MonitoringSettings.cs index 340d42f..2a22d0c 100644 --- a/Configuration/MonitoringSettings.cs +++ b/Configuration/MonitoringSettings.cs @@ -6,7 +6,6 @@ namespace ResourceMonitorService.Configuration public int DataRetentionDays { get; set; } = 7; public bool EnableGpuMonitoring { get; set; } = true; public bool EnableDiskMonitoring { get; set; } = true; - public bool EnableNetworkMonitoring { get; set; } = true; public bool EnableTemperatureMonitoring { get; set; } = true; public bool EnableProcessMonitoring { get; set; } = true; public bool EnableGameDetection { get; set; } = true; diff --git a/Controllers/ResourceController.cs b/Controllers/ResourceController.cs index dc1b9e5..dec1a00 100644 --- a/Controllers/ResourceController.cs +++ b/Controllers/ResourceController.cs @@ -113,21 +113,6 @@ namespace ResourceMonitorService.Controllers } } - [HttpGet("network")] - public async Task> GetNetworkUsage() - { - try - { - var networkUsage = await _resourceMonitorService.GetNetworkUsageAsync(); - return Ok(networkUsage); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error getting network usage"); - return StatusCode(500, "Internal server error"); - } - } - [HttpGet("processes")] public async Task>> GetTopProcesses([FromQuery] int count = 10) { diff --git a/Models/SystemInfo.cs b/Models/SystemInfo.cs index cbe63ad..9c0e63d 100644 --- a/Models/SystemInfo.cs +++ b/Models/SystemInfo.cs @@ -24,7 +24,6 @@ namespace ResourceMonitorService.Models public MemoryUsage Memory { get; set; } = new(); public GpuUsage GPU { get; set; } = new(); public List Disks { get; set; } = new(); - public NetworkUsage Network { get; set; } = new(); public List TopProcesses { get; set; } = new(); public TemperatureInfo Temperature { get; set; } = new(); public GameInfo? RunningGame { get; set; } @@ -84,27 +83,6 @@ namespace ResourceMonitorService.Models public long WriteOperations { get; set; } } - public class NetworkUsage - { - public float UploadSpeed { get; set; } // MB/s - public float DownloadSpeed { get; set; } // MB/s - public ulong BytesSent { get; set; } - public ulong BytesReceived { get; set; } - public List Adapters { get; set; } = new(); - } - - public class NetworkAdapter - { - public string Name { get; set; } = string.Empty; - public string Description { get; set; } = string.Empty; - public bool IsOperational { get; set; } - public long Speed { get; set; } - public float UploadSpeed { get; set; } - public float DownloadSpeed { get; set; } - public string IPAddress { get; set; } = string.Empty; - public string MACAddress { get; set; } = string.Empty; - } - public class ProcessInfo { public int ProcessId { get; set; } diff --git a/Services/ResourceMonitorService.cs b/Services/ResourceMonitorService.cs index 36f9fdc..d34228e 100644 --- a/Services/ResourceMonitorService.cs +++ b/Services/ResourceMonitorService.cs @@ -14,7 +14,6 @@ namespace ResourceMonitorService.Services Task GetMemoryUsageAsync(); Task GetGpuUsageAsync(); Task> GetDiskUsageAsync(); - Task GetNetworkUsageAsync(); Task> GetTopProcessesAsync(int count = 10); } @@ -23,8 +22,6 @@ namespace ResourceMonitorService.Services private readonly ILogger _logger; private readonly MonitoringSettings _settings; private readonly Dictionary _counters; - private readonly Dictionary _previousNetworkBytes; - private readonly Dictionary _previousNetworkTime; private readonly Dictionary _previousDiskBytes; private readonly Dictionary _previousDiskTime; private readonly Dictionary _errorCounts; @@ -35,8 +32,6 @@ namespace ResourceMonitorService.Services _logger = logger; _settings = settings.Value; _counters = new Dictionary(); - _previousNetworkBytes = new Dictionary(); - _previousNetworkTime = new Dictionary(); _previousDiskBytes = new Dictionary(); _previousDiskTime = new Dictionary(); _errorCounts = new Dictionary(); @@ -52,12 +47,6 @@ namespace ResourceMonitorService.Services _counters["cpu"] = new PerformanceCounter("Processor", "% Processor Time", "_Total"); _counters["memory_available"] = new PerformanceCounter("Memory", "Available MBytes"); - if (_settings.EnableNetworkMonitoring) - { - _counters["network_bytes_sent"] = new PerformanceCounter("Network Interface", "Bytes Sent/sec", "*"); - _counters["network_bytes_received"] = new PerformanceCounter("Network Interface", "Bytes Received/sec", "*"); - } - if (_settings.EnableDiskMonitoring) { _counters["disk_read"] = new PerformanceCounter("PhysicalDisk", "Disk Read Bytes/sec", "_Total"); @@ -119,9 +108,6 @@ namespace ResourceMonitorService.Services if (_settings.EnableDiskMonitoring) tasks.Add(Task.Run(async () => await GetDiskUsageAsync())); - if (_settings.EnableNetworkMonitoring) - tasks.Add(Task.Run(async () => await GetNetworkUsageAsync())); - if (_settings.EnableProcessMonitoring) tasks.Add(Task.Run(async () => await GetTopProcessesAsync(_settings.MaxProcessesToTrack))); @@ -134,7 +120,6 @@ namespace ResourceMonitorService.Services Memory = await GetMemoryUsageAsync(), GPU = _settings.EnableGpuMonitoring ? await GetGpuUsageAsync() : new GpuUsage(), Disks = _settings.EnableDiskMonitoring ? await GetDiskUsageAsync() : new List(), - Network = _settings.EnableNetworkMonitoring ? await GetNetworkUsageAsync() : new NetworkUsage(), TopProcesses = _settings.EnableProcessMonitoring ? await GetTopProcessesAsync(_settings.MaxProcessesToTrack) : new List(), Temperature = _settings.EnableTemperatureMonitoring ? await GetTemperatureInfoAsync() : new TemperatureInfo() }; @@ -654,91 +639,6 @@ namespace ResourceMonitorService.Services return false; } - public async Task GetNetworkUsageAsync() - { - try - { - return await Task.Run(() => - { - var networkUsage = new NetworkUsage(); - var adapters = new List(); - - try - { -#pragma warning disable CA1416 // Validate platform compatibility - using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface WHERE Name != 'Loopback'"); - using var collection = searcher.Get(); - - foreach (ManagementObject obj in collection) - { - var name = obj["Name"]?.ToString() ?? ""; - if (name.Contains("Loopback") || name.Contains("Isatap") || name.Contains("Teredo")) - continue; - - var bytesSent = Convert.ToInt64(obj["BytesSentPerSec"] ?? 0); - var bytesReceived = Convert.ToInt64(obj["BytesReceivedPerSec"] ?? 0); - var timestamp = DateTime.Now; - - var adapter = new NetworkAdapter - { - Name = name, - IsOperational = true - }; - - // Calculate speeds if we have previous data - var key = $"{name}_sent"; - if (_previousNetworkBytes.ContainsKey(key) && _previousNetworkTime.ContainsKey(key)) - { - var timeDiff = (timestamp - _previousNetworkTime[key]).TotalSeconds; - if (timeDiff > 0) - { - var bytesDiff = bytesSent - _previousNetworkBytes[key]; - adapter.UploadSpeed = (float)(bytesDiff / timeDiff / (1024 * 1024)); // MB/s - networkUsage.UploadSpeed += adapter.UploadSpeed; - } - } - - key = $"{name}_received"; - if (_previousNetworkBytes.ContainsKey(key) && _previousNetworkTime.ContainsKey(key)) - { - var timeDiff = (timestamp - _previousNetworkTime[key]).TotalSeconds; - if (timeDiff > 0) - { - var bytesDiff = bytesReceived - _previousNetworkBytes[key]; - adapter.DownloadSpeed = (float)(bytesDiff / timeDiff / (1024 * 1024)); // MB/s - networkUsage.DownloadSpeed += adapter.DownloadSpeed; - } - } - - // Store current values for next calculation - _previousNetworkBytes[$"{name}_sent"] = bytesSent; - _previousNetworkBytes[$"{name}_received"] = bytesReceived; - _previousNetworkTime[$"{name}_sent"] = timestamp; - _previousNetworkTime[$"{name}_received"] = timestamp; - - networkUsage.BytesSent += (ulong)bytesSent; - networkUsage.BytesReceived += (ulong)bytesReceived; - - adapters.Add(adapter); - } -#pragma warning restore CA1416 // Validate platform compatibility - } - catch (Exception ex) - { - _logger.LogWarning(ex, "Could not get network performance data"); - } - - networkUsage.Adapters = adapters; - return networkUsage; - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error getting network usage"); - return new NetworkUsage(); - } - } - public async Task> GetTopProcessesAsync(int count = 10) { try diff --git a/wwwroot/index.html b/wwwroot/index.html index d11096b..58bc620 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -41,7 +41,7 @@
-
+
@@ -93,22 +93,13 @@
-
-
- - -
-
-
-

Network

-

0 MB/s

+
+ + + 0°C + + Normal
-
- -
-
-
-

↑ 0 MB/s ↓ 0 MB/s

diff --git a/wwwroot/js/dashboard.js b/wwwroot/js/dashboard.js index b3aacdb..f2f46f1 100644 --- a/wwwroot/js/dashboard.js +++ b/wwwroot/js/dashboard.js @@ -228,18 +228,29 @@ class ResourceDashboard { // Update GPU if (data.gpu) { const gpuUsage = data.gpu.usage || 0; + const gpuTemp = data.gpu.temperature || 0; + document.getElementById('gpuUsage').textContent = `${gpuUsage.toFixed(1)}%`; document.getElementById('gpuBar').style.width = `${gpuUsage}%`; - } - - // Update Network - if (data.network) { - const bytesReceived = data.network.bytesReceived || 0; - const bytesSent = data.network.bytesSent || 0; - const totalSpeed = (bytesReceived + bytesSent) / 1024 / 1024; - document.getElementById('networkSpeed').textContent = `${totalSpeed.toFixed(1)} MB/s`; - document.getElementById('networkDetail').textContent = - `↑ ${(bytesSent / 1024 / 1024).toFixed(1)} MB/s ↓ ${(bytesReceived / 1024 / 1024).toFixed(1)} MB/s`; + + // Update GPU temperature + document.getElementById('gpuTemp').textContent = `${gpuTemp}°C`; + + // Set temperature status color based on temperature ranges + const tempStatusElement = document.getElementById('gpuTempStatus'); + if (gpuTemp <= 60) { + tempStatusElement.textContent = 'Cool'; + tempStatusElement.className = 'text-green-600'; + } else if (gpuTemp <= 75) { + tempStatusElement.textContent = 'Normal'; + tempStatusElement.className = 'text-yellow-600'; + } else if (gpuTemp <= 85) { + tempStatusElement.textContent = 'Warm'; + tempStatusElement.className = 'text-orange-600'; + } else { + tempStatusElement.textContent = 'Hot'; + tempStatusElement.className = 'text-red-600'; + } } // Update Game Detection @@ -258,6 +269,11 @@ class ResourceDashboard { if (data.disks && !document.getElementById('detailsSection').classList.contains('hidden')) { this.updateDiskUsage(data.disks); } + + // Update System Info GPU details (only if details section is visible and we have system info) + if (!document.getElementById('detailsSection').classList.contains('hidden') && this.lastSystemInfo) { + this.updateSystemInfo(this.lastSystemInfo); + } } catch (error) { console.error('Error updating dashboard:', error); this.showNotification('Error updating dashboard data', 'error'); @@ -343,6 +359,43 @@ class ResourceDashboard { // Store the latest system info this.lastSystemInfo = systemInfo; + // Get GPU info from the latest resource data if available + const gpuInfo = this.lastResourceData?.gpu; + + let gpuSection = ''; + if (gpuInfo && gpuInfo.isAvailable) { + gpuSection = ` +
+

GPU

+

${gpuInfo.name || 'Unknown GPU'}

+
+
+ Usage: + ${gpuInfo.usage || 0}% +
+
+ Temperature: + ${gpuInfo.temperature || 0}°C +
+
+ Memory: + ${gpuInfo.memoryUsed && gpuInfo.memoryTotal ? ((gpuInfo.memoryUsed / gpuInfo.memoryTotal) * 100).toFixed(1) : 0}% +
+ ${gpuInfo.fanSpeed ? ` +
+ Fan Speed: + ${gpuInfo.fanSpeed}% +
` : ''} + ${gpuInfo.powerUsage ? ` +
+ Power: + ${gpuInfo.powerUsage}W +
` : ''} +
+
+ `; + } + const systemInfoDiv = document.getElementById('systemInfo'); systemInfoDiv.innerHTML = `
@@ -369,6 +422,7 @@ class ResourceDashboard {

Uptime

${systemInfo.uptime ? this.formatUptime(systemInfo.uptime) : 'N/A'}

+ ${gpuSection} `; }