feature/laptop #2
+4
-4
@@ -10,13 +10,13 @@ public static class NvmlWrapper
|
|||||||
public static extern int NvmlShutdown();
|
public static extern int NvmlShutdown();
|
||||||
|
|
||||||
// Get device count
|
// Get device count
|
||||||
[DllImport("nvml.dll", CallingConvention = CallingConvention.Cdecl)]
|
/* [DllImport("nvml.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern int nvmlDeviceGetCount_v2(ref uint deviceCount);
|
private static extern int nvmlDeviceGetCount_v2(ref uint deviceCount); */
|
||||||
|
|
||||||
public static int NvmlDeviceGetCount(ref uint deviceCount)
|
/* public static int NvmlDeviceGetCount(ref uint deviceCount)
|
||||||
{
|
{
|
||||||
return nvmlDeviceGetCount_v2(ref deviceCount);
|
return nvmlDeviceGetCount_v2(ref deviceCount);
|
||||||
}
|
} */
|
||||||
|
|
||||||
[DllImport("nvml.dll", EntryPoint = "nvmlDeviceGetHandleByIndex_v2")]
|
[DllImport("nvml.dll", EntryPoint = "nvmlDeviceGetHandleByIndex_v2")]
|
||||||
public static extern int NvmlDeviceGetHandleByIndex(int index, out IntPtr device);
|
public static extern int NvmlDeviceGetHandleByIndex(int index, out IntPtr device);
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ namespace ResourceMonitorService
|
|||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("AllowAllOrigins",
|
options.AddPolicy("AllowAllOrigins",
|
||||||
builder => builder.AllowAnyOrigin()
|
builder => builder
|
||||||
|
.WithOrigins("http://localhost:4200","http://192.168.50.52:4200","http://vmwin11:4200")
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowAnyMethod());
|
.AllowAnyMethod());
|
||||||
});
|
});
|
||||||
@@ -42,7 +43,7 @@ namespace ResourceMonitorService
|
|||||||
// and compares it with the expected API key from appsettings.json.
|
// and compares it with the expected API key from appsettings.json.
|
||||||
// If the API key is missing or invalid, it returns a 401 Unauthorized response.
|
// If the API key is missing or invalid, it returns a 401 Unauthorized response.
|
||||||
//
|
//
|
||||||
app.Use(async (context, next) =>
|
/* app.Use(async (context, next) =>
|
||||||
{
|
{
|
||||||
if (!context.Request.Headers.TryGetValue("X-API-KEY", out var extractedApiKey) || extractedApiKey != apiKey)
|
if (!context.Request.Headers.TryGetValue("X-API-KEY", out var extractedApiKey) || extractedApiKey != apiKey)
|
||||||
{
|
{
|
||||||
@@ -52,7 +53,7 @@ namespace ResourceMonitorService
|
|||||||
}
|
}
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
});
|
}); */
|
||||||
// Apply CORS policy to allow all origins
|
// Apply CORS policy to allow all origins
|
||||||
app.UseCors("AllowAllOrigins");
|
app.UseCors("AllowAllOrigins");
|
||||||
|
|
||||||
@@ -230,7 +231,26 @@ namespace ResourceMonitorService
|
|||||||
if (usage > 80)
|
if (usage > 80)
|
||||||
{
|
{
|
||||||
// Get the current processes and sort them by CPU usage in descending order
|
// Get the current processes and sort them by CPU usage in descending order
|
||||||
var processes = Process.GetProcesses().OrderByDescending(p => p.TotalProcessorTime);
|
var processes = Process.GetProcesses()
|
||||||
|
.Select(p =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
Process = p,
|
||||||
|
TotalProcessorTime = p.TotalProcessorTime
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null; // Skip processes that throw exceptions
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.Where(p => p != null)
|
||||||
|
.OrderByDescending(p => p.TotalProcessorTime)
|
||||||
|
.Select(p => p.Process)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
// Create a new anonymous type containing the CPU usage, RAM usage, and the top 3 highest CPU-using processes
|
// Create a new anonymous type containing the CPU usage, RAM usage, and the top 3 highest CPU-using processes
|
||||||
return new
|
return new
|
||||||
@@ -327,7 +347,9 @@ namespace ResourceMonitorService
|
|||||||
{
|
{
|
||||||
Usage = utilization.Gpu,
|
Usage = utilization.Gpu,
|
||||||
Temperature = temperature,
|
Temperature = temperature,
|
||||||
FanSpeed = fanSpeed
|
FanSpeed = fanSpeed,
|
||||||
|
IsAvailable = false,
|
||||||
|
Error = ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -343,7 +365,7 @@ namespace ResourceMonitorService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsNvidiaGpuPresent()
|
/* private bool IsNvidiaGpuPresent()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -371,7 +393,7 @@ namespace ResourceMonitorService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
private object GetCurrentlyRunningGame()
|
private object GetCurrentlyRunningGame()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RunAsWindowsService": true,
|
||||||
|
"Kestrel": {
|
||||||
|
"Endpoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://*:5000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ApiSettings": {
|
||||||
|
"ApiKey": "b7f3e8a1-4c2d-4d9f-9a6e-2a1c5d7f8e9a"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RunAsWindowsService": true,
|
||||||
|
"Kestrel": {
|
||||||
|
"Endpoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://*:5000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ApiSettings": {
|
||||||
|
"ApiKey": "b7f3e8a1-4c2d-4d9f-9a6e-2a1c5d7f8e9a"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RunAsWindowsService": true,
|
||||||
|
"Kestrel": {
|
||||||
|
"Endpoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://*:5000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ApiSettings": {
|
||||||
|
"ApiKey": "b7f3e8a1-4c2d-4d9f-9a6e-2a1c5d7f8e9a"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user