Procházet zdrojové kódy

将service的监控采集从hos-broker中转移到hos-camel,采集只需要有一台服务器来执行就可以了。

airhead před 7 roky
rodič
revize
bb0d405732

+ 2 - 1
README.md

@ -1,3 +1,4 @@
# eip
信息共享交换平台(CoSharp)是一个面向医疗服务的智能化集成开发平台,定位于实现和推动医疗机构内外异构系统间的数据和服务信息共享与交换,实现网内外系统的互联互通。信息共享交换平台通过提供标准转换和各语言开发相关SDK或语言无关的API来规范开发流程,解耦应用间的依赖,降低系统的集成的难度,缩短时间周期和减少成本
信息共享交换平台(CoSharp)是一个面向医疗服务的智能化集成开发平台,定位于实现和推动医疗机构内外异构系统间的数据和服务信息共享与交换,实现网内外系统的互联互通。信息共享交换平台通过提供标准转换和各语言开发相关SDK或语言无关的API来规范开发流程,解耦应用间的依赖,降低系统的集成的难度,缩短时间周期和减少成本

+ 1 - 1
hos-broker/src/main/java/com/yihu/hos/broker/common/camelrouter/MonitorRouterBulider.java

@ -11,6 +11,6 @@ public class MonitorRouterBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("quartz://monitor/monitorTimer?cron=0 0/1 * * * ?")
                .to("bean:serviceMonitorService?method=monitor");
                .to("bean:serverMonitorService?method=collectEnvHealth");
    }
}

+ 0 - 59
hos-broker/src/main/java/com/yihu/hos/broker/common/scheduler/MonitorScheduler.java

@ -1,59 +0,0 @@
package com.yihu.hos.broker.common.scheduler;
import com.yihu.hos.broker.services.ServerMonitorService;
import com.yihu.hos.broker.services.ServiceMonitorService;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
 * 服务器性能数据采集定时器
 *
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/10/11.
 */
@Component
public class MonitorScheduler {
    static private final Logger logger = LoggerFactory.getLogger(MonitorScheduler.class);
    @Resource(name = ServiceMonitorService.BEAN_ID)
    private ServiceMonitorService serviceMonitorService;
    @Resource(name = ServerMonitorService.BEAN_ID)
    private ServerMonitorService serverMonitorService;
    @Scheduled(cron = "0 0/1 * * * ?") //每分钟执行一次
    public void statusCheck() {
        logger.debug("每分钟执行一次。开始============================================");
        //TODO 采集服务器健康监控指标数据 statusTask.healthCheck();
        collectEnvHealth();
        collectServiceHealth();
        logger.info("每分钟执行一次。结束。");
    }
    /**
     * 服务器健康指标采集
     *
     * @return
     */
    public void collectEnvHealth() {
        serverMonitorService.collectEnvHealth();
    }
    public void collectServiceHealth() {
//        serviceMonitorService.collectServiceHealth();
    }
    /**
     * 服务器列表保存
     */
//    @Scheduled(cron = "0 0 12 * * ?") //每天中午12点触发
    @Scheduled(fixedDelay = 3600 * 24 * 1000, initialDelay = 3000) //每天中午12点触发
    public void checkHost() {
        serverMonitorService.checkHost();
    }
}

+ 1 - 3
hos-broker/src/main/java/com/yihu/hos/broker/services/ServerMonitorService.java

@ -12,10 +12,8 @@ import org.springframework.stereotype.Service;
import java.util.List;
@Service("ServerMonitorService")
@Service("serverMonitorService")
public class ServerMonitorService {
    public static final String BEAN_ID = "ServerMonitorService";
    @Value("${hos.tenant.name}")
    private String tenant;
    private static String host = SigarUtil.getHost();

+ 1 - 2
hos-broker/src/main/java/com/yihu/hos/broker/models/LogOffset.java

@ -1,10 +1,9 @@
package com.yihu.hos.broker.models;
package camel.monitor.processor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.Entity;
import java.util.Date;
/**

+ 13 - 12
hos-broker/src/main/java/com/yihu/hos/broker/services/ServiceMonitorService.java

@ -1,12 +1,10 @@
package com.yihu.hos.broker.services;
package camel.monitor.processor;
import com.mongodb.MongoClient;
import com.mongodb.client.AggregateIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.yihu.hos.broker.common.constants.MonitorConstant;
import com.yihu.hos.broker.models.LogOffset;
import com.yihu.hos.core.datatype.DateUtil;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
@ -27,9 +25,12 @@ import java.util.Locale;
 * <p>
 * Created by chenweida on 2016/1/27.
 */
@Service("ServiceMonitorService")
@Service("serviceMonitorService")
public class ServiceMonitorService {
    public static final String BEAN_ID = "ServiceMonitorService";
    private static final String DATABASE = "log";
    private static final String SERVICE = "service";
    private static final String SERVICE_METRICS = "serviceMetrics";
    private static final String BUSINESS = "business";
    @Autowired
    private MongoClient mongoClient;
@ -38,9 +39,9 @@ public class ServiceMonitorService {
    public void monitor() {
        try {
            MongoDatabase database = mongoClient.getDatabase(MonitorConstant.DATABASE);
            MongoDatabase database = mongoClient.getDatabase(DATABASE);
            Query query = new Query();
            query.addCriteria(Criteria.where("name").is(MonitorConstant.SERVICE));  //Service表中已有的数据时间。
            query.addCriteria(Criteria.where("name").is(SERVICE));  //Service表中已有的数据时间。
            LogOffset offset = mongoOperations.findOne(query, LogOffset.class);
            Date begin = new Date();
            Date end = new Date();
@ -61,7 +62,7 @@ public class ServiceMonitorService {
            if (offset == null) {
                offset = new LogOffset();
                offset.setName(MonitorConstant.SERVICE);
                offset.setName(SERVICE);
            }
            offset.setOffset(end.getTime());
            mongoOperations.save(offset);
@ -72,7 +73,7 @@ public class ServiceMonitorService {
    }
    private void mapReduce(MongoDatabase database, String beginTime, String endTime) {
        Document document = new Document("mapReduce", MonitorConstant.BUSINESS);
        Document document = new Document("mapReduce", BUSINESS);
        String mapFunc = "function(){emit(this.breadcrumbId, {fireTime:this.fireTime, createTime:this.createTime, bodyLength:this.bodyLength, tenant:this.tenant, routeId:this.routeId});}";
        document = document.append("map", mapFunc);
        String reduceFunc = "function(key, values){" +
@ -83,12 +84,12 @@ public class ServiceMonitorService {
        document = document.append("reduce", reduceFunc);
        String query = "{fireTime:{$gte:new Date(\"" + beginTime + "\"), $lt:new Date(\"" + endTime + "\")}}";
        document = document.append("query", Document.parse(query));
        document = document.append("out", MonitorConstant.SERVICE);
        document = document.append("out", SERVICE);
        database.runCommand(document);
    }
    private AggregateIterable<Document> aggregate(MongoDatabase database, String beginTime, String endTime) {
        MongoCollection<Document> serviceCollection = database.getCollection(MonitorConstant.SERVICE);
        MongoCollection<Document> serviceCollection = database.getCollection(SERVICE);
        List<Document> pipeline = new ArrayList<>();
        Document match = new Document();
@ -121,7 +122,7 @@ public class ServiceMonitorService {
    }
    private void outPut(MongoDatabase database, AggregateIterable<Document> documents) {
        MongoCollection<Document> serviceMetrics = database.getCollection(MonitorConstant.SERVICE_METRICS);
        MongoCollection<Document> serviceMetrics = database.getCollection(SERVICE_METRICS);
        for (Document document : documents) {
            Document id = (Document) document.get("_id");
            String time = String.format("%04d", (int) id.get("year")) + String.format("%02d", (int) id.get("month")) + String.format("%02d", (int) id.get("day")) +

+ 16 - 0
hos-camel2/src/main/java/camel/monitor/route/MonitorRouterBulider.java

@ -0,0 +1,16 @@
package camel.monitor.route;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
/**
 * Created by l4qiang on 2017-06-16.
 */
@Component
public class MonitorRouterBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("quartz://monitor/monitorTimer?cron=0 0/1 * * * ?")
                .to("bean:serviceMonitorService?method=monitor");
    }
}

+ 0 - 74
src/main/webapp/WEB-INF/ehr/jsp/monitor/monitor.jsp

@ -1,74 +0,0 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<html>
<head>
	<meta charset="utf-8">
	<title>数据收集监控</title>
	<%@include file="/WEB-INF/ehr/commons/jsp/commonHeader.jsp" %>
    <script>
        //加载js模块组件
        seajs.use(['jquery','i18n','app/monitor/monitor'], function ($,i18n, Monitor) {
        });
    </script>
</head>
<body>
	<div class="" id="message"></div>
	<div id="conditionAreaT" class="f-mt10 f-ml10" align="left">
        <table>
            <tr>
                <td>
                    <select name="table" class="f-w200" id="hosTableList" placeholder="请选择数据集">
                    </select>
                </td>
                <td>
                    <input type="text" class="f-ml10" name="rowkey" id="rowkey" value="" style="width: 240px" class="form-control"  placeholder="请输入rowkey">
                </td>
                <td>
                    <input type="button" id="btnQuery" class="btn btn-warning f-ml10" value="查询数据">
                    <input type="button" id="btnStatic" class="btn btn-warning f-ml10" value="统计数据集入库">
                    <input type="button" id="btnVerify" class="btn btn-warning f-ml10" value="数据核对">
                    <a href="http://tool.oschina.net/codeformat/json"  class="f-ml10"  target="_blank">结果格式化</a>
                </td>
            </tr>
        </table>
	</div>
	<div id="ResultAreaT" class="f-mt10 f-ml10" align="left">
		<table>
			<tr>
				<textarea id="result" rows="10" style="width:90%"></textarea>
			</tr>
		</table>
	</div>
	<div id="conditionAreaD" class="f-mt10 f-ml10" align="left">
		<table>
			<tr>
				<td>
					<a>开始时间:</a>
				</td>
				<td>
					<input size="16" type="text" name="start" id="start" value="" placeholder="设置开始时间" class="form_datetime">
				</td>
				<td>
					<a class="f-ml10">结束时间:</a>
				</td>
				<td>
					<input size="16" type="text" name="end" id="end" value="" placeholder="设置结束时间" class="form_datetime">
				</td>
                <td>
                    <input type="button" id="btnQueryReport" class="btn btn-warning f-ml10" value="生成数据入库报告">
                </td>
			</tr>
		</table>
	</div>
	<div id="ResultAreaD" class="f-mt10 f-ml10" align="left">
		<div id="tblStaticResult">
			<!-- 结果集列表区域 -->
		</div>
	</div>
</body>
</html>

+ 4 - 4
src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManage.jsp

@ -123,15 +123,15 @@
                </div>
            </div>
            <%-- echarts 数据--%>
            <div id="main1" style="width: 500px;margin-left:130px;height:250px;border: solid deepskyblue 1px;"></div>
            <div id="main1" style="width: 500px;margin-left:130px;height:250px;border: solid #a6a6a6 1px;"></div>
            <%-- echarts 数据--%>
            <div id="main2"
                 style="width: 500px;margin:-250px 0px 20px 680px;height:250px;border: solid deepskyblue 1px;"></div>
                 style="width: 500px;margin:-250px 0px 20px 680px;height:250px;border: solid #a6a6a6 1px;"></div>
            <%-- echarts 数据--%>
            <div id="main3" style="width: 500px;margin-left:130px;height:250px;border: solid deepskyblue 1px;"></div>
            <div id="main3" style="width: 500px;margin-left:130px;height:250px;border: solid #a6a6a6 1px;"></div>
            <%-- echarts 数据--%>
            <div id="main4"
                 style="width: 500px;margin:-250px 0px 20px 680px;height:250px;border: solid deepskyblue 1px;"></div>
                 style="width: 500px;margin:-250px 0px 20px 680px;height:250px;border: solid #a6a6a6 1px;"></div>
        </div>
    </div>
</div>

+ 1 - 2
src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManageJs.jsp

@ -57,7 +57,6 @@
        var changeCheckbox = document.querySelector('#jobStatusSwitch');
        var switchery = new Switchery(changeCheckbox, {disabled: true, size: 'large'});
        changeCheckbox.onchange = function () {
            //debugger
            var a = me.switchery;
            var jobId = $("#selJob").ligerComboBox("getValue");
@ -129,7 +128,7 @@
                    service.qps(message.data);
                    service.delay(message.data);
                    service.usage(message.data);
                    service.setJobStatus();
//                    service.setJobStatus();
                } else {
                    $.ligerDialog.error(re.message);
                }