瀏覽代碼

Merge branch 'master' of http://192.168.1.220:10080/esb/esb

demon 8 年之前
父節點
當前提交
95c68383c5

+ 11 - 1
hos-broker/pom.xml

@ -62,8 +62,18 @@
			<groupId>org.fusesource</groupId>
			<groupId>org.fusesource</groupId>
			<artifactId>sigar</artifactId>
			<artifactId>sigar</artifactId>
			<version>1.6.4</version>
			<version>1.6.4</version>
			<exclusions>
				<exclusion>
					<groupId>log4j</groupId>
					<artifactId>log4j</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.21</version>
		</dependency>
		</dependency>
	</dependencies>
	</dependencies>

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

@ -3,9 +3,11 @@ package com.yihu.hos;
import com.yihu.hos.common.listener.ApplicationStartListener;
import com.yihu.hos.common.listener.ApplicationStartListener;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableScheduling
@EnableScheduling
public class HosBrokerApplication {
public class HosBrokerApplication {

+ 4 - 5
hos-broker/src/main/java/com/yihu/hos/common/appender/JMSAppender.java

@ -319,10 +319,9 @@ public class JMSAppender extends AppenderSkeleton {
      String message = event.getMessage().toString();
      String message = event.getMessage().toString();
      String routeId = StringUtil.toString(event.getMDC("camel.routeId"));
      String routeId = StringUtil.toString(event.getMDC("camel.routeId"));
      if (message.contains("("+routeId+") log[servers:")) {
      if (message.contains("("+routeId+") log[servers:")) {
        System.out.println("-------------------------------------------------");
        System.out.println(message);
        String body = message.substring(message.indexOf("Body:") + 5);
        String body = message.substring(message.indexOf("Body:") + 5);
        String totalServers = message.substring(message.indexOf("log[servers:") + 13, message.indexOf("]"));
        String totalServers = message.substring(message.indexOf("log[servers:") + 13, message.indexOf(","));
        String serverName = message.substring(message.indexOf("name") + 6, message.indexOf("]"));
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> map = new HashMap<>();
        map.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
        map.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
        map.put("correlationId", StringUtil.toString(event.getMDC("camel.correlationId")));
        map.put("correlationId", StringUtil.toString(event.getMDC("camel.correlationId")));
@ -331,12 +330,12 @@ public class JMSAppender extends AppenderSkeleton {
        map.put("breadcrumbId",StringUtil.toString(event.getMDC("camel.breadcrumbId")));
        map.put("breadcrumbId",StringUtil.toString(event.getMDC("camel.breadcrumbId")));
        map.put("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
        map.put("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
        map.put("totalServers", Integer.parseInt(totalServers));
        map.put("totalServers", Integer.parseInt(totalServers));
        map.put("serverName", serverName);
        map.put("body", body);
        map.put("body", body);
        map.put("fireTimeSource", DateUtil.toStringFormatGMTTime(DateUtil.toGMTTime(event.getTimeStamp()), DateUtil.DEFAULT_TIMESTAMP_FORMAT));
        map.put("fireTimeSource", DateUtil.toStringFormatGMTTime(DateUtil.toGMTTime(event.getTimeStamp()), DateUtil.DEFAULT_TIMESTAMP_FORMAT));
        msg.setObject(JSONObject.fromObject(map).toString());
        msg.setObject(JSONObject.fromObject(map).toString());
        topicPublisher.publish(msg);
      }
      }
      topicPublisher.publish(msg);
    } catch(JMSException e) {
    } catch(JMSException e) {
      errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
      errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
			 ErrorCode.GENERIC_FAILURE);
			 ErrorCode.GENERIC_FAILURE);

+ 18 - 3
hos-broker/src/main/java/com/yihu/hos/common/scheduler/EnvScheduler.java

@ -6,12 +6,14 @@ import com.yihu.hos.common.util.SigarUtil;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.services.ServiceMonitorService;
import net.sf.json.JSONArray;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONObject;
import org.bson.Document;
import org.bson.Document;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Date;
import java.util.List;
import java.util.List;
@ -22,15 +24,19 @@ import java.util.List;
 * Created at 2016/10/11.
 * Created at 2016/10/11.
 */
 */
@Component
@Component
public class EnvScheduler {
public class MonitorScheduler {
    static private final Logger logger = LoggerFactory.getLogger(EnvScheduler.class);
    static private final Logger logger = LoggerFactory.getLogger(MonitorScheduler.class);
    private static String host = SigarUtil.getHost();
    private static String host = SigarUtil.getHost();
    @Resource(name = ServiceMonitorService.BEAN_ID)
    private ServiceMonitorService serviceMonitorService;
    @Scheduled(cron="0 0/1 * * * ?") //每分钟执行一次
    @Scheduled(cron="0 0/1 * * * ?") //每分钟执行一次
    public void statusCheck() {
    public void statusCheck() {
        System.out.println("每分钟执行一次。开始============================================");
        System.out.println("每分钟执行一次。开始============================================");
        //TODO 采集服务器健康监控指标数据 statusTask.healthCheck();
        //TODO 采集服务器健康监控指标数据 statusTask.healthCheck();
        collectEnvHealth();
        collectEnvHealth();
        collectServiceHealth();
        System.out.println("每分钟执行一次。结束。");
        System.out.println("每分钟执行一次。结束。");
    }
    }
@ -72,7 +78,16 @@ public class EnvScheduler {
        return "";
        return "";
    }
    }
    public void collectServiceHealth(){
        Date now = new Date();
        Date beforeDate = new Date(now.getTime() - 60000);
        System.out.println(DateUtil.toString(beforeDate, DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
        System.out.println(DateUtil.toString(now, DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
//        serviceMonitorService.bandwidth(beforeDate.toString(), now.toString());
//        serviceMonitorService.qps(beforeDate.toString(), now.toString());
//        serviceMonitorService.delay(beforeDate.toString(), now.toString());
//        serviceMonitorService.usage(beforeDate.toString(), now.toString());
    }
//    @Scheduled(fixedRate=10000)
//    @Scheduled(fixedRate=10000)
//    public void testTasks() {
//    public void testTasks() {

+ 9 - 9
hos-broker/src/main/java/com/yihu/hos/controllers/ServerMonitorController.java

@ -1,6 +1,6 @@
package com.yihu.hos.controllers;
package com.yihu.hos.controllers;
import com.yihu.hos.services.ServerMonitorService;
import com.yihu.hos.services.ServiceMonitorService;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiParam;
@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.annotation.Resource;
@Controller
@Controller
@RequestMapping("/server")
public class ServerMonitorController {
    @Resource(name = ServerMonitorService.BEAN_ID)
    private ServerMonitorService serverMonitorService;
@RequestMapping("/service")
public class ServiceMonitorController {
    @Resource(name = ServiceMonitorService.BEAN_ID)
    private ServiceMonitorService serviceMonitorService;
    @RequestMapping(value = "/bandwidth", method = RequestMethod.POST)
    @RequestMapping(value = "/bandwidth", method = RequestMethod.POST)
    @ResponseBody
    @ResponseBody
@ -26,7 +26,7 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.bandwidth(beginTime, endTime);
        return serviceMonitorService.bandwidth(beginTime, endTime);
    }
    }
    @RequestMapping(value = "/qps", method = RequestMethod.POST)
    @RequestMapping(value = "/qps", method = RequestMethod.POST)
@ -37,7 +37,7 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.qps(beginTime, endTime);
        return serviceMonitorService.qps(beginTime, endTime);
    }
    }
    @RequestMapping(value = "/usage", method = RequestMethod.POST)
    @RequestMapping(value = "/usage", method = RequestMethod.POST)
@ -48,7 +48,7 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.usage(beginTime, endTime);
        return serviceMonitorService.usage(beginTime, endTime);
    }
    }
    @RequestMapping(value = "/delay", method = RequestMethod.POST)
    @RequestMapping(value = "/delay", method = RequestMethod.POST)
@ -59,6 +59,6 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.delay(beginTime, endTime);
        return serviceMonitorService.delay(beginTime, endTime);
    }
    }
}
}

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

@ -22,6 +22,7 @@ public class BusinessLog {
    @Indexed
    @Indexed
    private String breadcrumbId;
    private String breadcrumbId;
    private Integer totalServers;
    private Integer totalServers;
    private String serverName;
    private String camelContextId;
    private String camelContextId;
    private String body;
    private String body;
    private Integer bodyLength;
    private Integer bodyLength;
@ -126,4 +127,12 @@ public class BusinessLog {
    public void setTotalServers(Integer totalServers) {
    public void setTotalServers(Integer totalServers) {
        this.totalServers = totalServers;
        this.totalServers = totalServers;
    }
    }
    public String getServerName() {
        return serverName;
    }
    public void setServerName(String serverName) {
        this.serverName = serverName;
    }
}
}

+ 72 - 0
hos-broker/src/main/java/com/yihu/hos/models/ServiceMetrics.java

@ -0,0 +1,72 @@
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 = "serviceMetrics")
public class ServiceMetrics {
    @Id
    private String id;
    @Indexed
    private String routeId;
    @Indexed
    private String breadcrumbId;
    private String type;
    private String value;
    private String createTime;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getRouteId() {
        return routeId;
    }
    public void setRouteId(String routeId) {
        this.routeId = routeId;
    }
    public String getBreadcrumbId() {
        return breadcrumbId;
    }
    public void setBreadcrumbId(String breadcrumbId) {
        this.breadcrumbId = breadcrumbId;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
}

+ 86 - 13
hos-broker/src/main/java/com/yihu/hos/services/ServerMonitorService.java

@ -5,6 +5,7 @@ import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.datatype.NumberUtil;
import com.yihu.hos.core.datatype.NumberUtil;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.models.BusinessLog;
import com.yihu.hos.models.BusinessLog;
import com.yihu.hos.models.ServiceMetrics;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.Result;
import org.json.JSONObject;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,10 +18,9 @@ import java.util.Date;
/**
/**
 * Created by chenweida on 2016/1/27.
 * Created by chenweida on 2016/1/27.
 */
 */
@Service("ServerMonitorService")
public class ServerMonitorService {
    public static final String BEAN_ID = "ServerMonitorService";
    public static final String reduceTableName = "reduceResult";
@Service("ServiceMonitorService")
public class ServiceMonitorService {
    public static final String BEAN_ID = "ServiceMonitorService";
    @Autowired
    @Autowired
    private MongoOperations mongoOperations;
    private MongoOperations mongoOperations;
@ -94,21 +94,29 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        DBObject match = new BasicDBObject("$match", queryObject);
        // Now the $group operation
        // Now the $group operation
        DBObject groupFields = new BasicDBObject( "_id", "$breadcrumbId");
        DBObject groupFields = new BasicDBObject( "_id",
                new BasicDBObject("breadcrumbId", "$breadcrumbId")
                .append("routeId", "$routeId"));
//        groupFields.put("routeId", new BasicDBObject( "$first", "$routeId"));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
        groupFields.put("endTime", new BasicDBObject( "$last", "$fireTimeSource"));
        groupFields.put("endTime", new BasicDBObject("$last", "$fireTimeSource"));
        DBObject group = new BasicDBObject("$group", groupFields);
        DBObject group = new BasicDBObject("$group", groupFields);
        // build the $sort operation
        // build the $sort operation
        DBObject sortFields =  new BasicDBObject( "_id", 1);
        DBObject sortFields =  new BasicDBObject( "_id", 1);
        DBObject sort = new BasicDBObject("$sort", sortFields );
        DBObject sort = new BasicDBObject("$sort", sortFields );
        // run aggregation
        // run aggregation
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer calls = 0;
        Integer calls = 0;
        long interval = 0;
        long interval = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
        for (DBObject dbObject : output.results()) {
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            BasicDBObject id = (BasicDBObject) dbObject.get("_id");
            routeId = StringUtil.toString(id.get("routeId"));
            breadcrumbId  = StringUtil.toString(id.get("breadcrumbId"));
            if (count >= 2) {
            if (count >= 2) {
                calls++;
                calls++;
                String begin = StringUtil.toString(dbObject.get("beginTime"));
                String begin = StringUtil.toString(dbObject.get("beginTime"));
@ -118,8 +126,20 @@ public class ServerMonitorService {
                interval += (to.getTime() - from.getTime())/1000;
                interval += (to.getTime() - from.getTime())/1000;
            }
            }
        }
        }
        BigDecimal bandwidth = NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval));
        ServiceMetrics serviceMetrics = new ServiceMetrics();
        serviceMetrics.setRouteId(routeId);
        serviceMetrics.setBreadcrumbId(breadcrumbId);
        serviceMetrics.setType("bandwidth");
        serviceMetrics.setValue(bandwidth.toString());
        serviceMetrics.setCreateTime(endTime);
        mongoOperations.save(serviceMetrics);
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("bandwidth", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        result.put("bandwidth", bandwidth);
        System.out.println(result);
        return Result.success(result.toString());
        return Result.success(result.toString());
    }
    }
@ -136,7 +156,9 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        DBObject match = new BasicDBObject("$match", queryObject);
        // Now the $group operation
        // Now the $group operation
        DBObject groupFields = new BasicDBObject( "_id", "$breadcrumbId");
        DBObject groupFields = new BasicDBObject( "_id",
                new BasicDBObject("breadcrumbId", "$breadcrumbId")
                        .append("routeId", "$routeId"));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("total", new BasicDBObject( "$first", "$totalServers"));
        groupFields.put("total", new BasicDBObject( "$first", "$totalServers"));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
@ -150,8 +172,13 @@ public class ServerMonitorService {
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer calls = 0;
        Integer calls = 0;
        long interval = 0;
        long interval = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
        for (DBObject dbObject : output.results()) {
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            BasicDBObject id = (BasicDBObject) dbObject.get("_id");
            routeId = StringUtil.toString(id.get("routeId"));
            breadcrumbId  = StringUtil.toString(id.get("breadcrumbId"));
            if (count >= 2) {
            if (count >= 2) {
                Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
                Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
                if (total == count) {
                if (total == count) {
@ -164,8 +191,18 @@ public class ServerMonitorService {
                }
                }
            }
            }
        }
        }
        BigDecimal qps = NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval));
        ServiceMetrics serviceMetrics = new ServiceMetrics();
        serviceMetrics.setRouteId(routeId);
        serviceMetrics.setBreadcrumbId(breadcrumbId);
        serviceMetrics.setType("qps");
        serviceMetrics.setValue(qps.toString());
        serviceMetrics.setCreateTime(endTime);
        mongoOperations.save(serviceMetrics);
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("qps", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        result.put("qps", qps);
        return Result.success(result.toString());
        return Result.success(result.toString());
    }
    }
@ -182,7 +219,9 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        DBObject match = new BasicDBObject("$match", queryObject);
        // Now the $group operation
        // Now the $group operation
        DBObject groupFields = new BasicDBObject( "_id", "$breadcrumbId");
        DBObject groupFields = new BasicDBObject( "_id",
                new BasicDBObject("breadcrumbId", "$breadcrumbId")
                        .append("routeId", "$routeId"));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("total", new BasicDBObject( "$first", "$totalServers"));
        groupFields.put("total", new BasicDBObject( "$first", "$totalServers"));
        DBObject group = new BasicDBObject("$group", groupFields);
        DBObject group = new BasicDBObject("$group", groupFields);
@ -194,19 +233,35 @@ public class ServerMonitorService {
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer successCount = 0;
        Integer successCount = 0;
        Integer failureCount = 0;
        Integer failureCount = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
        for (DBObject dbObject : output.results()) {
            Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
            Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            BasicDBObject id = (BasicDBObject) dbObject.get("_id");
            routeId = StringUtil.toString(id.get("routeId"));
            breadcrumbId  = StringUtil.toString(id.get("breadcrumbId"));
            if (total == count) {
            if (total == count) {
                successCount++;
                successCount++;
            } else {
            } else {
                failureCount++;
                failureCount++;
            }
            }
        }
        }
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("totalCount", successCount + failureCount);
        result.put("totalCount", successCount + failureCount);
        result.put("successCount", successCount);
        result.put("successCount", successCount);
        result.put("failureCount", failureCount);
        result.put("failureCount", failureCount);
        ServiceMetrics serviceMetrics = new ServiceMetrics();
        serviceMetrics.setRouteId(routeId);
        serviceMetrics.setBreadcrumbId(breadcrumbId);
        serviceMetrics.setType("usage");
        serviceMetrics.setValue(result.toString());
        serviceMetrics.setCreateTime(endTime);
        mongoOperations.save(serviceMetrics);
        return Result.success(result.toString());
        return Result.success(result.toString());
    }
    }
@ -223,7 +278,9 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        DBObject match = new BasicDBObject("$match", queryObject);
        // Now the $group operation
        // Now the $group operation
        DBObject groupFields = new BasicDBObject( "_id", "$breadcrumbId");
        DBObject groupFields = new BasicDBObject( "_id",
                new BasicDBObject("breadcrumbId", "$breadcrumbId")
                        .append("routeId", "$routeId"));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("count", new BasicDBObject( "$sum", 1));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
        groupFields.put("endTime", new BasicDBObject( "$last", "$fireTimeSource"));
        groupFields.put("endTime", new BasicDBObject( "$last", "$fireTimeSource"));
@ -236,8 +293,13 @@ public class ServerMonitorService {
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer calls = 0;
        Integer calls = 0;
        long interval = 0;
        long interval = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
        for (DBObject dbObject : output.results()) {
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
            BasicDBObject id = (BasicDBObject) dbObject.get("_id");
            routeId = StringUtil.toString(id.get("routeId"));
            breadcrumbId  = StringUtil.toString(id.get("breadcrumbId"));
            if (count >= 2) {
            if (count >= 2) {
                calls++;
                calls++;
                String begin = StringUtil.toString(dbObject.get("beginTime"));
                String begin = StringUtil.toString(dbObject.get("beginTime"));
@ -247,8 +309,19 @@ public class ServerMonitorService {
                interval += (to.getTime() - from.getTime())/1000;
                interval += (to.getTime() - from.getTime())/1000;
            }
            }
        }
        }
        BigDecimal delay =  NumberUtil.divideBigDecimal(BigDecimal.valueOf(interval), BigDecimal.valueOf(calls));
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("delay", NumberUtil.divideBigDecimal(BigDecimal.valueOf(interval), BigDecimal.valueOf(calls)));
        result.put("delay", delay);
        ServiceMetrics serviceMetrics = new ServiceMetrics();
        serviceMetrics.setRouteId(routeId);
        serviceMetrics.setBreadcrumbId(breadcrumbId);
        serviceMetrics.setType("delay");
        serviceMetrics.setValue(delay.toString());
        serviceMetrics.setCreateTime(endTime);
        mongoOperations.save(serviceMetrics);
        return Result.success(result.toString());
        return Result.success(result.toString());
    }
    }
}
}

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

@ -21,7 +21,7 @@ timer:
---
---
spring:
spring:
  profiles: hzy
  profiles: dev
  datasource:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://172.19.103.71:3306/esb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
    url: jdbc:mysql://172.19.103.71:3306/esb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true

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

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

+ 12 - 0
hos-web-framework-dependencies/pom.xml

@ -101,6 +101,12 @@
        <dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        </dependency>
        <dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <groupId>org.mongodb</groupId>
@ -113,6 +119,12 @@
            <groupId>org.apache.camel</groupId>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
            <version>${camel.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        </dependency>
        <dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <groupId>org.apache.camel</groupId>

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

@ -29,70 +29,19 @@ public class ServiceMonitorController {
    //跳转到列表页
    //跳转到列表页
    @RequestMapping("/initial")
    @RequestMapping("/initial")
    public String serviceInitial(Model model) {
    public String serviceInitial(Model model) {
        model.addAttribute("contentPage", "/service/sEnvManage");
        model.addAttribute("contentPage", "/monitor/service/sEnvManage");
        return "partView";
        return "partView";
    }
    }
//    @RequestMapping(value = "/service/bandwidth", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation(value = "服务指标获取", produces = "application/json", notes = "服务指标获取")
//    public String serviceMetrics(
//            Model model,
//            @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";
//    }
    @RequestMapping(value = "/bandwidth", method = RequestMethod.POST)
    @RequestMapping(value = "/server/metrics", method = RequestMethod.GET)
    @ResponseBody
    @ResponseBody
    @ApiOperation(value = "获取带宽", produces = "application/json", notes = "获取带宽")
    public Result bandwidth(
    @ApiOperation(value = "获取服务指标", produces = "application/json", notes = "获取服务指标")
    public Result metrics(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
            @RequestParam(value = "endTime") String endTime) {
        return monitorService.bandwidth(beginTime, endTime);
    }
    @RequestMapping(value = "/qps", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取吞吐量", produces = "application/json", notes = "获取吞吐量")
    public Result qps(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return monitorService.qps(beginTime, endTime);
    }
    @RequestMapping(value = "/usage", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取使用率", produces = "application/json", notes = "获取使用率")
    public Result usage(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return monitorService.usage(beginTime, endTime);
    }
    @RequestMapping(value = "/delay", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取延时", produces = "application/json", notes = "获取延时")
    public Result delay(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return monitorService.delay(beginTime, endTime);
        return monitorService.metrics(beginTime, endTime);
    }
    }
}
}

+ 9 - 0
src/main/java/com/yihu/hos/monitor/model/BusinessLog.java

@ -22,6 +22,7 @@ public class BusinessLog {
    @Indexed
    @Indexed
    private String breadcrumbId;
    private String breadcrumbId;
    private Integer totalServers;
    private Integer totalServers;
    private String serverName;
    private String camelContextId;
    private String camelContextId;
    private String body;
    private String body;
    private Integer bodyLength;
    private Integer bodyLength;
@ -126,4 +127,12 @@ public class BusinessLog {
    public void setTotalServers(Integer totalServers) {
    public void setTotalServers(Integer totalServers) {
        this.totalServers = totalServers;
        this.totalServers = totalServers;
    }
    }
    public String getServerName() {
        return serverName;
    }
    public void setServerName(String serverName) {
        this.serverName = serverName;
    }
}
}

+ 24 - 55
src/main/java/com/yihu/hos/monitor/service/ServiceMonitorService.java

@ -87,53 +87,20 @@ public class ServiceMonitorService {
//        return jsonObject;
//        return jsonObject;
//    }
//    }
    public Result getMonitorInfo(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());
        }
        ActionResult actionResult = new ActionResult();
        actionResult.setData(result);
        return actionResult;
    public Result metrics(String beginTime, String endTime) {
        JSONObject bandwidth = bandwidth(beginTime, endTime);
        JSONObject qps = qps(beginTime, endTime);
        JSONObject delay = delay(beginTime, endTime);
        JSONObject usage = usage(beginTime, endTime);
        JSONArray jsonArray = new JSONArray();
        jsonArray.put(bandwidth);
        jsonArray.put(qps);
        jsonArray.put(delay);
        jsonArray.put(usage);
        return Result.success(jsonArray.toString());
    }
    }
    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;
    }
    public Result bandwidth(String beginTime, String endTime) {
    public JSONObject bandwidth(String beginTime, String endTime) {
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
                .getCollectionName(BusinessLog.class));
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -172,10 +139,10 @@ public class ServiceMonitorService {
        }
        }
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("bandwidth", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        result.put("bandwidth", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        return Result.success(result.toString());
        return result;
    }
    }
    public Result qps(String beginTime, String endTime) {
    public JSONObject qps(String beginTime, String endTime) {
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
                .getCollectionName(BusinessLog.class));
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -218,10 +185,10 @@ public class ServiceMonitorService {
        }
        }
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("qps", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        result.put("qps", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        return Result.success(result.toString());
        return result;
    }
    }
    public Result usage(String beginTime, String endTime) {
    public JSONObject usage(String beginTime, String endTime) {
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
                .getCollectionName(BusinessLog.class));
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -255,14 +222,16 @@ public class ServiceMonitorService {
                failureCount++;
                failureCount++;
            }
            }
        }
        }
        JSONObject count = new JSONObject();
        count.put("totalCount", successCount + failureCount);
        count.put("successCount", successCount);
        count.put("failureCount", failureCount);
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("totalCount", successCount + failureCount);
        result.put("successCount", successCount);
        result.put("failureCount", failureCount);
        return Result.success(result.toString());
        result.put("usage", count);
        return result;
    }
    }
    public Result delay(String beginTime, String endTime) {
    public JSONObject delay(String beginTime, String endTime) {
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
        DBCollection businessLog = mongoOperations.getCollection(mongoOperations
                .getCollectionName(BusinessLog.class));
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -301,6 +270,6 @@ public class ServiceMonitorService {
        }
        }
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        result.put("delay", NumberUtil.divideBigDecimal(BigDecimal.valueOf(interval), BigDecimal.valueOf(calls)));
        result.put("delay", NumberUtil.divideBigDecimal(BigDecimal.valueOf(interval), BigDecimal.valueOf(calls)));
        return Result.success(result.toString());
        return result;
    }
    }
}
}

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

@ -0,0 +1,60 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@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-bor-r{border-right: 0;}
    .c-item.active{background: #16B3EE;color:#fff}
    .ml50{margin-left: 50px;}
    .mt20{margin-top: 20px;}
    .mb20{margin-bottom: 20px;}
    .f-dis-inline{display: inline-block;}
    .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;}
    .c-content{font-size: 16px;display: inline-block;width: 100px;font-weight: bold;}
    .div-right-item{font-size: 12px;width: 150px;}
</style>
<!-- ####### 页面部分 ####### -->
<div id="div_wrapper">
    <!--左边 区域-->
    <div position="left"  style="margin-left:10px;margin-top:10px;">
        <div class="m-form-control" style="margin-bottom: 15px">
            <input type="text" id="div_wrapper_left_inp_search" placeholder="请输入服务器名"/>
        </div>
        <ul id="div_wrapper_left_ul_resourcetree" class="m-snav"></ul>
    </div>
    <div position="center" style="margin-left:10px;margin-top:10px;margin-right:10px;">
        <!-- ####### 查询条件部分 ####### -->
        <div class="m-form-inline" data-role-form>
            <div class="m-form-group">
                <label style="width: 100px;">开始时间:</label>
                <div class="m-form-control">
                    <input id="repeatStartTime" type="text" />
                </div>
                <label style="width: 100px;">结束时间:</label>
                <div class="m-form-control">
                    <input id="repeatEndTime" type="text" />
                </div>
                <div class="m-form-control">
                    <div id="btnSearch" class="l-button">
                        <span>搜索</span>
                    </div>
                </div>
            </div>
            <%-- echarts 数据--%>
            <div id="main1" style="width: 600px;height:400px;border: solid deepskyblue 1px;"></div>
            <%-- echarts 数据--%>
            <div id="main2" style="width: 600px;height:400px;border: solid deepskyblue 1px;"></div>
            <%-- echarts 数据--%>
            <div id="main3" style="width: 600px;height:400px;border: solid deepskyblue 1px;"></div>
            <%-- echarts 数据--%>
            <div id="main4" style="width: 600px;height:400px;border: solid deepskyblue 1px;"></div>
        </div>
    </div>
</div>

+ 329 - 0
src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManageJs.jsp

@ -0,0 +1,329 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script src="${contextRoot}/develop/lib/plugin/echarts/echarts-all.js"></script>
<script>
    $(function () {
        //l-layout-left
        //初始化layout
        $("#div_wrapper").ligerLayout({
            height: "99%",
            leftWidth: 200,
            isLeftCollapse: false,//左边区域初始化不可以隐藏
            allowLeftCollapse: false//左边区域不可以隐藏
        });
        /*初始化时间控件-start*/
        $("#repeatStartTime").ligerDateEditor({
            width: 240,
            showTime: true
        });
        $("#repeatEndTime").ligerDateEditor({
            width: 240,
            showTime: true
        });
        /*初始化时间控件-end*/
        //初始化图表
        var beginTime = $("#repeatStartTime").ligerDateEditor("getValue");
        var endTime = $("#repeatEndTime").ligerDateEditor("getValue");
        getServiceInfo(beginTime,endTime);
        //搜索按钮事件
        $(".m-form-control").on("click","#btnSearch",function(){
            var beginTime = $("#repeatStartTime").ligerDateEditor("getValue");
            var endTime = $("#repeatEndTime").ligerDateEditor("getValue");
            if(beginTime=="" && $endTime=="")
            {
                $.ligerDialog.error("请选择起始结束时间!");
                return false;
            }
            //获取服务器监控数据
            getServiceInfo(beginTime,endTime);
        })
    });
    function getServiceInfo(beginTime,endTime){
        $.ajax({
            type: "GET",
            url : "${contextRoot}/monitor/service/metrics",
            dataType : "json",
            data:{beginTime:beginTime,endTime:endTime},
            cache:false,
            success :function(re){
                if(re.successFlg) {
                    //TODO 设置图表
                            service.bandwidth(re);
                            service.qps(re);
                            service.delay(re);
                            service.usage(re);
                } else {
                    $.ligerDialog.error(re.message);
                }
            },
            error :function(data){
                $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
            }
        });
    }
    var service = {
        bandwidth:function(re){
             var me = this;
             var data = re.data;
             if(data!=null && data.length>0)
             {
                 var x = [];
                 var y = [];
                 for(var i=0;i<data.length;i++)
                 {
                     var create_date = data[i].create_date.substring(11,16);
                     x.push(create_date);
                     y.push(data[i].data.totalPerc);
                 }
                 // 基于准备好的dom,初始化echarts实例
                 var myChart = echarts.init(document.getElementById('main1'));
                 // 指定图表的配置项和数据
                 var option = {
                     title: {
                         text: ' CPU指标',
                         left: 'center'
                     },
                     tooltip: {
                         trigger: 'axis'
                     },
                     legend: {
                         left: 'left',
                         data: ['总使用率']
                     },
                     xAxis: {
                         type: 'category',
                         name: '时间',
                         splitLine: {show: false},
                         data: x
                     },
                     grid: {
                         left: '3%',
                         right: '4%',
                         bottom: '3%',
                         containLabel: true
                     },
                     yAxis: {
                         type: 'log',
                         name: '使用率'
                     },
                     series: [
                         {
                             name: '总使用率',
                             type: 'line',
                             data: y
                         },
                     ]
                 };
             myChart.setOption(option);
             //设置图例下方的信息
             } else {
                 me.clearTop();
             }
        },
        qps:function(re){
            var me = this;
            var data = re.data;
            if(data!=null && data.length>0)
            {
                var x = [];
                var y = [];
                for(var i=0;i<data.length;i++)
                {
                    var create_date = data[i].create_date.substring(11,16);
                    x.push(create_date);
                    y.push(data[i].data.usedPerc);
                }
                // 基于准备好的dom,初始化echarts实例
                var myChart = echarts.init(document.getElementById('main2'));
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: ' 内存使用率指标',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        left: 'left',
                        data: ['使用率']
                    },
                    xAxis: {
                        type: 'category',
                        name: '时间',
                        splitLine: {show: false},
                        data: x
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    yAxis: {
                        type: 'log',
                        name: '使用率'
                    },
                    series: [
                        {
                            name: '使用率',
                            type: 'line',
                            data: y
                        },
                    ]
                };
                myChart.setOption(option);
            }
            else{
                me.clearTop();
            }
        },
        delay:function(re){
            var me = this;
            var data = re.data;
            if(data!=null && data.length>0)
            {
                var x = [];
                var y = [];
                for(var i=0;i<data.length;i++)
                {
                    var create_date = data[i].create_date.substring(11,16);
                    x.push(create_date);
                    y.push(data[i].total);
                }
                // 基于准备好的dom,初始化echarts实例
                var myChart = echarts.init(document.getElementById('main3'));
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: ' 磁盘指标',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        left: 'left',
                        data: ['已使用']
                    },
                    xAxis: {
                        type: 'category',
                        name: '时间',
                        splitLine: {show: false},
                        data: x
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    yAxis: {
                        type: 'log',
                        name: '使用率'
                    },
                    series: [
                        {
                            name: '已使用',
                            type: 'line',
                            data: y
                        }
                    ]
                };
                myChart.setOption(option);
            }
            else{
                me.clearTop();
            }
        },
        usage:function(re){
            var me = this;
            var data = re.data;
            if(data!=null && data.length>0)
            {
                var x = [];
                var y = [];
                for(var i=0;i<data.length;i++)
                {
                    var create_date = data[i].create_date.substring(11,16);
                    x.push(create_date);
                    y.push(data[i].data.rxbps);
                }
                // 基于准备好的dom,初始化echarts实例
                var myChart = echarts.init(document.getElementById('main4'));
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: ' 网络指标',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        left: 'left',
                        data: ['接收']
                    },
                        xAxis: {
                        type: 'category',
                        name: '时间',
                        splitLine: {show: false},
                        data: x
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    yAxis: {
                        type: 'log',
                        name: '使用率(kbps)'
                    },
                    series: [
                        {
                            name: '接收',
                            type: 'line',
                            data: y
                        }
                    ]
                };
                myChart.setOption(option);
            }
            else{
                me.clearTop();
            }
        }
    }
    /*当前时间*/
    function nowDate(){
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        return year + '-' + month + '-' + day  + ' ' + hour + ':' + minute + ':' + second;
    }
    /*前一天时间*/
    function prevDate(){
        var now = new Date();
        var date = new Date(now.getTime() -  24 * 3600 * 1000);
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        return year + '-' + month + '-' + day  + ' 00:00:00';
    }
</script>