lith 5 жил өмнө
parent
commit
f7acd65490

+ 5 - 0
dotnet/Doc/UpgradeLog/Sers2.1.1.txt

@@ -92,4 +92,9 @@ ServiceCenter
 修改WebHost StaticFiles配置
 
 [tag]Sers2.1.1.304
+------------------------------------------------------------------------------------------------------------------
+服务中心添加按照服务站点统计qps功能
+
+
+tag]Sers2.1.1.316
 ------------------------------------------------------------------------------------------------------------------

+ 1 - 1
dotnet/Sers/Sers.ServiceCenter/Sers.Gover/Base/Model/ApiStationData.cs

@@ -65,7 +65,7 @@ namespace Sers.Gover.Base.Model
         /// 
         /// </summary>
         [JsonProperty]
-        public float qps { get; private set; } = -1;
+        public float qps { get; private set; } = 0;
 
         private DateTime? qps_TimeLast = null;
         private int qps_SumCountLast = 0;

+ 3 - 0
dotnet/Sers/Sers.ServiceCenter/Sers.Gover/Base/Model/ServiceStationData.cs

@@ -31,8 +31,11 @@ namespace Sers.Gover.Base.Model
 
         public Counter counter;
 
+        public float qps;
+
         public int apiNodeCount;
         public int activeApiNodeCount;
         public List<string> apiStationNames;
+
     }
 }

+ 2 - 1
dotnet/Sers/Sers.ServiceCenter/Sers.Gover/Base/ServiceStationMng.cs

@@ -29,7 +29,7 @@ namespace Sers.Gover.Base
         /// <summary>
         ///  serviceStationKey 和 服务站点 的映射
         /// </summary>
-        ConcurrentDictionary<string, ServiceStation> serviceStationKey_Map = new ConcurrentDictionary<string, ServiceStation>();
+        internal readonly ConcurrentDictionary<string, ServiceStation> serviceStationKey_Map = new ConcurrentDictionary<string, ServiceStation>();
 
 
         public void PublishUsageInfo(EnvUsageInfo item)
@@ -55,6 +55,7 @@ namespace Sers.Gover.Base
                     status = "" + m.Status_Get(),
                     usageStatus = m.usageStatus,
                     counter = m.counter,
+                    qps=m.qps,
                     apiNodeCount = m.apiNodes.Count,
                     activeApiNodeCount = m.ActiveApiNodeCount_Get(),
                     apiStationNames = m.ApiStationNames_Get()

+ 15 - 1
dotnet/Sers/Sers.ServiceCenter/Sers.Gover/Extensions/ServiceCenter_GoverExtensions.cs

@@ -35,6 +35,7 @@ namespace Vit.Extensions
         static int SaveToFile_tick = 0;
         static void QpsTimer_Calc()
         {
+            //(x.1)计算ApiStation qps
             try
             {
                 foreach (var item in GoverManage.Instance.ApiStation_GetAll())
@@ -47,7 +48,20 @@ namespace Vit.Extensions
                 Logger.Error(ex);
             }
 
-          
+            //(x.2)计算ServiceStation qps
+            try
+            {
+                foreach (var item in GoverManage.Instance.serviceStationMng.serviceStationKey_Map.Values)
+                {
+                    item.QpsCalc();
+                }
+            }
+            catch (System.Exception ex)
+            {
+                Logger.Error(ex);
+            }
+
+            //(x.3)按需保存计数信息到文件
             try
             {
                 SaveToFile_tick++;

+ 2 - 1
dotnet/Sers/Sers.ServiceCenter/Sers.Gover/Sers.Gover.csproj

@@ -1,7 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netstandard2.0</TargetFramework>  
+    <TargetFramework>netstandard2.0</TargetFramework>
+    <Version>2.1.1.315</Version>
   </PropertyGroup>
 
   <PropertyGroup>

+ 25 - 0
dotnet/Sers/Sers.ServiceCenter/Sers.ServiceCenter/Entity/ServiceStation.cs

@@ -65,6 +65,31 @@ namespace Sers.ServiceCenter.Entity
         #endregion
 
 
+
+        #region QpsCacl
+        /// <summary>
+        /// 
+        /// </summary>
+        [JsonProperty]
+        public float qps { get; private set; } = 0;
+
+        private DateTime? qps_TimeLast = null;
+        private int qps_SumCountLast = 0;
+        public void QpsCalc()
+        {
+            var curSumCount = counter.sumCount;
+            var curTime = DateTime.Now;
+            if (qps_TimeLast != null)
+            {
+                qps = ((int)(100000.0f * (curSumCount - qps_SumCountLast) / (curTime - qps_TimeLast.Value).TotalMilliseconds)) / 100f;
+            }
+            qps_TimeLast = curTime;
+            qps_SumCountLast = curSumCount;
+        }
+        #endregion
+
+
+
         public string GetApiStationNames()
         {
             var stationNames = apiNodes.Select(m => m.apiDesc.ApiStationNameGet());

+ 1 - 0
dotnet/Sers/Sers.ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter.csproj

@@ -2,6 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
+    <Version>2.1.1.315</Version>
   </PropertyGroup>
 
 

+ 16 - 7
dotnet/netcore/ServiceCenter/App.Gover.Gateway/wwwroot/_gover_/ApiStationMng.html

@@ -23,10 +23,11 @@
 <body>
 
     <h1>Api站点管理</h1>
-
+    <a href="#" onclick="apiStationFilter=null;reloadStations();" title="显示所有的Api站点">显示所有</a> 
+    <a href="#" onclick="apiStationFilter=apiStationFilter_OnlyOnline;reloadStations();" title="仅显示在线的Api站点(apiNodeCount不为0)(默认为仅显示在线)">仅显示在线</a>
     <div id="stations">
 
-        <div v-for="station in stations" style="width:300px;height:400px; float:left;margin:2px;padding:4px;word-wrap:break-word;" class="line">
+        <div v-for="station in stations" style="width:300px;height:250px; float:left;margin:2px;padding:4px;word-wrap:break-word;" class="line">
             {{station.stationName}}     <br />
             calledCount  err/sum:  {{(station.counter||{}).errorCount}}/ {{(station.counter||{}).sumCount}}<br />
             qps:{{station.qps}}     <br />
@@ -60,18 +61,26 @@
         });
 
 
-        function rendStations() {
-            sers.apiClient.apiStation_getAll(function (data) {
-                stations.stations = data.data;
+        function apiStationFilter_OnlyOnline(apiStations) {
+            return apiStations.filter(function (item) { return item.apiNodeCount; });
+        }
+
+        var apiStationFilter = apiStationFilter_OnlyOnline;
+
+        function reloadStations() {
+            sers.apiClient.apiStation_getAll(function (apiRet) {
+                var apiStations = apiRet.data;
+                if (apiStationFilter) apiStations = apiStationFilter(apiStations);
+                stations.stations = apiStations;
             });
         }
 
-        rendStations();
+        reloadStations();
 
 
         var intervals = [];
         function startRefreshTask() {
-            var interval = setInterval(rendStations, 2000);
+            var interval = setInterval(reloadStations, 2000);
             intervals.push(interval);
         }
         function stopRefreshTask() {

+ 2 - 0
dotnet/netcore/ServiceCenter/App.Gover.Gateway/wwwroot/_gover_/ServiceStationMng.html

@@ -34,6 +34,7 @@
             状态:{{station.status}}(正常、暂停)<br />
             操作:  <a href="#" @click="start(station)">打开</a>   <a href="#" @click="pause(station)">暂停</a>  <a href="#" @click="stop(station)">强制关闭</a> <br />
             -----------------------<br />
+            qps:{{station.qps}} <br />
             apiNodeCount:{{station.apiNodeCount}} <br />
             activeApiNodeCount:{{station.activeApiNodeCount}}     <br />
             calledCount  err/sum:  {{(station.counter||{}).errorCount}}/ {{(station.counter||{}).sumCount}}<br />
@@ -56,6 +57,7 @@
                     <td>  <font :title="station.connKey">{{(station.connKey||'').substr(0,4) }} </font></td>
                 </tr>
             </table>
+            st
             <br /> <!--{{station.deviceInfo}}-->
         </div>