demon 8 éve
szülő
commit
9cd1542a8a

+ 8 - 14
src/main/java/com/yihu/hos/monitor/controller/ServerMonitorController.java

@ -1,9 +1,9 @@
package com.yihu.hos.monitor.controller;
import com.yihu.hos.monitor.service.ServerMonitorService;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@ -31,28 +31,22 @@ public class ServerMonitorController {
    //跳转到列表页
    @RequestMapping("/initial")
    public String initial(Model model) {
        model.addAttribute("contentPage", "/server/sEnvManage");
        model.addAttribute("contentPage", "/monitor/server/sEnvManage");
        return "partView";
    }
    @RequestMapping(value = "/initialValue", method = RequestMethod.GET)
    @RequestMapping(value = "/usage", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "echar获取", produces = "application/json", notes = "echar获取")
    public String initial(
            Model model,
    @ApiOperation(value = "获取服务器使用率", produces = "application/json", notes = "获取服务器硬件使用率")
    public Result usage(
            @ApiParam(name = "type", value = "类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        try {
            JSONArray array = monitorService.getMonitorInfoTest(type, beginTime, endTime);
                model.addAttribute("monitorModel", array);
            model.addAttribute("contentPage", "server/monitor");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "partView";
        return monitorService.getMonitorInfo(type, beginTime, endTime);
    }
}

+ 0 - 79
src/main/java/com/yihu/hos/monitor/service/ServerMonitorService.java

@ -24,63 +24,6 @@ public class ServerMonitorService {
    @Autowired
    private Mongo mongo;
//    public Result mapReduce(String beginTime, String endTime) {
//        DBCollection businessLogDB = mongoOperations.getCollection(mongoOperations
//                .getCollectionName(BusinessLog.class));
//
//        String map = "function(){emit(this.breadcrumbId, this.fireTime);}";
//        String reduce = "function(key, values){ return values[0];}";
//        String out = reduceTableName;
//        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
//                new BasicDBObject[]{
//                        new BasicDBObject().append("fireTime",
//                            new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
//                        new BasicDBObject().append("fireTime",
//                                new BasicDBObject().append(QueryOperators.LT, DateUtil.toTimestamp(endTime)))});
//
//        MapReduceOutput mapReduceOutput = businessLogDB.mapReduce(map,
//                reduce.toString(), out, queryObject);
//        DBCollection resultColl = mapReduceOutput.getOutputCollection();
//        DBCursor cursor = resultColl.find();
//        String result = "";
//
//        while (cursor.hasNext()) {
//            result += cursor.next();
//        }
//        return Result.success(result);
//    }
//
//    public JSONObject aggregate(String beginTime, String endTime) {
//        DBCollection reduceDB = mongoOperations.getCollection(mongoOperations
//                .getCollectionName(ReduceResult.class));
//        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
//                new BasicDBObject[]{
//                        new BasicDBObject().append("value",
//                                new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
//                        new BasicDBObject().append("value",
//                                new BasicDBObject().append(QueryOperators.LT, DateUtil.toTimestamp(endTime)))});
//
//        DBObject match = new BasicDBObject("$match", queryObject);
//
//        // Now the $group operation
//        DBObject groupFields = new BasicDBObject( "_id", new BasicDBObject("$minute", "$value"));
//        groupFields.put("pv", new BasicDBObject( "$sum", 1));
//        DBObject group = new BasicDBObject("$group", groupFields);
//
//        // build the $sort operation
//        DBObject sortFields =  new BasicDBObject( "_id", 1);
//        DBObject sort = new BasicDBObject("$sort", sortFields );
//        // run aggregation
//        AggregationOutput output = reduceDB.aggregate(match, group, sort);
//        String result = "";
//        for (DBObject dbObject : output.results()) {
//            result += dbObject.toString();
//        }
//        JSONObject jsonObject = new JSONObject(result);
//        return jsonObject;
//    }
    public Result getMonitorInfo(String table,String beginTime, String endTime) {
        mongoOperations = new MongoTemplate(mongo, envHealth);
        DBCollection envCollection = mongoOperations.getCollection(table);
@ -105,26 +48,4 @@ public class ServerMonitorService {
        return actionResult;
    }
    public JSONArray getMonitorInfoTest(String table,String beginTime, String endTime) {
        mongoOperations = new MongoTemplate(mongo, envHealth);
        DBCollection envCollection = mongoOperations.getCollection(table);
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
                new BasicDBObject[]{
                        new BasicDBObject().append("create_time",
                                new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
                        new BasicDBObject().append("create_time",
                                new BasicDBObject().append(QueryOperators.LT, DateUtil.toTimestamp(endTime)))});
        JSONArray result = new JSONArray();
        DBCursor cursor = envCollection.find(queryObject);
        while(cursor.hasNext()) {
            DBObject dbObject = cursor.next();
            dbObject.removeField("_id");
            result.put(dbObject);
            System.out.println(dbObject.toString());
        }
        return result;
    }
}

+ 13 - 10
src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManage.jsp

@ -2,9 +2,10 @@
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<style>
    .c-item{float:left;height: 30px;line-height: 30px;width: 150px;background: #fff;color:#000;text-align: center;font-size: 12px;border:1px solid #dcdcdc;}
    .c-item{float:left;height: 30px;line-height: 30px;width: 15%;background: #fff;color:#000;text-align: center;font-size: 12px;border:1px solid #dcdcdc;}
    .c-bor-r{border-right: 0;}
    .c-item.active{background: #16B3EE;color:#fff}
    .ml50{margin-left: 50px;}
    .mt20{margin-top: 20px;}
    .mb20{margin-bottom: 20px;}
@ -12,8 +13,8 @@
    .f-fs12{font-size: 12px;}
    .f-fs14{font-size: 14px;}
    .c-fwb{font-weight: bold;}
    .div-item{width:50%;float: left;}
    .c-item{font-size: 12px;display: inline-block;width: 100px;}
    .div-item{width:40%;float: left;}
    .d-item{font-size: 12px;display: inline-block;width: 100px;}
    .c-content{font-size: 16px;display: inline-block;width: 100px;font-weight: bold;}
    .div-right-item{font-size: 12px;width: 150px;}
@ -57,22 +58,23 @@
            <div class="c-item" data-item="net">网络</div>
        </div>
            <%-- echarts 数据--%>
        <div id="main" style="width: 600px;height:400px;border: solid deepskyblue 1px;"></div>
        <div id="main" style="width: 60%;height:400px;border: solid deepskyblue 1px;"></div>
            <%-- 详细数据 --%>
            <div class="ml50 mt20">
                <div class="div-item">
                    <div>
                        <div class="c-item">利用率</div>
                        <div class="c-item">速度</div>
                        <div class="d-item">利用率</div>
                        <div class="d-item">速度</div>
                    </div>
                    <div class="mb20">
                        <div class="c-content">53%</div>
                        <div class="c-content">2.18GHZ</div>
                    </div>
                    <div>
                        <div class="c-item">进程</div>
                        <div class="c-item">线程</div>
                        <div class="c-item">句柄</div>
                        <div class="d-item">进程</div>
                        <div class="d-item">线程</div>
                        <div class="d-item">句柄</div>
                    </div>
                    <div class="mb20">
                        <div class="c-content">107</div>
@ -95,7 +97,8 @@
                    <div class="div-right-item">L3缓存:<span class="f-fs14 c-fwb">3.0MB</span></div>
                </div>
            </div>
        </div>
        </div>
    </div>
</div>

+ 46 - 4
src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManageJs.jsp

@ -172,7 +172,7 @@
         }
         else{
             me.clearTop();
            //TODO 清除数据处理
         }
    },
        memory:function(re){
@ -239,7 +239,7 @@
                myChart.setOption(option);
            }
            else{
                me.clearTop();
               //TODO 清除数据
            }
        },
        files:function(re){
@ -309,7 +309,7 @@
                myChart.setOption(option);
            }
            else{
                me.clearTop();
                //TODO 清除数据
            }
        },
        net:function(re){
@ -374,7 +374,7 @@
                myChart.setOption(option);
            }
            else{
                me.clearTop();
               //TODO 清除数据
            }
        }
    }
@ -401,4 +401,46 @@
        return year + '-' + month + '-' + day  + ' 00:00:00';
    }
    /* **************************动态DIV添加************************ */
    /* CPU 详情数据*/
    var $envInfo = $(".mt20");
    var html = "<div class=\"div-item\">\n" +
            "                    <div>\n" +
            "                        <div class=\"d-item\">利用率</div>\n" +
            "                        <div class=\"d-item\">速度</div>\n" +
            "                    </div>\n" +
            "                    <div class=\"mb20\">\n" +
            "                        <div class=\"c-content\">53%</div>\n" +
            "                        <div class=\"c-content\">2.18GHZ</div>\n" +
            "                    </div>\n" +
            "                    <div>\n" +
            "                        <div class=\"d-item\">进程</div>\n" +
            "                        <div class=\"d-item\">线程</div>\n" +
            "                        <div class=\"d-item\">句柄</div>\n" +
            "                    </div>\n" +
            "                    <div class=\"mb20\">\n" +
            "                        <div class=\"c-content\">107</div>\n" +
            "                        <div class=\"c-content\">1720</div>\n" +
            "                        <div class=\"c-content\">59868</div>\n" +
            "                    </div>\n" +
            "                    <div class=\"f-dis-inline f-fs12\">正常运行时间</div>\n" +
            "                    <div class=\"mb20\">\n" +
            "                        <div class=\"c-content\">11:19:15:40</div>\n" +
            "                    </div>\n" +
            "                </div>\n" +
            "                <div class=\"div-item\">\n" +
            "                    <div class=\"div-right-item\">最大速度:<span class=\"f-fs14 c-fwb\">2.19GHZ</span></div>\n" +
            "                    <div class=\"div-right-item\">插槽:<span class=\"f-fs14 c-fwb\">1</span></div>\n" +
            "                    <div class=\"div-right-item\">内核:<span class=\"f-fs14 c-fwb\">2</span></div>\n" +
            "                    <div class=\"div-right-item\">编辑处理器:<span class=\"f-fs14 c-fwb\">4</span></div>\n" +
            "                    <div class=\"div-right-item\">虚拟化:<span class=\"f-fs14 c-fwb\">已启用</span></div>\n" +
            "                    <div class=\"div-right-item\">L1缓存:<span class=\"f-fs14 c-fwb\">121KB</span></div>\n" +
            "                    <div class=\"div-right-item\">L2缓存:<span class=\"f-fs14 c-fwb\">512KB</span></div>\n" +
            "                    <div class=\"div-right-item\">L3缓存:<span class=\"f-fs14 c-fwb\">3.0MB</span></div>\n" +
            "                </div>";
</script>