Info.cshtml.cs 3.5 KB

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