ServiceStation.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Newtonsoft.Json;
  5. using Sers.Core.CL.MessageOrganize;
  6. using Sers.Core.Module.Counter;
  7. using Sers.Core.Module.Env;
  8. using Sers.Core.Module.Message;
  9. using Sers.Hardware.Env;
  10. using Sers.Hardware.Usage;
  11. using Vit.Core.Util.Extensible;
  12. using Vit.Core.Util.Pipelines;
  13. using Vit.Extensions;
  14. namespace Sers.ServiceCenter.Entity
  15. {
  16. /// <summary>
  17. /// 对应一个部署的服务站点
  18. /// </summary>
  19. [JsonObject(MemberSerialization.OptIn)]
  20. public class ServiceStation: Extensible
  21. {
  22. /// <summary>
  23. /// 服务站点开启时间
  24. /// </summary>
  25. [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  26. public DateTime? startTime;
  27. /// <summary>
  28. /// CL通信层连接对象
  29. /// </summary>
  30. [JsonIgnore]
  31. public IOrganizeConnection connection { get; set; }
  32. /// <summary>
  33. /// 站点软硬件环境信息
  34. /// </summary>
  35. [JsonProperty]
  36. public DeviceInfo deviceInfo;
  37. /// <summary>
  38. /// 站点信息。同一硬件可以部署多个站点,它们软硬件环境是一样的,但站点信息不一样。
  39. /// </summary>
  40. [JsonProperty]
  41. public ServiceStationInfo serviceStationInfo;
  42. [JsonProperty]
  43. public List<ApiNode> apiNodes;
  44. /// <summary>
  45. /// 系统当前占用率
  46. /// </summary>
  47. //[JsonProperty]
  48. public UsageStatus usageStatus;
  49. [JsonIgnore]
  50. public string serviceStationKey=> serviceStationInfo?.serviceStationKey;
  51. #region counter
  52. [JsonIgnore]
  53. private Counter _counter;
  54. //[JsonProperty]
  55. public Counter counter { get => (_counter ?? (_counter = new Counter())); set => _counter = value; }
  56. #endregion
  57. #region QpsCacl
  58. /// <summary>
  59. ///
  60. /// </summary>
  61. [JsonProperty]
  62. public float qps { get; private set; } = 0;
  63. private DateTime? qps_TimeLast = null;
  64. private int qps_SumCountLast = 0;
  65. public void QpsCalc()
  66. {
  67. var curSumCount = counter.sumCount;
  68. var curTime = DateTime.Now;
  69. if (qps_TimeLast != null)
  70. {
  71. qps = ((int)(100000.0f * (curSumCount - qps_SumCountLast) / (curTime - qps_TimeLast.Value).TotalMilliseconds)) / 100f;
  72. }
  73. qps_TimeLast = curTime;
  74. qps_SumCountLast = curSumCount;
  75. }
  76. #endregion
  77. public string GetApiStationNames()
  78. {
  79. var stationNames = apiNodes.Select(m => m.apiDesc.ApiStationNameGet());
  80. return String.Join(",", stationNames);
  81. }
  82. public void SendRequestAsync(Object sender, ApiMessage apiReqMessage, Action<object, Vit.Core.Util.Pipelines.ByteData> callback)
  83. {
  84. connection.SendRequestAsync(sender,apiReqMessage.Package(), callback);
  85. }
  86. }
  87. }