3d47fc1439
- Created ResourceHub.cs for SignalR group management. - Developed a modern web dashboard using Tailwind CSS for responsive design. - Implemented real-time updates with SignalR for CPU, Memory, GPU, and Network usage. - Added REST API endpoints for resource information and process management. - Integrated process management features to view and terminate high-usage processes. - Enhanced UI with loading spinners, notifications, and responsive tables. - Included performance charts for historical CPU and Memory usage. - Configured Swagger UI for API documentation. - Established security features including process kill restrictions and API key authentication.
79 lines
3.0 KiB
C#
79 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using ResourceMonitorService.Configuration;
|
|
using ResourceMonitorService.Services;
|
|
using Serilog;
|
|
using System.Diagnostics;
|
|
|
|
namespace ResourceMonitorService
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
// Configure Serilog early
|
|
Log.Logger = new LoggerConfiguration()
|
|
.WriteTo.Console()
|
|
.WriteTo.File("logs/resourcemonitor-.txt", rollingInterval: RollingInterval.Day)
|
|
.CreateLogger();
|
|
|
|
try
|
|
{
|
|
Log.Information("Starting Resource Monitor Service");
|
|
CreateHostBuilder(args).Build().Run();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Fatal(ex, "Application start-up failed");
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args)
|
|
{
|
|
var builder = Host.CreateDefaultBuilder(args)
|
|
.UseSerilog()
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
webBuilder.UseUrls("http://localhost:5000", "https://localhost:5001");
|
|
})
|
|
.ConfigureServices((hostContext, services) =>
|
|
{
|
|
// Bind configuration sections
|
|
services.Configure<MonitoringSettings>(
|
|
hostContext.Configuration.GetSection("MonitoringSettings"));
|
|
services.Configure<ApiSettings>(
|
|
hostContext.Configuration.GetSection("ApiSettings"));
|
|
services.Configure<LoggingSettings>(
|
|
hostContext.Configuration.GetSection("LoggingSettings"));
|
|
|
|
// Register services
|
|
services.AddSingleton<ISystemInfoService, SystemInfoService>();
|
|
services.AddSingleton<IResourceMonitorService, Services.ResourceMonitorService>();
|
|
services.AddSingleton<IGameDetectionService, GameDetectionService>();
|
|
services.AddSingleton<ITelegramNotificationService, TelegramNotificationService>();
|
|
services.AddSingleton<IAlertService, AlertService>();
|
|
|
|
// Register the main worker service
|
|
services.AddHostedService<Worker>();
|
|
});
|
|
|
|
// Configure as Windows Service if requested
|
|
if (args.Contains("--windows-service") || Environment.GetEnvironmentVariable("RUN_AS_SERVICE") == "true")
|
|
{
|
|
builder.UseWindowsService(options =>
|
|
{
|
|
options.ServiceName = "ResourceMonitorService";
|
|
});
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
}
|
|
} |