浏览代码

服务监控-tenant添加

demon 8 年之前
父节点
当前提交
695361f2e8

+ 9 - 3
hos-broker/src/main/java/com/yihu/hos/broker/models/ServiceMetrics.java

@ -1,11 +1,8 @@
package com.yihu.hos.broker.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.
 */
@ -17,6 +14,15 @@ public class ServiceMetrics {
    private String name;
    private String value;
    private String createTime;
    private String tenant;
    public String getTenant() {
        return tenant;
    }
    public void setTenant(String tenant) {
        this.tenant = tenant;
    }
    public String getId() {
        return id;

+ 6 - 0
hos-broker/src/main/java/com/yihu/hos/broker/services/ServiceMonitorService.java

@ -10,6 +10,7 @@ import com.yihu.hos.broker.models.BusinessLog;
import com.yihu.hos.broker.models.ServiceMetrics;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Service;
@ -22,6 +23,10 @@ import java.util.*;
@Service("ServiceMonitorService")
public class ServiceMonitorService {
    public static final String BEAN_ID = "ServiceMonitorService";
    @Value("${hos.tenant.name}")
    private String tenant;
    @Autowired
    private MongoOperations mongoOperations;
@ -403,6 +408,7 @@ public class ServiceMonitorService {
    public void saveServiceMetrics(String name, String type, String value, String createTime) {
        ServiceMetrics serviceMetrics = new ServiceMetrics();
        serviceMetrics.setTenant(tenant);
        serviceMetrics.setName(name);
        serviceMetrics.setType(type);
        serviceMetrics.setValue(value);

+ 3 - 3
hos-broker/src/main/resources/application.yml

@ -19,9 +19,9 @@ spring:
  profiles: dev
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.1.220:3306/esb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
    username: hos2
    password: hos2
    url: jdbc:mysql://192.168.1.220:8066/hos1?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
    username: hos
    password: 123456
    test-on-borrow: true
    validation-query: SELECT 1
    test-while-idle: true

+ 2 - 2
hos-camel/src/main/java/api7/route/ApiRouteBulider.java

@ -7,7 +7,7 @@ import org.apache.camel.builder.RouteBuilder;
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9097/api/v1").routeId("api7").log("servers: 0,code: ,order: 0")
                .process(new ApiProcessor()).log("servers: 0,code: ,order: 0");
        from("jetty:http://localhost:9097/api/v1").routeId("api7")
                .process(new ApiProcessor()).log("servers: 0,code: ,order: 0").log("servers: 0,code: ,order: 0");
    }
}

+ 5 - 3
src/main/java/com/yihu/hos/monitor/controller/ServiceMonitorController.java

@ -1,6 +1,5 @@
package com.yihu.hos.monitor.controller;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.monitor.service.ServiceMonitorService;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
@ -13,7 +12,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
 * @author HZY
@ -40,6 +40,7 @@ public class ServiceMonitorController {
    @ResponseBody
    @ApiOperation(value = "获取服务指标", produces = "application/json", notes = "获取服务指标")
    public Result metrics(
            HttpServletRequest request,
            @ApiParam(name = "id", value = "serviceID", required = true)
            @RequestParam(value = "id") String id,
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
@ -47,7 +48,8 @@ public class ServiceMonitorController {
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        try {
            return monitorService.metrics(id, beginTime, endTime);
            HttpSession session = request.getSession();
            return monitorService.metrics(session,id, beginTime, endTime);
        } catch (Exception e) {
            return Result.error("获取服务指标失败");
        }

+ 7 - 2
src/main/java/com/yihu/hos/monitor/service/ServiceMonitorService.java

@ -1,11 +1,13 @@
package com.yihu.hos.monitor.service;
import com.mongodb.*;
import com.yihu.hos.common.constants.ContextAttributes;
import com.yihu.hos.core.datatype.CollectionUtil;
import com.yihu.hos.monitor.dao.ServiceMonitorDao;
import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowConfig;
import com.yihu.hos.tenant.model.TenantSession;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.TreeView;
@ -16,6 +18,7 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -39,10 +42,11 @@ public class ServiceMonitorService {
    @Autowired
    private ServiceMonitorDao serviceMonitorDao;
    public Result metrics(String id, String beginTime, String endTime) throws Exception {
    public Result metrics(HttpSession session,String id, String beginTime, String endTime) throws Exception {
        String name;
        String code;
        String description;
        TenantSession tenantSession = (TenantSession)session.getAttribute(ContextAttributes.TENANT_SESSION);
        if (id.contains("flow")) {
            Integer flowId = Integer.parseInt(id.replace("flow", ""));
            SystemServiceFlow systemServiceFlow = serviceMonitorDao.getFlowById(flowId);
@ -68,7 +72,8 @@ public class ServiceMonitorService {
                                new BasicDBObject().append(QueryOperators.GTE, beginTime)),
                        new BasicDBObject().append("createTime",
                                new BasicDBObject().append(QueryOperators.LT, endTime)),
                        new BasicDBObject("name", code)});
                        new BasicDBObject("name", code),
                        new BasicDBObject("tenant", tenantSession.getTenant())});
        JSONObject result = new JSONObject();
        DBCursor cursor = metrics.find(queryObject);