ServiceCenterController.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Diagnostics;
  3. using Newtonsoft.Json.Linq;
  4. using Sers.Core.Module.Rpc;
  5. using Sers.Hardware.Usage;
  6. using Sers.SersLoader;
  7. using Sers.SersLoader.ApiDesc.Attribute.Valid;
  8. using Vit.Core.Module.Log;
  9. using Vit.Core.Util.ComponentModel.Api;
  10. using Vit.Core.Util.ComponentModel.Data;
  11. using Vit.Core.Util.ComponentModel.Model;
  12. using Vit.Extensions;
  13. namespace Sers.Gover.Controllers.ApiControllers
  14. {
  15. [SsStationName("_gover_")]
  16. public class ServerCenterController : IApiController
  17. {
  18. [SsRoute("serviceCenter/healthInfo")]
  19. [SsCallerSource(ECallerSource.Internal)]
  20. //[CallFromGover]
  21. [SsName("获取服务中心健康数据")]
  22. public ApiReturn<Object> HealthInfo()
  23. {
  24. JObject healthInfo = new JObject();
  25. //(x.1) usageStatus
  26. healthInfo["usageStatus"] = UsageHelp.GetUsageInfo()?.ConvertBySerialize<JObject>();
  27. //(x.2) Process信息
  28. try
  29. {
  30. var process = Process.GetCurrentProcess();
  31. var processInfo = new JObject();
  32. healthInfo["Process"] = processInfo;
  33. //(x.x.1) threadInfo
  34. processInfo["ThreadCount"] = process.Threads.Count;
  35. int n = 0;
  36. foreach (ProcessThread th in process.Threads)
  37. {
  38. if (th.ThreadState == ThreadState.Running)
  39. n++;
  40. }
  41. processInfo["RunningThreadCount"] = n;
  42. //(x.x.2) memory size
  43. processInfo["WorkingSet"] = (process.WorkingSet64/1024.0/1024).ToString("0.00")+" MB";
  44. }
  45. catch (Exception ex)
  46. {
  47. Logger.Error(ex);
  48. }
  49. return healthInfo;
  50. }
  51. }
  52. }