SysServerService.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
  2. //
  3. // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
  4. //
  5. // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
  6. using AlibabaCloud.SDK.Dysmsapi20170525.Models;
  7. using AngleSharp.Html.Parser;
  8. using AspNet.Security.OAuth.Gitee;
  9. using AspNet.Security.OAuth.Weixin;
  10. using AspNetCoreRateLimit;
  11. using Elastic.Clients.Elasticsearch;
  12. using IPTools.Core;
  13. using Lazy.Captcha.Core;
  14. using Magicodes.ExporterAndImporter.Pdf;
  15. using Magicodes.ExporterAndImporter.Word;
  16. using MailKit.Net.Smtp;
  17. using Novell.Directory.Ldap;
  18. using OnceMi.AspNetCore.OSS;
  19. using QRCoder;
  20. namespace Admin.NET.Core.Service;
  21. /// <summary>
  22. /// 系统服务器监控服务 🧩
  23. /// </summary>
  24. [ApiDescriptionSettings(Order = 290)]
  25. public class SysServerService : IDynamicApiController, ITransient
  26. {
  27. public SysServerService()
  28. {
  29. }
  30. /// <summary>
  31. /// 获取服务器配置信息 🔖
  32. /// </summary>
  33. /// <returns></returns>
  34. [DisplayName("获取服务器配置信息")]
  35. public dynamic GetServerBase()
  36. {
  37. return new
  38. {
  39. HostName = Environment.MachineName, // 主机名称
  40. SystemOs = ComputerUtil.GetOSInfo(),//RuntimeInformation.OSDescription, // 操作系统
  41. OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(), // 系统架构
  42. ProcessorCount = Environment.ProcessorCount + " 核", // CPU核心数
  43. SysRunTime = ComputerUtil.GetRunTime(), // 系统运行时间
  44. RemoteIp = ComputerUtil.GetIpFromOnline(), // 外网地址
  45. LocalIp = App.HttpContext?.Connection?.LocalIpAddress.ToString(), // 本地地址
  46. RuntimeInformation.FrameworkDescription, // NET框架
  47. Environment = App.HostEnvironment.IsDevelopment() ? "Development" : "Production",
  48. Wwwroot = App.WebHostEnvironment.WebRootPath, // 网站根目录
  49. Stage = App.HostEnvironment.IsStaging() ? "Stage环境" : "非Stage环境", // 是否Stage环境
  50. };
  51. }
  52. /// <summary>
  53. /// 获取服务器使用信息 🔖
  54. /// </summary>
  55. /// <returns></returns>
  56. [DisplayName("获取服务器使用信息")]
  57. public dynamic GetServerUsed()
  58. {
  59. var programStartTime = Process.GetCurrentProcess().StartTime;
  60. var totalMilliseconds = (DateTime.Now - programStartTime).TotalMilliseconds.ToString();
  61. var ts = totalMilliseconds.Contains('.') ? totalMilliseconds.Split('.')[0] : totalMilliseconds;
  62. var programRunTime = DateTimeUtil.FormatTime(ts.ParseToLong());
  63. var memoryMetrics = ComputerUtil.GetComputerInfo();
  64. return new
  65. {
  66. memoryMetrics.FreeRam, // 空闲内存
  67. memoryMetrics.UsedRam, // 已用内存
  68. memoryMetrics.TotalRam, // 总内存
  69. memoryMetrics.RamRate, // 内存使用率
  70. memoryMetrics.CpuRate, // Cpu使用率
  71. StartTime = programStartTime.ToString("yyyy-MM-dd HH:mm:ss"), // 服务启动时间
  72. RunTime = programRunTime, // 服务运行时间
  73. };
  74. }
  75. /// <summary>
  76. /// 获取服务器磁盘信息 🔖
  77. /// </summary>
  78. /// <returns></returns>
  79. [DisplayName("获取服务器磁盘信息")]
  80. public dynamic GetServerDisk()
  81. {
  82. return ComputerUtil.GetDiskInfos();
  83. }
  84. /// <summary>
  85. /// 获取框架主要程序集 🔖
  86. /// </summary>
  87. /// <returns></returns>
  88. [DisplayName("获取框架主要程序集")]
  89. public dynamic GetAssemblyList()
  90. {
  91. var furionAssembly = typeof(App).Assembly.GetName();
  92. var sqlSugarAssembly = typeof(ISqlSugarClient).Assembly.GetName();
  93. var yitIdAssembly = typeof(YitIdHelper).Assembly.GetName();
  94. var redisAssembly = typeof(Redis).Assembly.GetName();
  95. var jsonAssembly = typeof(NewtonsoftJsonMvcCoreBuilderExtensions).Assembly.GetName();
  96. var excelAssembly = typeof(IExcelImporter).Assembly.GetName();
  97. var pdfAssembly = typeof(IPdfExporter).Assembly.GetName();
  98. var wordAssembly = typeof(IWordExporter).Assembly.GetName();
  99. var captchaAssembly = typeof(ICaptcha).Assembly.GetName();
  100. var wechatApiAssembly = typeof(WechatApiClient).Assembly.GetName();
  101. var wechatTenpayAssembly = typeof(WechatTenpayClient).Assembly.GetName();
  102. var ossAssembly = typeof(IOSSServiceFactory).Assembly.GetName();
  103. var parserAssembly = typeof(Parser).Assembly.GetName();
  104. var elasticsearchClientAssembly = typeof(ElasticsearchClient).Assembly.GetName();
  105. var limitAssembly = typeof(IpRateLimitMiddleware).Assembly.GetName();
  106. var htmlParserAssembly = typeof(HtmlParser).Assembly.GetName();
  107. var fluentEmailAssembly = typeof(SmtpClient).Assembly.GetName();
  108. var qRCodeGeneratorAssembly = typeof(QRCodeGenerator).Assembly.GetName();
  109. var sendSmsRequestAssembly = typeof(SendSmsRequest).Assembly.GetName();
  110. var imageAssembly = typeof(Image).Assembly.GetName();
  111. var rabbitMQAssembly = typeof(RabbitMQEventSourceStore).Assembly.GetName();
  112. var ldapConnectionAssembly = typeof(LdapConnection).Assembly.GetName();
  113. var ipToolAssembly = typeof(IpTool).Assembly.GetName();
  114. var weixinAuthenticationOptionsAssembly = typeof(WeixinAuthenticationOptions).Assembly.GetName();
  115. var giteeAuthenticationOptionsAssembly = typeof(GiteeAuthenticationOptions).Assembly.GetName();
  116. return new[]
  117. {
  118. new { furionAssembly.Name, furionAssembly.Version },
  119. new { sqlSugarAssembly.Name, sqlSugarAssembly.Version },
  120. new { yitIdAssembly.Name, yitIdAssembly.Version },
  121. new { redisAssembly.Name, redisAssembly.Version },
  122. new { jsonAssembly.Name, jsonAssembly.Version },
  123. new { excelAssembly.Name, excelAssembly.Version },
  124. new { pdfAssembly.Name, pdfAssembly.Version },
  125. new { wordAssembly.Name, wordAssembly.Version },
  126. new { captchaAssembly.Name, captchaAssembly.Version },
  127. new { wechatApiAssembly.Name, wechatApiAssembly.Version },
  128. new { wechatTenpayAssembly.Name, wechatTenpayAssembly.Version },
  129. new { ossAssembly.Name, ossAssembly.Version },
  130. new { parserAssembly.Name, parserAssembly.Version },
  131. new { elasticsearchClientAssembly.Name, elasticsearchClientAssembly.Version },
  132. new { limitAssembly.Name, limitAssembly.Version },
  133. new { htmlParserAssembly.Name, htmlParserAssembly.Version },
  134. new { fluentEmailAssembly.Name, fluentEmailAssembly.Version },
  135. new { qRCodeGeneratorAssembly.Name, qRCodeGeneratorAssembly.Version },
  136. new { sendSmsRequestAssembly.Name, sendSmsRequestAssembly.Version },
  137. new { imageAssembly.Name, imageAssembly.Version },
  138. new { rabbitMQAssembly.Name, rabbitMQAssembly.Version },
  139. new { ldapConnectionAssembly.Name, ldapConnectionAssembly.Version },
  140. new { ipToolAssembly.Name, ipToolAssembly.Version },
  141. new { weixinAuthenticationOptionsAssembly.Name, weixinAuthenticationOptionsAssembly.Version },
  142. new { giteeAuthenticationOptionsAssembly.Name, giteeAuthenticationOptionsAssembly.Version },
  143. };
  144. }
  145. }