ServerController.cs 2.6 KB

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