付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
package com.wgcloud.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.comparator.PropertyComparator;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import com.wgcloud.config.CommonConfig;
import com.wgcloud.dto.ChartDapingNewInfo;
import com.wgcloud.entity.DiskState;
import com.wgcloud.entity.HostDiskPer;
import com.wgcloud.entity.LogInfo;
import com.wgcloud.entity.SystemInfo;
import com.wgcloud.service.*;
import com.wgcloud.util.DateUtil;
import com.wgcloud.util.FormatUtil;
import com.wgcloud.util.HostUtil;
import com.wgcloud.util.ThreadPoolUtil;
import com.wgcloud.util.staticvar.StaticKeys;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
 
/**
 * @version v3.3
 * @ClassName:DapingNewController.java
 * @author: http://www.wgstart.com
 * @date: 20212年6月9日
 * @Description: 大屏新版controller
 * @Copyright: 2019-2022 wgcloud. All rights reserved.
 */
@Controller
@RequestMapping(value = "/dapingNew")
public class DapingNewController {
 
 
    private void testThread() {
        Runnable runnable = () -> {
            logger.info("DapingNewController----------testThread");
        };
        ThreadPoolUtil.executor.execute(runnable);
    }
 
 
    private static final Logger logger = LoggerFactory.getLogger(DapingNewController.class);
    @Resource
    private DbTableService dbTableService;
    @Resource
    private PortInfoService portInfoService;
    @Resource
    private FileSafeService fileSafeService;
    @Resource
    private DceInfoService dceInfoService;
    @Resource
    private SnmpInfoService snmpInfoService;
    @Resource
    private DbInfoService dbInfoService;
    @Resource
    private SystemInfoService systemInfoService;
    @Resource
    private AppInfoService appInfoService;
    @Resource
    private FileWarnInfoService fileWarnInfoService;
    @Resource
    private FileWarnStateService fileWarnStateService;
    @Resource
    private HostDiskPerService hostDiskPerService;
    @Resource
    private DockerInfoService dockerInfoService;
    @Resource
    private LogInfoService logInfoService;
    @Autowired
    private HeathMonitorService heathMonitorService;
    @Autowired
    private ShellInfoService shellInfoService;
    @Resource
    private AccountInfoService accountInfoService;
    @Resource
    private DiskStateService diskStateService;
    @Autowired
    private CommonConfig commonConfig;
 
    /**
     * 根据条件查询host列表
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "index")
    public String index(Model model, HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        try {
            int totalSystemInfoSize = systemInfoService.countByParams(params);
            //监控主机总量
            model.addAttribute("totalSystemInfoSize", totalSystemInfoSize);
            params.put("state", StaticKeys.DOWN_STATE);
            int hostDownSize = systemInfoService.countByParams(params);
            //下线主机数量
            model.addAttribute("hostDownSize", hostDownSize);
 
            params.clear();
            int totalSizeApp = appInfoService.countByParams(params);
            //进程总数量
            model.addAttribute("totalSizeApp", totalSizeApp);
            int dockerSize = dockerInfoService.countByParams(params);
            //docker总数量
            model.addAttribute("dockerSize", dockerSize);
 
            params.put("state", StaticKeys.DOWN_STATE);
            int downAppSize = appInfoService.countByParams(params);
            //监控进程下线数量
            model.addAttribute("downAppSize", downAppSize);
            int downDockerSize = dockerInfoService.countByParams(params);
            //监控docker下线数量
            model.addAttribute("downDockerSize", downDockerSize);
 
            params.clear();
            int portSize = portInfoService.countByParams(params);
            //端口总数量
            model.addAttribute("portSize", portSize);
            params.put("state", StaticKeys.DOWN_STATE);
            int portDownSize = portInfoService.countByParams(params);
            //端口下线数量
            model.addAttribute("portDownSize", portDownSize);
 
            params.clear();
            int dceSize = dceInfoService.countByParams(params);
            //数通设备总数量
            model.addAttribute("dceSize", dceSize);
            params.put("resTimes", -1);
            int dceDownSize = dceInfoService.countByParams(params);
            //数通设备下线数量
            model.addAttribute("dceDownSize", dceDownSize);
 
            params.clear();
            int snmpSize = snmpInfoService.countByParams(params);
            //snmp设备总数量
            model.addAttribute("snmpSize", snmpSize);
            params.put("state", StaticKeys.DOWN_STATE);
            int snmpDownSize = snmpInfoService.countByParams(params);
            //snmp设备下线数量
            model.addAttribute("snmpDownSize", snmpDownSize);
 
            params.clear();
            Integer fileWarnSize = fileWarnInfoService.countByParams(params);
            //日志监控总量
            model.addAttribute("fileWarnSize", fileWarnSize == null ? 0 : fileWarnSize);
 
            params.clear();
            Integer fileSafeSize = fileSafeService.countByParams(params);
            //文件防篡改总量
            model.addAttribute("fileSafeSize", fileSafeSize == null ? 0 : fileSafeSize);
            params.put("state", StaticKeys.DOWN_STATE);
            int fileSafeDownSize = fileSafeService.countByParams(params);
            //文件防篡改下线数量
            model.addAttribute("fileSafeDownSize", fileSafeDownSize);
 
            params.clear();
            Integer dbTableSize = dbTableService.countByParams(params);
            //数据表总量
            model.addAttribute("dbTableSize", dbTableSize);
 
            params.clear();
            int dbInfoSize = dbInfoService.countByParams(params);
            //数据源数量
            model.addAttribute("dbInfoSize", dbInfoSize);
 
            params.clear();
            params.put("dbState", StaticKeys.DOWN_STATE);
            int dbInfoDownSize = dbInfoService.countByParams(params);
            //失败数据源数量
            model.addAttribute("dbInfoDownSize", dbInfoDownSize);
 
            params.clear();
            int heathSize = heathMonitorService.countByParams(params);
            //服务接口数量
            model.addAttribute("heathSize", heathSize);
            params.put("heathStatus", StaticKeys.HEATH_STATUS_200);
            int heath200Size = heathMonitorService.countByParams(params);
            model.addAttribute("heath200Size", heath200Size);
            //服务接口失败数量
            model.addAttribute("heatherrSize", (heathSize - heath200Size));
 
            params.clear();
            int shellInfoSize = shellInfoService.countByParams(params);
            //失败数据源数量
            model.addAttribute("shellInfoSize", shellInfoSize);
 
 
            //监控资源总数量
            Integer resourceAllSize = totalSystemInfoSize + totalSizeApp + dockerSize + portSize + dceSize + snmpSize + fileWarnSize +
                    dbInfoSize + heathSize + fileSafeSize + dbTableSize;
            model.addAttribute("resourceAllSize", resourceAllSize);
 
            //设置每个系统类型的数量
            params.clear();
            List<SystemInfo> systemInfoList = systemInfoService.selectAllByParams(params);
            setSystemType(systemInfoList, model);
 
            //累积告警(次数)
            params.clear();
            params.put("hostname", "告警");
            model.addAttribute("warnCount", logInfoService.countByParams(params));
 
            // 主机及其资源告警次数最高,取前6个
            setTopDownHostChart(model);
 
            //设置cpu总核数,内存总大小
            setMiddleData(systemInfoList, model);
 
            //设置大屏显示的日志告警和恢复信息
            setLogInfo(model);
 
            //设置服务接口状态类型饼图
            setHeathMonitorType(model, heathSize);
 
            // 设置告警统计信息蜘蛛网图
            warnInfoInit(model);
 
            //主机进程数量,连接数量,mem使用率,cpu使用率,磁盘使用率,最新上报前6
            hostInfoTop6(model);
 
            return "daping/indexNew";
        } catch (Exception e) {
            logger.error("大屏展示错误", e);
        }
        return "";
    }
 
    /**
     * 设置服务接口状态类型饼图
     *
     * @param model
     */
    private void setHeathMonitorType(Model model, Integer heathSize) {
        Map<String, Object> params = new HashMap<String, Object>();
        try {
            params.put("heathStatus", StaticKeys.HEATH_STATUS_200);
            int heath200Size = heathMonitorService.countByParams(params);
            model.addAttribute("heath200Size", heath200Size);
 
            params.put("heathStatus", "400");
            int heath400Size = heathMonitorService.countByParams(params);
            model.addAttribute("heath400Size", heath400Size);
 
            params.put("heathStatus", "403");
            int heath403Size = heathMonitorService.countByParams(params);
            model.addAttribute("heath403Size", heath403Size);
 
            params.put("heathStatus", "404");
            int heath404Size = heathMonitorService.countByParams(params);
            model.addAttribute("heath404Size", heath404Size);
 
            params.put("heathStatus", "500");
            int heath500Size = heathMonitorService.countByParams(params);
            model.addAttribute("heath500Size", heath500Size);
 
 
            int heathOtherSize = heathSize - heath200Size - heath400Size - heath403Size - heath404Size - heath500Size;
            model.addAttribute("heathOtherSize", heathOtherSize);
        } catch (Exception e) {
            logger.error("setHeathMonitorType错误", e);
        }
 
    }
 
    /**
     * 设置每个系统类型的数量
     *
     * @param systemInfoList
     * @param model
     */
    private void setSystemType(List<SystemInfo> systemInfoList, Model model) {
        Map<String, Integer> map = HostUtil.getSystemTypeMap(systemInfoList);
        Integer windows = 0;
        Integer centos = 0;
        Integer redhat = 0;
        Integer ubuntu = 0;
        Integer debian = 0;
        Integer others = 0;
        if (null != map.get("windows")) {
            windows = map.get("windows");
        }
        if (null != map.get("centos")) {
            centos = map.get("centos");
        }
        if (null != map.get("redhat")) {
            redhat = map.get("redhat");
        }
        if (null != map.get("ubuntu")) {
            ubuntu = map.get("ubuntu");
        }
        if (null != map.get("debian")) {
            debian = map.get("debian");
        }
        if (null != map.get("其他Linux")) {
            others = map.get("其他Linux");
        }
        model.addAttribute("windowsSize", windows);
        model.addAttribute("centosSize", centos);
        model.addAttribute("redhatSize", redhat);
        model.addAttribute("ubuntuSize", ubuntu);
        model.addAttribute("debianSize", debian);
        model.addAttribute("othersSize", others);
    }
 
 
    /**
     * 主机及其资源告警次数最高,取前6个
     *
     * @param model
     */
    private void setTopDownHostChart(Model model) {
        Map<String, Object> params = new HashMap<String, Object>();
        List<ChartDapingNewInfo> chartInfoList = new ArrayList();
        try {
            //取最近一周的数据比对
            int days = 7;
            List<String> dateList = getDateList(days);
            String startDay = dateList.get(0);
            String endDay = dateList.get(dateList.size() - 1);
            params.put(StaticKeys.SEARCH_START_TIME, startDay + " 00:00:00");
            params.put(StaticKeys.SEARCH_END_TIME, endDay + " 23:59:59");
            List<SystemInfo> systemInfoList = systemInfoService.selectAllByParams(params);
            for (SystemInfo systemInfo : systemInfoList) {
                params.put("hostname", systemInfo.getHostname());
                params.put("hostnameNe", "已恢复");
                int size = logInfoService.countByParams(params);
                ChartDapingNewInfo chartInfo = new ChartDapingNewInfo();
                chartInfo.setName(systemInfo.getHostname());
                chartInfo.setValue(size);
                chartInfoList.add(chartInfo);
            }
            Collections.sort(chartInfoList, new PropertyComparator<>("value"));
 
            //告警次数最高6个主机 begin
            CollectionUtil.reverse(chartInfoList);
            List<ChartDapingNewInfo> chartInfoListTmp = new ArrayList();
            if (chartInfoList.size() > 6) {
                chartInfoListTmp = chartInfoList.subList(0, 6);
            } else {
                chartInfoListTmp = chartInfoList;
            }
            //添加主机备注信息
            for (ChartDapingNewInfo dto : chartInfoListTmp) {
                dto.setName(dto.getName() + HostUtil.addRemark(dto.getName()));
            }
            model.addAttribute("topDownHostChart", JSONUtil.parseArray(chartInfoListTmp));
            //告警次数最高6个主机 end
        } catch (Exception e) {
            logger.error("统计分析主机及资源告警次数TOP10错误", e);
        }
    }
 
    /**
     * 设置大屏显示的系统日志前10条,两边各显示5条
     *
     * @param model
     */
    private void setLogInfo(Model model) throws Exception {
        List<LogInfo> recordList = new ArrayList<>();
        Map<String, Object> params = new HashMap<String, Object>();
        PageInfo logListPage = logInfoService.selectByParams(params, 1, 10);
        if (logListPage.getList().size() <= 5) {
            model.addAttribute("logLeftList", logListPage.getList());
            model.addAttribute("logRightList", recordList);
        }
        if (logListPage.getList().size() > 5) {
            model.addAttribute("logLeftList", logListPage.getList().subList(0, 5));
            model.addAttribute("logRightList", logListPage.getList().subList(5, logListPage.getList().size()));
        }
 
    }
 
    /**
     * 设置告警统计信息蜘蛛网图
     *
     * @param model
     */
    private void warnInfoInit(Model model) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("hostname", "主机下线告警");
            int hostDownWarnSize = logInfoService.countByParams(params);
            //主机下线次数
            model.addAttribute("hostDownWarnSize", hostDownWarnSize);
 
            params.clear();
            params.put("hostname", "内存告警");
            int memWarnSize = logInfoService.countByParams(params);
            //内存告警次数
            model.addAttribute("memWarnSize", memWarnSize);
 
            params.clear();
            params.put("hostname", "CPU告警");
            int cpuWarnSize = logInfoService.countByParams(params);
            //cpu告警次数
            model.addAttribute("cpuWarnSize", cpuWarnSize);
 
            params.clear();
            params.put("hostname", "传输速率告警");
            int netWarnSize = logInfoService.countByParams(params);
            //上行下行速率告警次数
            model.addAttribute("netWarnSize", netWarnSize);
 
            params.clear();
            params.put("hostname", "磁盘告警");
            int diskWarnSize = logInfoService.countByParams(params);
            //磁盘告警次数
            model.addAttribute("diskWarnSize", diskWarnSize);
 
            params.clear();
            params.put("hostname", "系统负载(5分钟)告警");
            int load5WarnSize = logInfoService.countByParams(params);
            //系统负载告警次数
            model.addAttribute("load5WarnSize", load5WarnSize);
 
            //设置告警次数最大值 begin
            int WarnCountMaxSize = 1;
            if (hostDownWarnSize > WarnCountMaxSize) {
                WarnCountMaxSize = hostDownWarnSize;
            }
            if (memWarnSize > WarnCountMaxSize) {
                WarnCountMaxSize = memWarnSize;
            }
            if (cpuWarnSize > WarnCountMaxSize) {
                WarnCountMaxSize = cpuWarnSize;
            }
            if (netWarnSize > WarnCountMaxSize) {
                WarnCountMaxSize = netWarnSize;
            }
            if (diskWarnSize > WarnCountMaxSize) {
                WarnCountMaxSize = diskWarnSize;
            }
            if (load5WarnSize > WarnCountMaxSize) {
                WarnCountMaxSize = load5WarnSize;
            }
            model.addAttribute("WarnCountMaxSize", WarnCountMaxSize);
            //设置告警次数最大值 begin
 
        } catch (Exception e) {
            logger.error("设置告警统计信息蜘蛛网图错误", e);
        }
 
    }
 
    /**
     * 设置所有主机最近10分钟状态,cpu总核数,总内存
     *
     * @param model
     * @param list
     */
    private void setMiddleData(List<SystemInfo> list, Model model) {
        //cpu使用率最高
        Double maxCpu = 0d;
        //cpu使用率平均
        Double avgCpu = 0d;
        //cpu使用率最低
        Double minCpu = 1000d;
        Double sumCpu = 0d;
 
        //内存使用率最高
        Double maxMem = 0d;
        //内存使用率最低
        Double minMem = 1000d;
        //内存使用率平均
        Double avgMem = 0d;
        Double sumMem = 0d;
 
 
        //5分钟负载最高
        Double maxFiveLoad = 0d;
        //5分钟负载平均
        Double avgFiveLoad = 0d;
        //5分钟负载最低
        Double minFiveLoad = 1000d;
        Double sumFiveLoad = 0d;
 
        //15分钟负载最高
        Double maxFifteenLoad = 0d;
        //15分钟负载最低
        Double minFifteenLoad = 1000d;
        //15分钟负载平均
        Double avgFifteenLoad = 0d;
        Double sumFifteenLoad = 0d;
 
        //主机数量
        int systemSize = 0;
 
        //cpu总核数
        int cpuCoresSum = 0;
        //内存总和
        double memSum = 0;
 
        //所有主机运行总时间秒
        long uptimeSum = 0;
 
        for (SystemInfo systemInfo : list) {
            systemSize += 1;
            //组装cpu使用率 begin
            if (null != systemInfo.getCpuPer()) {
                if (systemInfo.getCpuPer() > maxCpu) {
                    maxCpu = systemInfo.getCpuPer();
                }
                if (systemInfo.getCpuPer() < minCpu) {
                    minCpu = systemInfo.getCpuPer();
                }
                sumCpu += systemInfo.getCpuPer();
            }
            //组装cpu使用率 end
 
            //组装内存使用率 begin
            if (null != systemInfo.getMemPer()) {
                if (systemInfo.getMemPer() > maxMem) {
                    maxMem = systemInfo.getMemPer();
                }
                if (systemInfo.getMemPer() < minMem) {
                    minMem = systemInfo.getMemPer();
                }
                sumMem += systemInfo.getMemPer();
            }
            //组装内存使用率 end
 
 
            //组装5分钟负载 begin
            if (null != systemInfo.getFiveLoad()) {
                if (Double.valueOf(systemInfo.getFiveLoad()) > maxFiveLoad) {
                    maxFiveLoad = Double.valueOf(systemInfo.getFiveLoad());
                }
                if (Double.valueOf(systemInfo.getFiveLoad()) < minFiveLoad) {
                    minFiveLoad = Double.valueOf(systemInfo.getFiveLoad());
                }
                sumFiveLoad += Double.valueOf(systemInfo.getFiveLoad());
            }
            //组装5分钟负载 end
 
            //组装15分钟负载 begin
            if (null != systemInfo.getFifteenLoad()) {
                if (Double.valueOf(systemInfo.getFifteenLoad()) > maxFifteenLoad) {
                    maxFifteenLoad = Double.valueOf(systemInfo.getFifteenLoad());
                }
                if (Double.valueOf(systemInfo.getFifteenLoad()) < minFifteenLoad) {
                    minFifteenLoad = Double.valueOf(systemInfo.getFifteenLoad());
                }
                sumFifteenLoad += Double.valueOf(systemInfo.getFifteenLoad());
            }
            //组装15分钟负载 end
 
            //组装cpu总核数 begin
            try {
                cpuCoresSum += Integer.valueOf(systemInfo.getCpuCoreNum());
            } catch (Exception e) {
                logger.error("统计所有主机总核数错误", e);
            }
            //组装cpu总核数 end
 
            //组装总内存 begin
            try {
                memSum += Double.valueOf(systemInfo.getTotalMem().replace("G", ""));
            } catch (Exception e) {
                logger.error("统计所有主机总内存错误", e);
            }
            //组装总内存 end
 
            //运行总时间秒 begin
            if (null != systemInfo.getUptime()) {
                uptimeSum += systemInfo.getUptime();
            }
            //运行总时间秒 end
        }
 
        model.addAttribute("cpuCoresSum", cpuCoresSum);
        model.addAttribute("memSum", FormatUtil.gToT(memSum + ""));
        model.addAttribute("uptimeSum", FormatUtil.secondsToDays(uptimeSum));
 
        if (systemSize > 0) {
            avgCpu = sumCpu / list.size();
            avgMem = sumMem / list.size();
            avgFifteenLoad = sumFifteenLoad / list.size();
            avgFiveLoad = sumFiveLoad / list.size();
        } else {
            minCpu = 0d;
            minMem = 0d;
            avgFifteenLoad = 0d;
            avgFiveLoad = 0d;
        }
 
        //最近5分钟所有主机cpu状态 begin
        model.addAttribute("maxCpuInfo", maxCpu);
        model.addAttribute("avgCpuInfo", FormatUtil.formatDouble(avgCpu, 2));
        model.addAttribute("minCpuInfo", minCpu);
        //最近5分钟所有主机cpu状态 end
 
        //最近5分钟所有主机内存状态 begin
        model.addAttribute("maxMemInfo", maxMem);
        model.addAttribute("avgMemInfo", FormatUtil.formatDouble(avgMem, 2));
        model.addAttribute("minMemInfo", minMem);
        //最近5分钟所有主机内存状态 end
 
 
        model.addAttribute("maxFiveLoad", maxFiveLoad);
        model.addAttribute("minFiveLoad", minFiveLoad);
        model.addAttribute("avgFiveLoad", FormatUtil.formatDouble(avgFiveLoad, 2));
        model.addAttribute("maxFifteenLoad", maxFifteenLoad);
        model.addAttribute("minFifteenLoad", minFifteenLoad);
        model.addAttribute("avgFifteenLoad", FormatUtil.formatDouble(avgFifteenLoad, 2));
 
        //磁盘总使用率最高
        Double maxDiskPer = 0d;
        String maxDiskPerIp = "";
        //磁盘总使用率最低
        Double minDiskPer = 1000d;
        String minDiskPerIp = "";
        //磁盘总使用率平均
        Double avgDiskPer = 0d;
        //磁盘总使用率总和
        Double sumDiskPer = 0d;
        try {
            //组织磁盘总使用率最大平均最低值 begin
            Map<String, Object> params = new HashMap<String, Object>();
            String oneDayBefore = DateUtil.getDateBefore(1);
            params.put(StaticKeys.SEARCH_START_TIME, oneDayBefore.substring(0, 10) + " 00:00:00");
            params.put(StaticKeys.SEARCH_END_TIME, oneDayBefore.substring(0, 10) + " 23:59:59");
            List<HostDiskPer> hostDiskPerList = hostDiskPerService.selectAllByParams(params);
            for (HostDiskPer hostDiskPer : hostDiskPerList) {
                if (null != hostDiskPer.getDiskSumPer() && hostDiskPer.getDiskSumPer() > maxDiskPer) {
                    maxDiskPer = hostDiskPer.getDiskSumPer();
                }
                if (null != hostDiskPer.getDiskSumPer() && hostDiskPer.getDiskSumPer() < minDiskPer) {
                    minDiskPer = hostDiskPer.getDiskSumPer();
                }
                if (null != hostDiskPer.getDiskSumPer()) {
                    sumDiskPer += hostDiskPer.getDiskSumPer();
                }
            }
            if (hostDiskPerList.size() > 0) {
                avgDiskPer = sumDiskPer / hostDiskPerList.size();
            } else {
                minDiskPer = 0d;
            }
            model.addAttribute("maxDiskPer", maxDiskPer);
            model.addAttribute("avgDiskPer", avgDiskPer);
            model.addAttribute("minDiskPer", minDiskPer);
            //组织磁盘总使用率最大平均最低值 end
        } catch (Exception e) {
            logger.error("组织磁盘总使用率最大平均最低值错误", e);
        }
 
    }
 
    /**
     * mem使用率,cpu使用率,最新上报前6
     *
     * @param model
     */
    private void hostInfoTop6(Model model) {
        try {
            Double maxSystemValue = 1d;
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("orderBy", "CREATE_TIME");
            params.put("orderType", "DESC");
            PageInfo<SystemInfo> pageInfo = systemInfoService.selectByParams(params, 1, 6);
            List<String> hostNameTop6List = new ArrayList<>();
            List<Double> hostMemTop6List = new ArrayList<>();
            List<Double> hostCpuTop6List = new ArrayList<>();
            List<Integer> hostProcsTop6List = new ArrayList<>();
            List<Integer> hostNetConnectionsTop6List = new ArrayList<>();
            List<Double> hostDiskPerTop6List = new ArrayList<>();
            Map<String, Object> paramsAppInfo = new HashMap<String, Object>();
            for (SystemInfo systemInfo : pageInfo.getList()) {
                hostNameTop6List.add(systemInfo.getHostname());
                hostMemTop6List.add(systemInfo.getMemPer());
                hostCpuTop6List.add(systemInfo.getCpuPer());
                if (!StringUtils.isEmpty(systemInfo.getProcs())) {
                    hostProcsTop6List.add(Integer.valueOf(systemInfo.getProcs()));
                } else {
                    hostProcsTop6List.add(0);
                }
 
                if (!StringUtils.isEmpty(systemInfo.getNetConnections())) {
                    hostNetConnectionsTop6List.add(Integer.valueOf(systemInfo.getNetConnections()));
                } else {
                    hostNetConnectionsTop6List.add(0);
                }
 
                //设置磁盘总使用率 begin
                paramsAppInfo.put("hostname", systemInfo.getHostname());
                List<DiskState> deskStates = diskStateService.selectAllByParams(paramsAppInfo);
                HostUtil.setDiskSumPer(deskStates, systemInfo);
                hostDiskPerTop6List.add(systemInfo.getDiskPer());
                //设置磁盘总使用率 end
            }
 
            //取最大值 begin
            for (Double memPer : hostMemTop6List) {
                if (memPer > maxSystemValue) {
                    maxSystemValue = memPer;
                }
            }
            for (Double cpuPer : hostCpuTop6List) {
                if (cpuPer > maxSystemValue) {
                    maxSystemValue = cpuPer;
                }
            }
            for (Double diskPer : hostDiskPerTop6List) {
                if (diskPer > maxSystemValue) {
                    maxSystemValue = diskPer;
                }
            }
            maxSystemValue = FormatUtil.formatDouble(maxSystemValue * 1.2, 2);
            //取最大值 end
 
            model.addAttribute("hostNameTop6List", JSONUtil.parseArray(hostNameTop6List));
            model.addAttribute("hostMemTop6List", JSONUtil.parseArray(hostMemTop6List));
            model.addAttribute("hostCpuTop6List", JSONUtil.parseArray(hostCpuTop6List));
            model.addAttribute("hostProcsTop6List", JSONUtil.parseArray(hostProcsTop6List));
            model.addAttribute("hostNetConnectionsTop6List", JSONUtil.parseArray(hostNetConnectionsTop6List));
            model.addAttribute("hostDiskPerTop6List", JSONUtil.parseArray(hostDiskPerTop6List));
            model.addAttribute("maxSystemValue", maxSystemValue);
 
        } catch (Exception e) {
            logger.error("主机最新上报前10错误", e);
        }
 
    }
 
    /**
     * 获取时间列表
     *
     * @param days 几天
     * @return
     */
    public List<String> getDateList(int days) {
        List<String> dateList = new ArrayList<String>();
        String sevenDayBefore = DateUtil.getDateBefore(days);
        for (int i = 1; i < days + 1; i++) {
            sevenDayBefore = DateUtil.getDateBefore(i);
            dateList.add(sevenDayBefore.substring(0, 10));
        }
        CollectionUtil.reverse(dateList);
        return dateList;
    }
 
 
}