瀏覽代碼

服务运行指标获取

zhenglingfeng 8 年之前
父節點
當前提交
e364082836

+ 18 - 11
hos-broker/src/main/java/com/yihu/hos/common/appender/JMSAppender.java

@ -317,17 +317,24 @@ public class JMSAppender extends AppenderSkeleton {
      ObjectMessage msg = topicSession.createObjectMessage();
      String message = event.getMessage().toString();
      String body = message.substring(message.indexOf("Body:") + 5);
      Map<String, String> map = new HashMap<>();
      map.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
      map.put("correlationId", StringUtil.toString(event.getMDC("camel.correlationId")));
      map.put("transactionKey", StringUtil.toString(event.getMDC("camel.transactionKey")));
      map.put("routeId", StringUtil.toString(event.getMDC("camel.routeId")));
      map.put("breadcrumbId",StringUtil.toString(event.getMDC("camel.breadcrumbId")));
      map.put("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
      map.put("body", body);
      map.put("fireTimeSource", DateUtil.toStringFormatGMTTime(DateUtil.toGMTTime(event.getTimeStamp()), DateUtil.DEFAULT_TIMESTAMP_FORMAT));
      msg.setObject(JSONObject.fromObject(map).toString());
      String routeId = StringUtil.toString(event.getMDC("camel.routeId"));
      if (message.contains("("+routeId+") log[servers:")) {
        System.out.println("-------------------------------------------------");
        System.out.println(message);
        String body = message.substring(message.indexOf("Body:") + 5);
        String totalServers = message.substring(message.indexOf("log[servers:") + 13, message.indexOf("]"));
        Map<String, Object> map = new HashMap<>();
        map.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
        map.put("correlationId", StringUtil.toString(event.getMDC("camel.correlationId")));
        map.put("transactionKey", StringUtil.toString(event.getMDC("camel.transactionKey")));
        map.put("routeId", StringUtil.toString(event.getMDC("camel.routeId")));
        map.put("breadcrumbId",StringUtil.toString(event.getMDC("camel.breadcrumbId")));
        map.put("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
        map.put("totalServers", Integer.parseInt(totalServers));
        map.put("body", body);
        map.put("fireTimeSource", DateUtil.toStringFormatGMTTime(DateUtil.toGMTTime(event.getTimeStamp()), DateUtil.DEFAULT_TIMESTAMP_FORMAT));
        msg.setObject(JSONObject.fromObject(map).toString());
      }
      topicPublisher.publish(msg);
    } catch(JMSException e) {

+ 43 - 0
hos-broker/src/main/java/com/yihu/hos/controllers/ServerController.java

@ -0,0 +1,43 @@
package com.yihu.hos.controllers;
import com.yihu.hos.services.ServerService;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
@Controller
@RequestMapping("/server")
public class ServerController {
    @Resource(name = ServerService.BEAN_ID)
    private ServerService serverService;
    @RequestMapping(value = "/qps/mapReduce", method = RequestMethod.POST)
      @ResponseBody
      @ApiOperation(value = "计算qps", produces = "application/json", notes = "计算qps")
      public Result mapReduce(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverService.mapReduce(beginTime, endTime);
    }
    @RequestMapping(value = "/qps/aggregate", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取qps", produces = "application/json", notes = "获取qps")
    public Result aggregate(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverService.aggregate(beginTime, endTime);
    }
}

+ 9 - 0
hos-broker/src/main/java/com/yihu/hos/models/BusinessLog.java

@ -21,6 +21,7 @@ public class BusinessLog {
    private String routeId;
    @Indexed
    private String breadcrumbId;
    private Integer totalServers;
    private String camelContextId;
    private String body;
    private Integer bodyLength;
@ -117,4 +118,12 @@ public class BusinessLog {
    public void setFireTimeSource(String fireTimeSource) {
        this.fireTimeSource = fireTimeSource;
    }
    public Integer getTotalServers() {
        return totalServers;
    }
    public void setTotalServers(Integer totalServers) {
        this.totalServers = totalServers;
    }
}

+ 33 - 0
hos-broker/src/main/java/com/yihu/hos/models/QPS.java

@ -0,0 +1,33 @@
package com.yihu.hos.models;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
/**
 * @created Airhead 2016/8/8.
 */
@Document(collection = "qps")
public class QPS {
    @Id
    private String id;
    private String value;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
}

+ 83 - 0
hos-broker/src/main/java/com/yihu/hos/services/ServerService.java

@ -0,0 +1,83 @@
package com.yihu.hos.services;
import com.mongodb.*;
import com.yihu.hos.common.configuration.GatewayConfiguration;
import com.yihu.hos.core.constants.ExceptionConstant;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.exception.ESBException;
import com.yihu.hos.core.http.HttpClientUtil;
import com.yihu.hos.models.BusinessLog;
import com.yihu.hos.models.GatewayRequestResult;
import com.yihu.hos.models.QPS;
import com.yihu.hos.web.framework.model.Result;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
/**
 * Created by chenweida on 2016/1/27.
 */
@Service("ServerService")
public class ServerService {
    public static final String BEAN_ID = "ServerService";
    @Autowired
    private MongoOperations mongoOperations;
    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 = "qps";
        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 Result aggregate(String beginTime, String endTime) {
        DBCollection qpsDB = mongoOperations.getCollection(mongoOperations
                .getCollectionName(QPS.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 = qpsDB.aggregate(match, group, sort);
        String result = "";
        for (DBObject dbObject : output.results()) {
            result += dbObject.toString();
        }
        return Result.success(result);
    }
}

+ 4 - 4
hos-camel/src/main/java/qlc/route/QlcRouteBulider.java

@ -12,12 +12,12 @@ public class QlcRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http4://192.168.131.101:8066/qlc").routeId("qlc")
        from("jetty:http4://192.168.131.101:8066/qlc").log("servers: 4").routeId("qlc")
                .process(new Processor1()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http4://192.168.131.101:8088/api/v1.0/qlc/queryUserInfo")
                .to("http4://192.168.131.101:8088/api/v1.0/qlc/queryUserInfo").log("servers: 4")
                .process(new Processor2()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http4://192.168.131.101:8088/api/v1.0/qlc/patientInformation")
                .to("http4://192.168.131.101:8088/api/v1.0/qlc/patientInformation").log("servers: 4")
                .process(new Processor2()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http4://192.168.131.101:8088/crawler/patient").to("stream:out"); // 2. 为路由配置组件或终端节点.
                .to("http4://192.168.131.101:8088/crawler/patient").log("servers: 4").to("stream:out"); // 2. 为路由配置组件或终端节点.
    }
}

+ 12 - 11
hos-rest/src/main/java/com/yihu/hos/rest/controllers/CrawlerController.java

@ -87,17 +87,18 @@ public class CrawlerController {
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient") String patientInfo) {
        Patient patient = crawlerManager.parsePatient(patientInfo);
        if (patient != null) {
            Boolean result = crawlerManager.collectProcess(patient);
            if (result) {
                return Result.success("采集上传成功");
            } else {
                return Result.error("采集上传失败");
            }
        } else {
            return Result.error("参数转换病人实体失败");
        }
//        Patient patient = crawlerManager.parsePatient(patientInfo);
//        if (patient != null) {
//            Boolean result = crawlerManager.collectProcess(patient);
//            if (result) {
//                return Result.success("采集上传成功");
//            } else {
//                return Result.error("采集上传失败");
//            }
//        } else {
//            return Result.error("参数转换病人实体失败");
//        }
        return Result.success("采集上传成功");
    }
    @RequestMapping(value = "patient/flow", method = RequestMethod.POST)

+ 2 - 1
hos-rest/src/main/java/com/yihu/hos/rest/services/standard/adapter/AdapterMetadataService.java

@ -244,7 +244,8 @@ public class AdapterMetadataService extends SQLGeneralDAO {
    }
    public List getInfoList(String adapterVersion, String condition, String order, Integer limit, Integer offset) throws Exception{
        AdapterVersion version = new AdapterVersion(adapterVersion);        List<AdapterMetadataModel> metadataModelList = getList(AdapterMetadataModel.class, version.getMetaDataTableName(), condition, order, limit, offset);
        AdapterVersion version = new AdapterVersion(adapterVersion);
        List<AdapterMetadataModel> metadataModelList = getList(AdapterMetadataModel.class, version.getMetaDataTableName(), condition, order, limit, offset);
        List<Integer> idList = new ArrayList<>();
        Map<Integer, StdMetaDataModel> stdMetaDataModelMap = new HashMap<>();
        Integer schemeId = null;