浏览代码

dashboard优化

懒得勤快 4 年之前
父节点
当前提交
8f24d3d6da

+ 2 - 2
src/Masuit.MyBlogs.Core/Common/PerfCounter.cs

@@ -42,7 +42,7 @@ namespace Masuit.MyBlogs.Core.Common
 
         public static PerformanceCounter GetCurrentPerformanceCounter()
         {
-            var time = DateTime.Now.GetTotalMilliseconds(); // - 28800000;
+            var time = (long)DateTime.Now.GetTotalMilliseconds();
             float load = SystemInfo.CpuLoad;
             var mem = (1 - SystemInfo.MemoryAvailable.ConvertTo<float>() / SystemInfo.PhysicalMemory.ConvertTo<float>()) * 100;
 
@@ -72,7 +72,7 @@ namespace Masuit.MyBlogs.Core.Common
             /// <summary>
             /// 当前时间戳
             /// </summary>
-            public double Time { get; set; }
+            public long Time { get; set; }
 
             /// <summary>
             /// CPU当前负载

+ 8 - 21
src/Masuit.MyBlogs.Core/Controllers/SystemController.cs

@@ -31,7 +31,6 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// 系统设置
         /// </summary>
         public ISystemSettingService SystemSettingService { get; set; }
-
         public IFirewallRepoter FirewallRepoter { get; set; }
         public IMailSender MailSender { get; set; }
 
@@ -46,32 +45,32 @@ namespace Masuit.MyBlogs.Core.Controllers
                 cpu = PerfCounter.List.Select(c => new[]
                 {
                     c.Time,
-                    c.CpuLoad
+                    c.CpuLoad.ConvertTo<long>()
                 }),
                 mem = PerfCounter.List.Select(c => new[]
                 {
                     c.Time,
-                    c.MemoryUsage
+                    c.MemoryUsage.ConvertTo<long>()
                 }),
                 read = PerfCounter.List.Select(c => new[]
                 {
                     c.Time,
-                    c.DiskRead
+                    c.DiskRead.ConvertTo<long>()
                 }),
                 write = PerfCounter.List.Select(c => new[]
                 {
                     c.Time,
-                    c.DiskWrite
+                    c.DiskWrite.ConvertTo<long>()
                 }),
                 down = PerfCounter.List.Select(c => new[]
                 {
                     c.Time,
-                    c.Download
+                    c.Download.ConvertTo<long>()
                 }),
                 up = PerfCounter.List.Select(c => new[]
                 {
                     c.Time,
-                    c.Upload
+                    c.Upload.ConvertTo<long>()
                 })
             });
         }
@@ -90,18 +89,6 @@ namespace Masuit.MyBlogs.Core.Controllers
             return ResultData(list);
         }
 
-        ///// <summary>
-        ///// 获取设置项
-        ///// </summary>
-        ///// <param name="name"></param>
-        ///// <returns></returns>
-        //[AllowAnonymous]
-        //public ActionResult GetSetting(string name)
-        //{
-        //    var entity = SystemSettingService.Get(s => s.Name.Equals(name));
-        //    return ResultData(entity);
-        //}
-
         /// <summary>
         /// 保存设置
         /// </summary>
@@ -346,7 +333,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return ResultData(null, false);
             }
 
-            var basedir = AppDomain.CurrentDomain.BaseDirectory ?? Environment.CurrentDirectory;
+            var basedir = AppDomain.CurrentDomain.BaseDirectory;
             string ips = await System.IO.File.ReadAllTextAsync(Path.Combine(basedir, "App_Data", "whitelist.txt"));
             List<string> list = ips.Split(',').Where(s => !string.IsNullOrEmpty(s)).ToList();
             list.Add(ip);
@@ -368,7 +355,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             }
 
             CommonHelper.DenyIP += "," + ip;
-            var basedir = AppDomain.CurrentDomain.BaseDirectory ?? Environment.CurrentDirectory;
+            var basedir = AppDomain.CurrentDomain.BaseDirectory;
             await System.IO.File.WriteAllTextAsync(Path.Combine(basedir, "App_Data", "denyip.txt"), CommonHelper.DenyIP, Encoding.UTF8);
             CommonHelper.IPWhiteList.Remove(ip);
             await System.IO.File.WriteAllTextAsync(Path.Combine(basedir, "App_Data", "whitelist.txt"), string.Join(",", CommonHelper.IPWhiteList.Distinct()), Encoding.UTF8);

+ 2 - 0
src/Masuit.MyBlogs.Core/Views/Dashboard/Counter.cshtml

@@ -9,6 +9,7 @@
 <head>
     <title>服务器性能监控</title>
     <link href="https://cdn.staticfile.org/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
+    <link href="https://cdn.staticfile.org/limonte-sweetalert2/6.6.9/sweetalert2.min.css" rel="stylesheet">
 </head>
 <body>
     <div class="container-fluid">
@@ -16,6 +17,7 @@
     </div>
     <script src="/_framework/blazor.server.js"></script>
     <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
+    <script src="https://cdn.staticfile.org/limonte-sweetalert2/6.6.10/sweetalert2.min.js"></script>
     <script src="~/Scripts/global/counter.js"></script>
 </body>
 </html>

+ 7 - 0
src/Masuit.MyBlogs.Core/Views/Dashboard/Counter.razor

@@ -68,6 +68,7 @@
         </tr>
     </tbody>
 </table>
+    <button class="btn btn-success" @onclick="ClearMemory">整理内存</button>
 <div>
     <div class="page-header">
         <h3 class="text-center">性能实时监控</h3>
@@ -105,4 +106,10 @@
     {
         return PerfCounter.GetCurrentPerformanceCounter();
     }
+
+    public void ClearMemory()
+    {
+        Windows.ClearMemorySilent();
+        JS.InvokeVoidAsync("showSuccess");
+    }
 }

+ 38 - 34
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/counter.js

@@ -75,27 +75,40 @@ function showIO(data) {
         },
         dataZoom: [{
                 type: 'inside',
-                start: 90,
+                start: 70,
                 end: 100,
-                minValueSpan: 50
+                minValueSpan: 100
             }, {
-                start: 90,
+                start: 70,
                 end: 100,
-                minValueSpan: 50
+                minValueSpan: 100
             }],
         xAxis: {
             type: 'time',
+            interval: 20000,
+            axisLabel: {
+                formatter:function (value){
+                    var dt=new Date(value);
+                    return dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds()
+                }
+            },
             splitLine: {
                 show: false
             }
         },
         yAxis: [{
                 name: '磁盘',
-                type: 'value'
+                type: 'value',
+                splitLine: {
+                    show: false
+                }
             },
             {
                 name: '网络',
-                type: 'value'
+                type: 'value',
+                splitLine: {
+                    show: false
+                }
             }
         ],
         legend: {
@@ -106,47 +119,27 @@ function showIO(data) {
                 type: 'line',
                 showSymbol: false,
                 hoverAnimation: false,
-                data: data.read,
-                markLine: {
-                    data: [
-                        { type: 'average', name: '磁盘读平均值' }
-                    ]
-                }
+                data: data.read
             }, {
                 name: '磁盘写(KBps)',
                 type: 'line',
                 showSymbol: false,
                 hoverAnimation: false,
-                data: data.write,
-                markLine: {
-                    data: [
-                        { type: 'average', name: '磁盘写平均值' }
-                    ]
-                }
+                data: data.write
             }, {
                 name: '网络上行(KBps)',
                 yAxisIndex: 1,
                 type: 'line',
                 showSymbol: false,
                 hoverAnimation: false,
-                data: data.up,
-                markLine: {
-                    data: [
-                        { type: 'average', name: '上行平均值' }
-                    ]
-                }
+                data: data.up
             }, {
                 name: '网络下行(KBps)',
                 yAxisIndex: 1,
                 type: 'line',
                 showSymbol: false,
                 hoverAnimation: false,
-                data: data.down,
-                markLine: {
-                    data: [
-                        { type: 'average', name: '下行平均值' }
-                    ]
-                }
+                data: data.down
             }]
     });
     return myChart;
@@ -176,16 +169,23 @@ function showLine() {
             },
             dataZoom: [{
                     type: 'inside',
-                    start: 90,
+                    start: 70,
                     end: 100,
-                    minValueSpan: 50
+                    minValueSpan: 100
                 }, {
-                    start: 90,
+                    start: 70,
                     end: 100,
-                    minValueSpan: 50
+                    minValueSpan: 100
                 }],
             xAxis: {
                 type: 'time',
+                interval: 20000,
+                axisLabel: {
+                    formatter:function (value){
+                        var dt=new Date(value);
+                        return dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds()
+                    }
+                  },
                 splitLine: {
                     show: false
                 }
@@ -274,4 +274,8 @@ function showLine() {
     }).catch(function(e) {
         console.error(e);
     });
+}
+
+function showSuccess() {
+    swal({ type: 'success', html: "操作成功" });
 }