SysServerService.cs 8.4 KB

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