This commit is contained in:
Phoenix
2024-12-27 10:10:43 +08:00
30 changed files with 98 additions and 21 deletions
+37 -2
View File
@@ -66,12 +66,47 @@ namespace ResourceMonitorService
}; };
} }
private float GetCpuUsage() private object GetCpuUsage()
{ {
var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuCounter.NextValue(); cpuCounter.NextValue();
Thread.Sleep(1000); // Wait a second to get a valid reading Thread.Sleep(1000); // Wait a second to get a valid reading
return cpuCounter.NextValue();
var usage = cpuCounter.NextValue();
if (usage > 80)
{
// Get the current processes and sort them by CPU usage in descending order
var processes = Process.GetProcesses().OrderByDescending(p => p.TotalProcessorTime);
// Create a new anonymous type containing the CPU usage, RAM usage, and the top 3 highest CPU-using processes
return new
{
Usage = usage,
Process1 = new
{
Name = processes.ElementAt(0).ProcessName,
TotalProcessorTime = processes.ElementAt(0).TotalProcessorTime,
WorkingSet64 = processes.ElementAt(0).WorkingSet64 / (1024 * 1024) // Convert to MB
},
Process2 = new
{
Name = processes.ElementAt(1).ProcessName,
TotalProcessorTime = processes.ElementAt(1).TotalProcessorTime,
WorkingSet64 = processes.ElementAt(1).WorkingSet64 / (1024 * 1024) // Convert to MB
},
Process3 = new
{
Name = processes.ElementAt(2).ProcessName,
TotalProcessorTime = processes.ElementAt(2).TotalProcessorTime,
WorkingSet64 = processes.ElementAt(2).WorkingSet64 / (1024 * 1024) // Convert to MB
}
};
}
return new
{
Usage = usage
};
} }
private float GetRamUsage() private float GetRamUsage()
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://localhost:5000" "Url": "http://*:5000"
} }
} }
} }
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://localhost:5000" "Url": "http://*:5000"
} }
} }
} }
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://*:5000" "Url": "http://localhost:5000"
} }
} }
} }
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://*:5000" "Url": "http://localhost:5000"
} }
} }
} }
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ResourceMonitorService")] [assembly: System.Reflection.AssemblyCompanyAttribute("ResourceMonitorService")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7dc90104512834ceb810324f20a2b5d12de354c0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+297c90d55ddfc8f23ee02a37dcab1ed38a5bd12a")]
[assembly: System.Reflection.AssemblyProductAttribute("ResourceMonitorService")] [assembly: System.Reflection.AssemblyProductAttribute("ResourceMonitorService")]
[assembly: System.Reflection.AssemblyTitleAttribute("ResourceMonitorService")] [assembly: System.Reflection.AssemblyTitleAttribute("ResourceMonitorService")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
1212cb7eab016db3876a66a85bc18562ffabead52c3b48120f48f729d68cf190 b331d637528b151c24189432c7e86019209ffeb58d10eec2b534d742e683f465
@@ -17,6 +17,14 @@ D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json D:\din\dev\vmsvc\ResourceMonitorService\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ResourceMonitorService")] [assembly: System.Reflection.AssemblyCompanyAttribute("ResourceMonitorService")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f16578d19a39c4688f17fdac49af6472a49fec57")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7dc90104512834ceb810324f20a2b5d12de354c0")]
[assembly: System.Reflection.AssemblyProductAttribute("ResourceMonitorService")] [assembly: System.Reflection.AssemblyProductAttribute("ResourceMonitorService")]
[assembly: System.Reflection.AssemblyTitleAttribute("ResourceMonitorService")] [assembly: System.Reflection.AssemblyTitleAttribute("ResourceMonitorService")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
775fabb90a6c4c2ade72fe6bb97d7187c0bca0ffc636f7a7f1f46fc245002ac5 608e465b7ba84317d117e2f91b1dd0cbc27eb989794e186fbb1d28e072618ae2
@@ -62,3 +62,11 @@ D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publi
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Release\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
{ {
"format": 1, "format": 1,
"restore": { "restore": {
<<<<<<< HEAD
"C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj": {} "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj": {}
}, },
"projects": { "projects": {
@@ -12,6 +13,19 @@
"projectPath": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj", "projectPath": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\", "packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\",
"outputPath": "C:\\Work\\DEV\\ResourceUsageAPI\\obj\\", "outputPath": "C:\\Work\\DEV\\ResourceUsageAPI\\obj\\",
=======
"C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj": {}
},
"projects": {
"C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectName": "ResourceMonitorService",
"projectPath": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\",
"outputPath": "C:\\din\\dev\\ResourceUsageAPI\\obj\\",
>>>>>>> 28da999de06ef6db877e7001bd19f327db1d0910
"projectStyle": "PackageReference", "projectStyle": "PackageReference",
"configFilePaths": [ "configFilePaths": [
"C:\\Users\\dinxs\\AppData\\Roaming\\NuGet\\NuGet.Config" "C:\\Users\\dinxs\\AppData\\Roaming\\NuGet\\NuGet.Config"
+8
View File
@@ -2087,11 +2087,19 @@
"project": { "project": {
"version": "1.0.0", "version": "1.0.0",
"restore": { "restore": {
<<<<<<< HEAD
"projectUniqueName": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj", "projectUniqueName": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectName": "ResourceMonitorService", "projectName": "ResourceMonitorService",
"projectPath": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj", "projectPath": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\", "packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\",
"outputPath": "C:\\Work\\DEV\\ResourceUsageAPI\\obj\\", "outputPath": "C:\\Work\\DEV\\ResourceUsageAPI\\obj\\",
=======
"projectUniqueName": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectName": "ResourceMonitorService",
"projectPath": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\",
"outputPath": "C:\\din\\dev\\ResourceUsageAPI\\obj\\",
>>>>>>> 28da999de06ef6db877e7001bd19f327db1d0910
"projectStyle": "PackageReference", "projectStyle": "PackageReference",
"configFilePaths": [ "configFilePaths": [
"C:\\Users\\dinxs\\AppData\\Roaming\\NuGet\\NuGet.Config" "C:\\Users\\dinxs\\AppData\\Roaming\\NuGet\\NuGet.Config"
+6
View File
@@ -1,8 +1,14 @@
{ {
"version": 2, "version": 2,
<<<<<<< HEAD
"dgSpecHash": "21qKVFLqEJQ=", "dgSpecHash": "21qKVFLqEJQ=",
"success": true, "success": true,
"projectFilePath": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj", "projectFilePath": "C:\\Work\\DEV\\ResourceUsageAPI\\ResourceMonitorService.csproj",
=======
"dgSpecHash": "c9QUeYvHFTQ=",
"success": true,
"projectFilePath": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
>>>>>>> 28da999de06ef6db877e7001bd19f327db1d0910
"expectedPackageFiles": [ "expectedPackageFiles": [
"C:\\Users\\dinxs\\.nuget\\packages\\microsoft.aspnetcore.jsonpatch\\9.0.0\\microsoft.aspnetcore.jsonpatch.9.0.0.nupkg.sha512", "C:\\Users\\dinxs\\.nuget\\packages\\microsoft.aspnetcore.jsonpatch\\9.0.0\\microsoft.aspnetcore.jsonpatch.9.0.0.nupkg.sha512",
"C:\\Users\\dinxs\\.nuget\\packages\\microsoft.aspnetcore.mvc.newtonsoftjson\\9.0.0\\microsoft.aspnetcore.mvc.newtonsoftjson.9.0.0.nupkg.sha512", "C:\\Users\\dinxs\\.nuget\\packages\\microsoft.aspnetcore.mvc.newtonsoftjson\\9.0.0\\microsoft.aspnetcore.mvc.newtonsoftjson.9.0.0.nupkg.sha512",
Binary file not shown.
Binary file not shown.
Binary file not shown.
+5 -7
View File
@@ -1,10 +1,8 @@
# PowerShell script to create a new inbound rule in Windows Firewall # PowerShell script to create a new inbound rule in Windows Firewall
# Define the port number
$port = 5000 $port = 5000
# Define the rule name
$ruleName = "ResourceMonitorService" $ruleName = "ResourceMonitorService"
if (Get-NetFirewallRule -DisplayName $ruleName) {
# Create a new inbound rule Write-Host "Rule already exists, not creating a new one"
New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Protocol TCP -LocalPort $port -Action Allow -Profile Any } else {
New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Protocol TCP -LocalPort $port -Action Allow -Profile Any
}
+1 -1
View File
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://localhost:5000" "Url": "http://*:5000"
} }
} }
} }
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://localhost:5000" "Url": "http://*:5000"
} }
} }
} }
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://*:5000" "Url": "http://localhost:5000"
} }
} }
} }
@@ -9,7 +9,7 @@
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {
"Url": "http://*:5000" "Url": "http://localhost:5000"
} }
} }
} }