1
0
懒得勤快 4 жил өмнө
parent
commit
fd2d1c63f0

+ 46 - 43
src/Masuit.MyBlogs.Core/Controllers/SystemController.cs

@@ -6,12 +6,9 @@ using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.Tools;
 using Masuit.Tools.DateTimeExt;
-using Masuit.Tools.Hardware;
 using Masuit.Tools.Logging;
 using Masuit.Tools.Models;
 using Masuit.Tools.Systems;
-using Masuit.Tools.Win32;
-using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
@@ -20,7 +17,6 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Net;
-using System.Net.Sockets;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -40,39 +36,43 @@ namespace Masuit.MyBlogs.Core.Controllers
         public IMailSender MailSender { get; set; }
 
         /// <summary>
-        /// 获取硬件基本信息
+        /// 获取历史性能计数器
         /// </summary>
         /// <returns></returns>
-        public ActionResult GetBaseInfo()
+        public IActionResult GetCounterHistory()
         {
-            var cpuInfo = SystemInfo.GetCpuInfo();
-            var ramInfo = SystemInfo.GetRamInfo();
-            var osVersion = Windows.GetOsVersion();
-            var mac = SystemInfo.GetMacAddress();
-            var ips = SystemInfo.GetLocalIPs().OrderBy(u => u.Address.AddressFamily != AddressFamily.InterNetwork).Select(a => a.Address.ToString()).ToList();
-            var diskTotal = SystemInfo.DiskTotalSpace().Select(kv => kv.Key + kv.Value).Join(" | ");
-            var diskFree = SystemInfo.DiskFree().Select(kv => kv.Key + kv.Value).Join(" | ");
-            var diskUsage = SystemInfo.DiskUsage().Select(kv => kv.Key + kv.Value.ToString("P")).Join(" | ");
-            var span = DateTime.Now - CommonHelper.StartupTime;
-            var boot = DateTime.Now - SystemInfo.BootTime();
-            return Json(new
+            return Ok(new
             {
-                runningTime = $"{span.Days}天{span.Hours}小时{span.Minutes}分钟",
-                bootTime = $"{boot.Days}天{boot.Hours}小时{boot.Minutes}分钟",
-                cpuInfo,
-                ramInfo,
-                osVersion,
-                diskInfo = new
+                cpu = PerfCounter.List.Select(c => new[]
                 {
-                    total = diskTotal,
-                    free = diskFree,
-                    usage = diskUsage
-                },
-                netInfo = new
+                    c.Time,
+                    c.CpuLoad
+                }),
+                mem = PerfCounter.List.Select(c => new[]
                 {
-                    mac,
-                    ips
-                }
+                    c.Time,
+                    c.MemoryUsage
+                }),
+                read = PerfCounter.List.Select(c => new[]
+                {
+                    c.Time,
+                    c.DiskRead
+                }),
+                write = PerfCounter.List.Select(c => new[]
+                {
+                    c.Time,
+                    c.DiskWrite
+                }),
+                down = PerfCounter.List.Select(c => new[]
+                {
+                    c.Time,
+                    c.Download
+                }),
+                up = PerfCounter.List.Select(c => new[]
+                {
+                    c.Time,
+                    c.Upload
+                })
             });
         }
 
@@ -90,17 +90,17 @@ 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>
+        ///// <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>
         /// 保存设置
@@ -213,7 +213,10 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult BounceEmail(string email)
         {
             var msg = MailSender.AddRecipient(email);
-            return Ok(new { msg });
+            return Ok(new
+            {
+                msg
+            });
         }
 
         #region 网站防火墙

+ 1 - 1
src/Masuit.MyBlogs.Core/Extensions/MiddlewareExtension.cs

@@ -76,7 +76,7 @@ namespace Masuit.MyBlogs.Core.Extensions
             services.AddResponseCaching(); //注入响应缓存
             services.Configure<BrotliCompressionProviderOptions>(options =>
             {
-                options.Level = CompressionLevel.Optimal;
+                options.Level = CompressionLevel.Fastest;
             }).Configure<GzipCompressionProviderOptions>(options =>
             {
                 options.Level = CompressionLevel.Optimal;

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

@@ -105,41 +105,4 @@
     {
         return PerfCounter.GetCurrentPerformanceCounter();
     }
-
-    /// <summary>
-    /// 获取历史性能计数器
-    /// </summary>
-    /// <returns></returns>
-    [JSInvokable]
-    public static object GetHistoryList()
-    {
-        return new
-        {
-            cpu = PerfCounter.List.Select(c => new[] {
-                c.Time,
-                c.CpuLoad
-            }),
-            mem = PerfCounter.List.Select(c => new[] {
-                c.Time,
-                c.MemoryUsage
-            }),
-            read = PerfCounter.List.Select(c => new[] {
-                c.Time,
-                c.DiskRead
-            }),
-            write = PerfCounter.List.Select(c => new[] {
-                c.Time,
-                c.DiskWrite
-            }),
-            down = PerfCounter.List.Select(c => new[] {
-                c.Time,
-                c.Download
-            }),
-            up = PerfCounter.List.Select(c => new[] {
-                c.Time,
-                c.Upload
-            }),
-        };
-    }
-
 }

+ 212 - 202
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/counter.js

@@ -1,32 +1,32 @@
 function showSpeed() {
-            var myChart = echarts.init(document.getElementById("container"));
-            myChart.setOption({
-                series: [{
-                    type: 'gauge',
-                    anchor: {
-                        show: true,
-                        showAbove: true,
-                        size: 18,
-                        itemStyle: {
-                            color: '#FAC858'
-                        }
-                    },
-                    pointer: {
-                        icon: 'path://M2.9,0.7L2.9,0.7c1.4,0,2.6,1.2,2.6,2.6v115c0,1.4-1.2,2.6-2.6,2.6l0,0c-1.4,0-2.6-1.2-2.6-2.6V3.3C0.3,1.9,1.4,0.7,2.9,0.7z',
-                        width: 8,
-                        length: '80%',
-                        offsetCenter: [0, '8%']
-                    },
+    var myChart = echarts.init(document.getElementById("container"));
+    myChart.setOption({
+        series: [{
+                type: 'gauge',
+                anchor: {
+                    show: true,
+                    showAbove: true,
+                    size: 18,
+                    itemStyle: {
+                        color: '#FAC858'
+                    }
+                },
+                pointer: {
+                    icon: 'path://M2.9,0.7L2.9,0.7c1.4,0,2.6,1.2,2.6,2.6v115c0,1.4-1.2,2.6-2.6,2.6l0,0c-1.4,0-2.6-1.2-2.6-2.6V3.3C0.3,1.9,1.4,0.7,2.9,0.7z',
+                    width: 8,
+                    length: '80%',
+                    offsetCenter: [0, '8%']
+                },
 
-                    progress: {
-                        show: true,
-                        overlap: true,
-                        roundCap: true
-                    },
-                    axisLine: {
-                        roundCap: true
-                    },
-                    data: [{
+                progress: {
+                    show: true,
+                    overlap: true,
+                    roundCap: true
+                },
+                axisLine: {
+                    roundCap: true
+                },
+                data: [{
                         value: 0,
                         name: 'CPU',
                         title: {
@@ -46,33 +46,135 @@
                             offsetCenter: ['20%', '95%']
                         }
                     }
-                    ],
-                    title: {
-                        fontSize: 14
-                    },
-                    detail: {
-                        width: 40,
-                        height: 14,
-                        fontSize: 14,
-                        color: '#fff',
-                        backgroundColor: 'auto',
-                        borderRadius: 3,
-                        formatter: '{value}%'
-                    }
-                }]
-            });
-            return myChart;
-        }
-        function showIO(data) {
-            var myChart = echarts.init(document.getElementById("container-io"));
-            myChart.setOption({
-                tooltip: {
-                    trigger: 'axis',
-                    axisPointer: {
-                        animation: false
-                    }
+                ],
+                title: {
+                    fontSize: 14
                 },
-                dataZoom: [{
+                detail: {
+                    width: 40,
+                    height: 14,
+                    fontSize: 14,
+                    color: '#fff',
+                    backgroundColor: 'auto',
+                    borderRadius: 3,
+                    formatter: '{value}%'
+                }
+            }]
+    });
+    return myChart;
+}
+
+function showIO(data) {
+    var myChart = echarts.init(document.getElementById("container-io"));
+    myChart.setOption({
+        tooltip: {
+            trigger: 'axis',
+            axisPointer: {
+                animation: false
+            }
+        },
+        dataZoom: [{
+                type: 'inside',
+                start: 90,
+                end: 100,
+                minValueSpan: 50
+            }, {
+                start: 90,
+                end: 100,
+                minValueSpan: 50
+            }],
+        xAxis: {
+            type: 'time',
+            splitLine: {
+                show: false
+            }
+        },
+        yAxis: [{
+                name: '磁盘',
+                type: 'value'
+            },
+            {
+                name: '网络',
+                type: 'value'
+            }
+        ],
+        legend: {
+            data: ['磁盘读(KBps)', '磁盘写(KBps)', "网络上行(KBps)", "网络下行(KBps)"]
+        },
+        series: [{
+                name: '磁盘读(KBps)',
+                type: 'line',
+                showSymbol: false,
+                hoverAnimation: false,
+                data: data.read,
+                markLine: {
+                    data: [
+                        { type: 'average', name: '磁盘读平均值' }
+                    ]
+                }
+            }, {
+                name: '磁盘写(KBps)',
+                type: 'line',
+                showSymbol: false,
+                hoverAnimation: false,
+                data: data.write,
+                markLine: {
+                    data: [
+                        { type: 'average', name: '磁盘写平均值' }
+                    ]
+                }
+            }, {
+                name: '网络上行(KBps)',
+                yAxisIndex: 1,
+                type: 'line',
+                showSymbol: false,
+                hoverAnimation: false,
+                data: data.up,
+                markLine: {
+                    data: [
+                        { type: 'average', name: '上行平均值' }
+                    ]
+                }
+            }, {
+                name: '网络下行(KBps)',
+                yAxisIndex: 1,
+                type: 'line',
+                showSymbol: false,
+                hoverAnimation: false,
+                data: data.down,
+                markLine: {
+                    data: [
+                        { type: 'average', name: '下行平均值' }
+                    ]
+                }
+            }]
+    });
+    return myChart;
+}
+
+function showLine() {
+    window.fetch("/system/GetCounterHistory", {
+        credentials: 'include',
+        method: 'GET',
+        mode: 'cors'
+    }).then(function(response) {
+        return response.json();
+    }).then(function(data) {
+        var myChart = echarts.init(document.getElementById("container-cpu"));
+        myChart.setOption({
+            visualMap: [{
+                    show: false,
+                    type: 'continuous',
+                    seriesIndex: 0
+                }],
+            tooltip: {
+                trigger: 'axis',
+
+                axisPointer: {
+                    animation: false
+                }
+            },
+            dataZoom: [{
                     type: 'inside',
                     start: 90,
                     end: 100,
@@ -82,172 +184,78 @@
                     end: 100,
                     minValueSpan: 50
                 }],
-                xAxis: {
-                    type: 'time',
-                    splitLine: {
-                        show: false
-                    }
-                }, yAxis: [
-                    {
-                        name: '磁盘',
-                        type: 'value'
-                    },
-                    {
-                        name: '网络',
-                        type: 'value'
-                    }
-                ],
-                legend: {
-                    data: ['磁盘读(KBps)', '磁盘写(KBps)', "网络上行(KBps)", "网络下行(KBps)"]
+            xAxis: {
+                type: 'time',
+                splitLine: {
+                    show: false
+                }
+            },
+            yAxis: {
+                type: 'value',
+                boundaryGap: [0, '100%'],
+                splitLine: {
+                    show: false
                 },
-                series: [{
-                    name: '磁盘读(KBps)',
+                max: 100
+            },
+            legend: {
+                data: ['CPU使用率', '内存使用率']
+            },
+            series: [{
+                    name: 'CPU使用率',
                     type: 'line',
                     showSymbol: false,
                     hoverAnimation: false,
-                    data: data.read,
-                    markLine: {
+                    data: data.cpu,
+                    markPoint: {
                         data: [
-                            { type: 'average', name: '磁盘读平均值' }
+                            { type: 'max', name: '最大值' },
+                            { type: 'min', name: '最小值' }
                         ]
-                    }
-                }, {
-                    name: '磁盘写(KBps)',
-                    type: 'line',
-                    showSymbol: false,
-                    hoverAnimation: false,
-                    data: data.write,
+                    },
                     markLine: {
                         data: [
-                            { type: 'average', name: '磁盘写平均值' }
+                            { type: 'average', name: '平均值' }
                         ]
                     }
                 }, {
-                    name: '网络上行(KBps)',
-                    yAxisIndex: 1,
+                    name: '内存使用率',
                     type: 'line',
                     showSymbol: false,
                     hoverAnimation: false,
-                    data: data.up,
-                    markLine: {
+                    data: data.mem,
+                    markPoint: {
                         data: [
-                            { type: 'average', name: '上行平均值' }
+                            { type: 'max', name: '最大值' },
+                            { type: 'min', name: '最小值' }
                         ]
-                    }
-                }, {
-                    name: '网络下行(KBps)',
-                    yAxisIndex: 1,
-                    type: 'line',
-                    showSymbol: false,
-                    hoverAnimation: false,
-                    data: data.down,
+                    },
                     markLine: {
                         data: [
-                            { type: 'average', name: '下行平均值' }
+                            { type: 'average', name: '平均值' }
                         ]
                     }
                 }]
-            });
-            return myChart;
-        }
-        function showLine() {
-            DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'GetHistoryList').then(data => {
-                var myChart = echarts.init(document.getElementById("container-cpu"));
-                myChart.setOption({
-                    visualMap: [{
-                        show: false,
-                        type: 'continuous',
-                        seriesIndex: 0
-                    }],
-                    tooltip: {
-                        trigger: 'axis',
-
-                        axisPointer: {
-                            animation: false
-                        }
-                    },
-                    dataZoom: [{
-                        type: 'inside',
-                        start: 90,
-                        end: 100,
-                        minValueSpan: 50
-                    }, {
-                        start: 90,
-                        end: 100,
-                        minValueSpan: 50
-                    }],
-                    xAxis: {
-                        type: 'time',
-                        splitLine: {
-                            show: false
-                        }
-                    },
-                    yAxis: {
-                        type: 'value',
-                        boundaryGap: [0, '100%'],
-                        splitLine: {
-                            show: false
-                        },
-                        max:100
-                    },
-                    legend: {
-                        data: ['CPU使用率', '内存使用率']
-                    },
-                    series: [{
-                        name: 'CPU使用率',
-                        type: 'line',
-                        showSymbol: false,
-                        hoverAnimation: false,
-                        data: data.cpu,
-                        markPoint: {
-                            data: [
-                                { type: 'max', name: '最大值' },
-                                { type: 'min', name: '最小值' }
-                            ]
-                        },
-                        markLine: {
-                            data: [
-                                { type: 'average', name: '平均值' }
-                            ]
-                        }
-                    }, {
-                        name: '内存使用率',
-                        type: 'line',
-                        showSymbol: false,
-                        hoverAnimation: false,
-                        data: data.mem,
-                        markPoint: {
-                            data: [
-                                { type: 'max', name: '最大值' },
-                                { type: 'min', name: '最小值' }
-                            ]
-                        },
-                        markLine: {
-                            data: [
-                                { type: 'average', name: '平均值' }
-                            ]
-                        }
-                    }]
-                });
-                var rateChart = showSpeed();
-                var ioChart = showIO(data);
-                setInterval(function () {
-                    DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'GetCurrentPerformanceCounter').then(item => {
-                        data.cpu.push([item.time, item.cpuLoad.toFixed(2)]);
-                        data.mem.push([item.time, item.memoryUsage.toFixed(2)]);
-                        data.read.push([item.time, item.diskRead.toFixed(2)]);
-                        data.write.push([item.time, item.diskWrite.toFixed(2)]);
-                        data.up.push([item.time, item.upload.toFixed(2)]);
-                        data.down.push([item.time, item.download.toFixed(2)]);
-                        myChart.setOption({
-                            series: [{
+        });
+        var rateChart = showSpeed();
+        var ioChart = showIO(data);
+        setInterval(function() {
+                DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'GetCurrentPerformanceCounter').then(item => {
+                    data.cpu.push([item.time, item.cpuLoad.toFixed(2)]);
+                    data.mem.push([item.time, item.memoryUsage.toFixed(2)]);
+                    data.read.push([item.time, item.diskRead.toFixed(2)]);
+                    data.write.push([item.time, item.diskWrite.toFixed(2)]);
+                    data.up.push([item.time, item.upload.toFixed(2)]);
+                    data.down.push([item.time, item.download.toFixed(2)]);
+                    myChart.setOption({
+                        series: [{
                                 data: data.cpu
                             }, {
                                 data: data.mem
                             }]
-                        });
-                        ioChart.setOption({
-                            series: [{
+                    });
+                    ioChart.setOption({
+                        series: [{
                                 data: data.read
                             }, {
                                 data: data.write
@@ -256,12 +264,14 @@
                             }, {
                                 data: data.down
                             }]
-                        });
-                        let option = rateChart.getOption();
-                        option.series[0].data[0].value = item.cpuLoad.toFixed(2);
-                        option.series[0].data[1].value = item.memoryUsage.toFixed(2);
-                        rateChart.setOption(option, true);
                     });
-                }, 5000);
-            });
-        }
+                    let option = rateChart.getOption();
+                    option.series[0].data[0].value = item.cpuLoad.toFixed(2);
+                    option.series[0].data[1].value = item.memoryUsage.toFixed(2);
+                    rateChart.setOption(option, true);
+                });
+            }, 5000);
+    }).catch(function(e) {
+        console.error(e);
+    });
+}