ServerController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Diagnostics;
  2. using System.Management;
  3. using System.Runtime.InteropServices;
  4. using Microsoft.AspNetCore.Authorization;
  5. using Microsoft.AspNetCore.Mvc;
  6. using bitforum.Models;
  7. namespace bitforum.Controllers.System
  8. {
  9. [Authorize]
  10. [Route("System")]
  11. public class ServerController : Controller
  12. {
  13. private readonly ILogger<ServerController> _logger;
  14. private readonly IHostEnvironment _env;
  15. public ServerController(ILogger<ServerController> logger, IHostEnvironment env)
  16. {
  17. _logger = logger;
  18. _env = env;
  19. }
  20. [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  21. public IActionResult Error()
  22. {
  23. return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  24. }
  25. [HttpGet("Server")]
  26. public IActionResult Index()
  27. {
  28. var process = Process.GetCurrentProcess();
  29. var info = new
  30. {
  31. // 앱, 호스트(Host) 관련
  32. _env.EnvironmentName,
  33. _env.ContentRootPath,
  34. _env.ApplicationName,
  35. // OS, Framework 관련
  36. RuntimeInformation.OSDescription,
  37. OSArchitecture = RuntimeInformation.OSArchitecture.ToString(),
  38. RuntimeInformation.FrameworkDescription,
  39. ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString(),
  40. WorkingSet = process.WorkingSet64 / 1048576, // 물리 메모리 사용량(바이트)
  41. TotalCpuTime = process.TotalProcessorTime, // 프로세스 실행 시간
  42. // 시스템(환경변수) 관련
  43. Environment.MachineName,
  44. Environment.CurrentDirectory,
  45. Environment.SystemDirectory,
  46. Environment.Is64BitOperatingSystem,
  47. Environment.Is64BitProcess,
  48. Environment.ProcessorCount,
  49. // 시작 시각 등
  50. TickCount = TimeSpan.FromMicroseconds(Environment.TickCount).ToString(), // 시스템 시작 후 경과 시간(밀리초)
  51. };
  52. // CPU 정보
  53. ViewBag.cpu = new ManagementObjectSearcher("select * from Win32_Processor").Get();
  54. // 메모리 정보
  55. ViewBag.memory = new ManagementObjectSearcher("select * from Win32_MemoryDevice").Get();
  56. // 디스크 정보
  57. ViewBag.disk = new ManagementObjectSearcher("select * from Win32_DiskDrive").Get();
  58. ViewBag.Info = info;
  59. return View("~/Views/System/Server.cshtml");
  60. }
  61. }
  62. }