Info.cshtml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.AspNetCore.Mvc.RazorPages;
  3. using System.Diagnostics;
  4. using System.Management;
  5. using System.Runtime.InteropServices;
  6. namespace Admin.Areas.Identity.Pages.Server;
  7. public class InfoModel : PageModel
  8. {
  9. private readonly IHostEnvironment _env;
  10. // 앱, 호스트(Host)
  11. public required string EnvironmentName { get; set; }
  12. public required string ContentRootPath { get; set; }
  13. public required string ApplicationName { get; set; }
  14. // OS, Framework
  15. public required string OSDescription { get; set; }
  16. public required string OSArchitecture { get; set; }
  17. public required string FrameworkDescription { get; set; }
  18. public required string ProcessArchitecture { get; set; }
  19. public long WorkingSet { get; set; }
  20. public TimeSpan TotalCpuTime { get; set; }
  21. // 시스템
  22. public required string MachineName { get; set; }
  23. public required string CurrentDirectory { get; set; }
  24. public required string SystemDirectory { get; set; }
  25. public bool Is64BitOperatingSystem { get; set; }
  26. public bool Is64BitProcess { get; set; }
  27. public int ProcessorCount { get; set; }
  28. public required string TickCount { get; set; }
  29. public ManagementObjectCollection? CPU { get; private set; }
  30. public ManagementObjectCollection? Memory { get; private set; }
  31. public ManagementObjectCollection? Disk { get; private set; }
  32. public InfoModel(IHostEnvironment env)
  33. {
  34. _env = env;
  35. }
  36. public async Task<IActionResult> OnGetAsync()
  37. {
  38. var process = Process.GetCurrentProcess();
  39. // 앱, 호스트(Host) 관련
  40. EnvironmentName = _env.EnvironmentName;
  41. ContentRootPath = _env.ContentRootPath;
  42. ApplicationName = _env.ApplicationName;
  43. // OS, Framework 관련
  44. OSDescription = RuntimeInformation.OSDescription;
  45. OSArchitecture = RuntimeInformation.OSArchitecture.ToString();
  46. FrameworkDescription = RuntimeInformation.FrameworkDescription;
  47. ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString();
  48. WorkingSet = process.WorkingSet64 / 1048576; // 물리 메모리 사용량(바이트)
  49. TotalCpuTime = process.TotalProcessorTime; // 프로세스 실행 시간
  50. // 시스템(환경변수) 관련
  51. MachineName = Environment.MachineName;
  52. CurrentDirectory = Environment.CurrentDirectory;
  53. SystemDirectory = Environment.SystemDirectory;
  54. Is64BitOperatingSystem = Environment.Is64BitOperatingSystem;
  55. Is64BitProcess = Environment.Is64BitProcess;
  56. ProcessorCount = Environment.ProcessorCount;
  57. // 시작 시각 등
  58. TickCount = TimeSpan.FromMicroseconds(Environment.TickCount).ToString(); // 시스템 시작 후 경과 시간(밀리초)
  59. // 플랫폼 조건부 코드로 Windows에서만 실행되도록 수정
  60. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  61. {
  62. // CPU 정보
  63. CPU = new ManagementObjectSearcher("select * from Win32_Processor").Get();
  64. // 메모리 정보
  65. Memory = new ManagementObjectSearcher("select * from Win32_MemoryDevice").Get();
  66. // 디스크 정보
  67. Disk = new ManagementObjectSearcher("select * from Win32_DiskDrive").Get();
  68. }
  69. return Page();
  70. }
  71. }