Преглед изворни кода

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

Airhead пре 8 година
родитељ
комит
c5b6a59465
22 измењених фајлова са 950 додато и 264 уклоњено
  1. 11 1
      hos-broker/pom.xml
  2. 3 1
      hos-broker/src/main/java/com/yihu/hos/HosBrokerApplication.java
  3. 4 5
      hos-broker/src/main/java/com/yihu/hos/common/appender/JMSAppender.java
  4. 18 0
      hos-broker/src/main/java/com/yihu/hos/common/constants/MonitorConstant.java
  5. 32 14
      hos-broker/src/main/java/com/yihu/hos/common/scheduler/EnvScheduler.java
  6. 26 12
      hos-broker/src/main/java/com/yihu/hos/common/util/SigarUtil.java
  7. 9 9
      hos-broker/src/main/java/com/yihu/hos/controllers/ServerMonitorController.java
  8. 9 0
      hos-broker/src/main/java/com/yihu/hos/models/BusinessLog.java
  9. 72 0
      hos-broker/src/main/java/com/yihu/hos/models/ServiceMetrics.java
  10. 86 13
      hos-broker/src/main/java/com/yihu/hos/services/ServerMonitorService.java
  11. 1 1
      hos-broker/src/main/resources/application.yml
  12. 4 4
      hos-camel/src/main/java/qlc/route/QlcRouteBulider.java
  13. 12 0
      hos-web-framework-dependencies/pom.xml
  14. 26 1
      src/main/java/com/yihu/hos/monitor/controller/ServerMonitorController.java
  15. 5 56
      src/main/java/com/yihu/hos/monitor/controller/ServiceMonitorController.java
  16. 9 0
      src/main/java/com/yihu/hos/monitor/model/BusinessLog.java
  17. 48 2
      src/main/java/com/yihu/hos/monitor/service/ServerMonitorService.java
  18. 24 55
      src/main/java/com/yihu/hos/monitor/service/ServiceMonitorService.java
  19. 36 36
      src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManage.jsp
  20. 126 54
      src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManageJs.jsp
  21. 60 0
      src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManage.jsp
  22. 329 0
      src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManageJs.jsp

+ 11 - 1
hos-broker/pom.xml

@ -62,8 +62,18 @@
			<groupId>org.fusesource</groupId>
			<artifactId>sigar</artifactId>
			<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>
	</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 org.springframework.boot.SpringApplication;
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;
@SpringBootApplication
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableScheduling
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 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("]"));
        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.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
        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("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
        map.put("totalServers", Integer.parseInt(totalServers));
        map.put("serverName", serverName);
        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);
      }
      topicPublisher.publish(msg);
    } catch(JMSException e) {
      errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
			 ErrorCode.GENERIC_FAILURE);

+ 18 - 0
hos-broker/src/main/java/com/yihu/hos/common/constants/MonitorConstant.java

@ -0,0 +1,18 @@
package com.yihu.hos.common.constants;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/11/3.
 */
public class MonitorConstant {
    public static String HOST = "host";
    public static String CPU = "cpu";
    public static String FILES = "files";
    public static String MEMORY = "memory";
    public static String NET = "net";
}

+ 32 - 14
hos-broker/src/main/java/com/yihu/hos/common/scheduler/EnvScheduler.java

@ -1,16 +1,19 @@
package com.yihu.hos.common.scheduler;
import com.yihu.hos.common.constants.MonitorConstant;
import com.yihu.hos.common.util.MongodbUtil;
import com.yihu.hos.common.util.SigarUtil;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.services.ServiceMonitorService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.bson.Document;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@ -21,41 +24,53 @@ import java.util.List;
 * Created at 2016/10/11.
 */
@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();
    @Resource(name = ServiceMonitorService.BEAN_ID)
    private ServiceMonitorService serviceMonitorService;
    @Scheduled(cron="0 0/1 * * * ?") //每分钟执行一次
    public void statusCheck() {
        System.out.println("每分钟执行一次。开始============================================");
        //TODO 采集服务器健康监控指标数据 statusTask.healthCheck();
        collectEnvHealth();
        collectServiceHealth();
        System.out.println("每分钟执行一次。结束。");
    }
    public String collectEnvHealth(){
        try {
            MongodbUtil monoEnv = new MongodbUtil("envHealth");
            Document result = new Document();
            Document result = null;
            result = new Document();
            result.put("create_date", DateUtil.getCurrentString(DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
            result.put("create_time", new Date());
            //cpu
            JSONObject cpu = JSONObject.fromObject( SigarUtil.cpu());
            result.put("data",cpu);
            monoEnv.insert("cpu",result);
            result.put("type", MonitorConstant.CPU);
            monoEnv.insert(host,result);
            //内存
            JSONObject memory = JSONObject.fromObject( SigarUtil.memory());
            result.put("data",memory);
            monoEnv.insert("memory",result);
            result.put("type", MonitorConstant.MEMORY);
            result.remove("_id");
            monoEnv.insert(host,result);
            //硬盘
            List<JSONObject> files = JSONArray.fromObject( SigarUtil.file());
            result.put("data",files);
            monoEnv.insert("files", result);
            result.put("type", MonitorConstant.FILES);
            result.remove("_id");
            monoEnv.insert(host, result);
            //网络
            JSONObject net = JSONObject.fromObject( SigarUtil.net());
            result.put("data",net);
            monoEnv.insert("net",result);
            result.put("type", MonitorConstant.NET);
            result.remove("_id");
            monoEnv.insert(host,result);
        } catch (Exception e) {
            e.printStackTrace();
@ -63,13 +78,16 @@ public class EnvScheduler {
        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)
//    public void testTasks() {

+ 26 - 12
hos-broker/src/main/java/com/yihu/hos/common/util/SigarUtil.java

@ -74,6 +74,18 @@ public class SigarUtil {
     *
     * @throws UnknownHostException
     */
    public static String getHost(){
        try {
            InetAddress addr = InetAddress.getLocalHost();
            String ip = addr.getHostAddress();
            return ip;
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return "unknowHost";
    }
    private static void property() throws UnknownHostException {
        Runtime r = Runtime.getRuntime();
        Properties props = System.getProperties();
@ -152,24 +164,25 @@ public class SigarUtil {
    public static Map<String, Object> cpu()  {
        Map<String, Object> cpuMap = new HashMap<>();
        try {
            Cpu timer = sigar.getCpu();
            CpuInfo infos[] = sigar.getCpuInfoList();
            CpuPerc cpuPerc = sigar.getCpuPerc();
            CpuInfo info1 = infos[0];
            //cpu信息
            cpuMap.put("quantity", infos.length);
            cpuMap.put("model", info1.getModel());
            cpuMap.put("totalCores", info1.getTotalCores());
            cpuMap.put("totalSockets", info1.getTotalSockets());
            cpuMap.put("model", info1.getModel());// CPU型号
            cpuMap.put("totalCores", info1.getTotalCores());// CPU逻辑个数
            cpuMap.put("totalSockets", info1.getTotalSockets());// CPU物理个数
            cpuMap.put("Mhz", info1.getMhz());
            //cpu使用率
            String totalPerc = String.format("%.2f", cpuPerc.getCombined() * 100);
            String userPerc = String.format("%.2f", cpuPerc.getUser() * 100);
            String sysPerc = String.format("%.2f", cpuPerc.getSys() * 100);
            String wait = String.format("%.2f", cpuPerc.getWait() * 100);
            String nice = String.format("%.2f", cpuPerc.getNice() * 100);
            String freePerc = String.format("%.2f", cpuPerc.getIdle() * 100);
            cpuMap.put("cores",info1.getCoresPerSocket());//核数
            long cacheSize = info1.getCacheSize();
            if (cacheSize != Sigar.FIELD_NOTIMPL) {
                cpuMap.put("cache",info1.getCacheSize());//核数
            }
            //cpu使用率
            cpuMap.put("timer",timer.getUser());//核数
            cpuMap.put("totalPerc", getDouble(cpuPerc.getCombined() * 100));
            cpuMap.put("userPerc", getDouble(cpuPerc.getUser() * 100));
            cpuMap.put("sysPerc", getDouble(cpuPerc.getSys() * 100));
@ -177,7 +190,7 @@ public class SigarUtil {
            cpuMap.put("nice", getDouble(cpuPerc.getNice() * 100));
            cpuMap.put("freePerc", getDouble(cpuPerc.getIdle() * 100));
        }catch (SigarException e){
        } catch (SigarException e){
            e.printStackTrace();
        }
        return cpuMap;
@ -366,4 +379,5 @@ public class SigarUtil {
        return Double.parseDouble(total);
    }
}

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

@ -1,6 +1,6 @@
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 io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
@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)
    @ResponseBody
@ -26,7 +26,7 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.bandwidth(beginTime, endTime);
        return serviceMonitorService.bandwidth(beginTime, endTime);
    }
    @RequestMapping(value = "/qps", method = RequestMethod.POST)
@ -37,7 +37,7 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.qps(beginTime, endTime);
        return serviceMonitorService.qps(beginTime, endTime);
    }
    @RequestMapping(value = "/usage", method = RequestMethod.POST)
@ -48,7 +48,7 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.usage(beginTime, endTime);
        return serviceMonitorService.usage(beginTime, endTime);
    }
    @RequestMapping(value = "/delay", method = RequestMethod.POST)
@ -59,6 +59,6 @@ public class ServerMonitorController {
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @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
    private String breadcrumbId;
    private Integer totalServers;
    private String serverName;
    private String camelContextId;
    private String body;
    private Integer bodyLength;
@ -126,4 +127,12 @@ public class BusinessLog {
    public void setTotalServers(Integer 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.StringUtil;
import com.yihu.hos.models.BusinessLog;
import com.yihu.hos.models.ServiceMetrics;
import com.yihu.hos.web.framework.model.Result;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,10 +18,9 @@ import java.util.Date;
/**
 * 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
    private MongoOperations mongoOperations;
@ -94,21 +94,29 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        // 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("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);
        // build the $sort operation
        DBObject sortFields =  new BasicDBObject( "_id", 1);
        DBObject sort = new BasicDBObject("$sort", sortFields );
        // run aggregation
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer calls = 0;
        long interval = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
            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) {
                calls++;
                String begin = StringUtil.toString(dbObject.get("beginTime"));
@ -118,8 +126,20 @@ public class ServerMonitorService {
                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();
        result.put("bandwidth", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        result.put("bandwidth", bandwidth);
        System.out.println(result);
        return Result.success(result.toString());
    }
@ -136,7 +156,9 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        // 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("total", new BasicDBObject( "$first", "$totalServers"));
        groupFields.put("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
@ -150,8 +172,13 @@ public class ServerMonitorService {
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer calls = 0;
        long interval = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
            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) {
                Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
                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();
        result.put("qps", NumberUtil.divideBigDecimal(BigDecimal.valueOf(calls), BigDecimal.valueOf(interval)));
        result.put("qps", qps);
        return Result.success(result.toString());
    }
@ -182,7 +219,9 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        // 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("total", new BasicDBObject( "$first", "$totalServers"));
        DBObject group = new BasicDBObject("$group", groupFields);
@ -194,19 +233,35 @@ public class ServerMonitorService {
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer successCount = 0;
        Integer failureCount = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
            Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
            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) {
                successCount++;
            } else {
                failureCount++;
            }
        }
        JSONObject result = new JSONObject();
        result.put("totalCount", successCount + failureCount);
        result.put("successCount", successCount);
        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());
    }
@ -223,7 +278,9 @@ public class ServerMonitorService {
        DBObject match = new BasicDBObject("$match", queryObject);
        // 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("beginTime", new BasicDBObject( "$first", "$fireTimeSource"));
        groupFields.put("endTime", new BasicDBObject( "$last", "$fireTimeSource"));
@ -236,8 +293,13 @@ public class ServerMonitorService {
        AggregationOutput output = businessLog.aggregate(match, group, sort);
        Integer calls = 0;
        long interval = 0;
        String routeId = "";
        String breadcrumbId = "";
        for (DBObject dbObject : output.results()) {
            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) {
                calls++;
                String begin = StringUtil.toString(dbObject.get("beginTime"));
@ -247,8 +309,19 @@ public class ServerMonitorService {
                interval += (to.getTime() - from.getTime())/1000;
            }
        }
        BigDecimal delay =  NumberUtil.divideBigDecimal(BigDecimal.valueOf(interval), BigDecimal.valueOf(calls));
        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());
    }
}

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

@ -21,7 +21,7 @@ timer:
---
spring:
  profiles: hzy
  profiles: dev
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    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
    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"))
                .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"))
                .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"))
                .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>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
@ -113,6 +119,12 @@
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>

+ 26 - 1
src/main/java/com/yihu/hos/monitor/controller/ServerMonitorController.java

@ -39,13 +39,38 @@ public class ServerMonitorController {
    @ResponseBody
    @ApiOperation(value = "获取服务器使用率", produces = "application/json", notes = "获取服务器硬件使用率")
    public Result usage(
            @ApiParam(name = "host", value = "服务器IP", required = true)
            @RequestParam(value = "host") String host,
            @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) {
        return monitorService.getMonitorInfo(type, beginTime, endTime);
        host = monitorService.getHost();
        return monitorService.getMonitorList(host,type, beginTime, endTime);
    }
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取服务器详情信息", produces = "application/json", notes = "获取服务器详情信息")
    public Result detail(
            @ApiParam(name = "host", value = "服务器IP", required = true)
            @RequestParam(value = "host") String host,
            @ApiParam(name = "type", value = "类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "date", value = "时间点", required = true)
            @RequestParam(value = "date") String date) {
        host = monitorService.getHost();
        return monitorService.getMonitorDetail(host,type, date);
    }
    @RequestMapping(value = "/hosts", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取服务器列表", produces = "application/json", notes = "获取服务器列表")
    public Result hosts() {
        return monitorService.getHosts();
    }

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

@ -29,70 +29,19 @@ public class ServiceMonitorController {
    //跳转到列表页
    @RequestMapping("/initial")
    public String serviceInitial(Model model) {
        model.addAttribute("contentPage", "/service/sEnvManage");
        model.addAttribute("contentPage", "/monitor/service/sEnvManage");
        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
    @ApiOperation(value = "获取带宽", produces = "application/json", notes = "获取带宽")
    public Result bandwidth(
    @ApiOperation(value = "获取服务指标", produces = "application/json", notes = "获取服务指标")
    public Result metrics(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @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
    private String breadcrumbId;
    private Integer totalServers;
    private String serverName;
    private String camelContextId;
    private String body;
    private Integer bodyLength;
@ -126,4 +127,12 @@ public class BusinessLog {
    public void setTotalServers(Integer totalServers) {
        this.totalServers = totalServers;
    }
    public String getServerName() {
        return serverName;
    }
    public void setServerName(String serverName) {
        this.serverName = serverName;
    }
}

+ 48 - 2
src/main/java/com/yihu/hos/monitor/service/ServerMonitorService.java

@ -10,6 +10,12 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
 * Created by chenweida on 2016/1/27.
 */
@ -24,11 +30,12 @@ public class ServerMonitorService {
    @Autowired
    private Mongo mongo;
    public Result getMonitorInfo(String table,String beginTime, String endTime) {
    public Result getMonitorList(String table, String type, 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("type",type),
                        new BasicDBObject().append("create_time",
                                new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
                        new BasicDBObject().append("create_time",
@ -40,7 +47,6 @@ public class ServerMonitorService {
            DBObject dbObject = cursor.next();
            dbObject.removeField("_id");
            result.put(dbObject);
            System.out.println(dbObject.toString());
        }
        ActionResult actionResult = new ActionResult();
@ -48,4 +54,44 @@ public class ServerMonitorService {
        return actionResult;
    }
    public Result getMonitorDetail(String host, String type, String date) {
        mongoOperations = new MongoTemplate(mongo, envHealth);
        DBCollection envCollection = mongoOperations.getCollection(host);
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
                new BasicDBObject[]{
                        new BasicDBObject().append("type", type),
                        new BasicDBObject().append("create_time",new BasicDBObject().append(QueryOperators.LTE, DateUtil.toTimestamp(date)))});
        Map result = new HashMap<>();
        DBCursor cursor = envCollection.find(queryObject).sort(new BasicDBObject("create_time",-1)).limit(1);
        while(cursor.hasNext()) {
            DBObject dbObject = cursor.next();
            dbObject.removeField("_id");
            result = dbObject.toMap();
        }
        ActionResult actionResult = new ActionResult();
        actionResult.setData(result);
        return actionResult;
    }
    public static String getHost(){
        try {
            InetAddress addr = InetAddress.getLocalHost();
            String ip = addr.getHostAddress();
            return ip;
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return "unknowHost";
    }
    public Result getHosts() {
        mongoOperations = new MongoTemplate(mongo, envHealth);
        Set<String> collections = mongoOperations.getCollectionNames();
        ActionResult actionResult = new ActionResult();
        actionResult.setData(collections);
        return actionResult;
    }
}

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

@ -87,53 +87,20 @@ public class ServiceMonitorService {
//        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
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -172,10 +139,10 @@ public class ServiceMonitorService {
        }
        JSONObject result = new JSONObject();
        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
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -218,10 +185,10 @@ public class ServiceMonitorService {
        }
        JSONObject result = new JSONObject();
        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
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -255,14 +222,16 @@ public class ServiceMonitorService {
                failureCount++;
            }
        }
        JSONObject count = new JSONObject();
        count.put("totalCount", successCount + failureCount);
        count.put("successCount", successCount);
        count.put("failureCount", failureCount);
        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
                .getCollectionName(BusinessLog.class));
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -301,6 +270,6 @@ public class ServiceMonitorService {
        }
        JSONObject result = new JSONObject();
        result.put("delay", NumberUtil.divideBigDecimal(BigDecimal.valueOf(interval), BigDecimal.valueOf(calls)));
        return Result.success(result.toString());
        return result;
    }
}

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

@ -58,44 +58,44 @@
            <div class="c-item" data-item="net">网络</div>
        </div>
            <%-- echarts 数据--%>
        <div id="main" style="width: 60%;height:400px;border: solid deepskyblue 1px;"></div>
        <div id="main" style="width: 80%;height:400px;border: solid deepskyblue 1px;"></div>
            <%-- 详细数据 --%>
            <div class="ml50 mt20">
                <div class="div-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="d-item">进程</div>
                        <div class="d-item">线程</div>
                        <div class="d-item">句柄</div>
                    </div>
                    <div class="mb20">
                        <div class="c-content">107</div>
                        <div class="c-content">1720</div>
                        <div class="c-content">59868</div>
                    </div>
                    <div class="f-dis-inline f-fs12">正常运行时间</div>
                    <div class="mb20">
                        <div class="c-content">11:19:15:40</div>
                    </div>
                </div>
                <div class="div-item">
                    <div class="div-right-item">最大速度:<span class="f-fs14 c-fwb">2.19GHZ</span></div>
                    <div class="div-right-item">插槽:<span class="f-fs14 c-fwb">1</span></div>
                    <div class="div-right-item">内核:<span class="f-fs14 c-fwb">2</span></div>
                    <div class="div-right-item">编辑处理器:<span class="f-fs14 c-fwb">4</span></div>
                    <div class="div-right-item">虚拟化:<span class="f-fs14 c-fwb">已启用</span></div>
                    <div class="div-right-item">L1缓存:<span class="f-fs14 c-fwb">121KB</span></div>
                    <div class="div-right-item">L2缓存:<span class="f-fs14 c-fwb">512KB</span></div>
                    <div class="div-right-item">L3缓存:<span class="f-fs14 c-fwb">3.0MB</span></div>
                </div>
            <div id="detail" class="ml50 mt20">
                <%--<div class="div-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="d-item">进程</div>--%>
                        <%--<div class="d-item">线程</div>--%>
                        <%--<div class="d-item">句柄</div>--%>
                    <%--</div>--%>
                    <%--<div class="mb20">--%>
                        <%--<div class="c-content">107</div>--%>
                        <%--<div class="c-content">1720</div>--%>
                        <%--<div class="c-content">59868</div>--%>
                    <%--</div>--%>
                    <%--<div class="f-dis-inline f-fs12">正常运行时间</div>--%>
                    <%--<div class="mb20">--%>
                        <%--<div class="c-content">11:19:15:40</div>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="div-item">--%>
                    <%--<div class="div-right-item">最大速度:<span class="f-fs14 c-fwb">2.19GHZ</span></div>--%>
                    <%--<div class="div-right-item">插槽:<span class="f-fs14 c-fwb">1</span></div>--%>
                    <%--<div class="div-right-item">内核:<span class="f-fs14 c-fwb">2</span></div>--%>
                    <%--<div class="div-right-item">编辑处理器:<span class="f-fs14 c-fwb">4</span></div>--%>
                    <%--<div class="div-right-item">虚拟化:<span class="f-fs14 c-fwb">已启用</span></div>--%>
                    <%--<div class="div-right-item">L1缓存:<span class="f-fs14 c-fwb">121KB</span></div>--%>
                    <%--<div class="div-right-item">L2缓存:<span class="f-fs14 c-fwb">512KB</span></div>--%>
                    <%--<div class="div-right-item">L3缓存:<span class="f-fs14 c-fwb">3.0MB</span></div>--%>
                <%--</div>--%>
            </div>

+ 126 - 54
src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManageJs.jsp

@ -1,6 +1,7 @@
<%@ 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 src="${contextRoot}/develop/echarts/echarts.js"></script>--%>
<script>
    $(function () {
@ -30,8 +31,9 @@
        var type = $(".div-menu .active").attr("data-item");
        var beginTime = $("#repeatStartTime").ligerDateEditor("getValue");
        var endTime = $("#repeatEndTime").ligerDateEditor("getValue");
        getServerInfo(type,beginTime,endTime);
        var host = '192.168.131.11'; //TODO 通过树获取服务器IP
        getServerInfo(host,type,beginTime,endTime);
        getCpnInfo(host,type,endTime);
        //搜索按钮事件
        $(".m-form-control").on("click","#btnSearch",function(){
@ -44,8 +46,10 @@
            }
            var type = $(".div-menu .active").attr("data-item");
            var host = '192.168.131.11'; //TODO 通过树获取服务器IP
            //获取服务器监控数据
            getServerInfo(type,beginTime,endTime);
            getServerInfo(host,type,beginTime,endTime);
            getCpnInfo(host,type,endTime);
        })
        //选项卡切换时间
@ -56,17 +60,18 @@
            //获取服务器监控数据
            var beginTime = $("#repeatStartTime").ligerDateEditor("getValue");
            var endTime = $("#repeatEndTime").ligerDateEditor("getValue");
            getServerInfo(type,beginTime,endTime);
            var host = '192.168.131.11'; //TODO 通过树获取服务器IP
            getServerInfo(host,type,beginTime,endTime);
            getCpnInfo(host,type,endTime);
        })
    });
    function getServerInfo(type,beginTime,endTime){
    function getServerInfo(host,type,beginTime,endTime){
        $.ajax({
            type: "GET",
            url : "${contextRoot}/monitor/server/usage",
            dataType : "json",
            data:{type:type,beginTime:beginTime,endTime:endTime},
            data:{host:host,type:type,beginTime:beginTime,endTime:endTime},
            cache:false,
            success :function(re){
                if(re.successFlg) {
@ -100,21 +105,44 @@
    }
    var env ={
        $resourceTree: $("#div_wrapper_left_ul_resourcetree"),//树对象
    init:function(){
            //初始化树
            var resourceTree = this.$resourceTree;
            $.ajax({
                type: "POST",
                url: "${contextRoot}/monitor/server/hosts",
                success: function (msg) {
                    // 初始化树形菜单
                    resourceTree = resourceTree.ligerTree({
                        data: msg.data,
                        idFieldName: 'id',
                        nodeWidth: 200,
                        parentIDFieldName: 'pid',
                        isExpand: false,
                        onClick: function (obj) {
                            rsResoureManege.reloadGridTree(obj.data.id, rsResoureManege.$searchresourceName.val());
                            rsResoureManege.$resourceTreeId=obj.data.id;
                        },
                        onSuccess: function (data) {
                        }
                    });
                }
            });
        },
        cpuInfo:function(re){
         var data = re.data;
         if(data!=null && data.length>0)
         {
             var count = 0
             var success =0;
             var x = [];
             var y1=[];
             var y2=[];
             for(var i=0;i<data.length;i++)
             {
                 var create_date = data[i].create_date.substring(11,16);
                 x.push(create_date);
                 count += data[i].data.totalPerc;
                 success += data[i].data.userPerc;
//                 var create_date = data[i].create_date.substring(11,16);
//                 x.push(create_date);
                 x.push(data[i].create_date);
                 y1.push(data[i].data.totalPerc);
                 y2.push(data[i].data.userPerc);
             }
@ -129,6 +157,11 @@
                 tooltip: {
                     trigger: 'axis'
                 },
                 dataZoom : {
                     show : true,
                     start : 0,
                     end : 100
                 },
                 legend: {
                     left: 'left',
                     data: ['总使用率', '用户使用率']
@ -165,11 +198,12 @@
                 ]
             };
             myChart.setOption(option);
             myChart.on('mouseover', function (params) {
//                 getCpnInfo(host,type,params.name);
                 console.log(params);
             });
             //设置图例下方的信息
         }
         else{
            //TODO 清除数据处理
@ -179,8 +213,6 @@
            var data = re.data;
            if(data!=null && data.length>0)
            {
                var count = 0
                var success =0;
                var x = [];
                var y1=[];
                var y2=[];
@ -188,7 +220,6 @@
                {
                    var create_date = data[i].create_date.substring(11,16);
                    x.push(create_date);
                    count += data[i].data.usedPerc;
                    y1.push(data[i].data.usedPerc);
                    y2.push(data[i].data.freePerc);
                }
@ -203,6 +234,11 @@
                    tooltip: {
                        trigger: 'axis'
                    },
                    dataZoom : {
                        show : true,
                        start : 0,
                        end : 100
                    },
                    legend: {
                        left: 'left',
                        data: ['使用率', '空闲率']
@ -273,6 +309,11 @@
                    tooltip: {
                        trigger: 'axis'
                    },
                    dataZoom : {
                        show : true,
                        start : 0,
                        end : 100
                    },
                    legend: {
                        left: 'left',
                        data: ['已使用', '总量']
@ -338,6 +379,11 @@
                    tooltip: {
                        trigger: 'axis'
                    },
                    dataZoom : {
                        show : true,
                        start : 0,
                        end : 100
                    },
                    legend: {
                        left: 'left',
                        data: ['接收', '发送']
@ -405,42 +451,68 @@
    /* **************************动态DIV添加************************ */
    /* CPU 详情数据*/
    function getCpnInfo(host,type,date){
        $.ajax({
            type: "GET",
            url : "${contextRoot}/monitor/server/detail",
            dataType : "json",
            data:{host:host,type:type,date:date},
            cache:false,
            success :function(re){
                if(re.successFlg) {
                    //TODO 设置详情数据
                    var data = re.data;
                    if(data!=null && data!=''>0){
                        var envData = data.data;
                        debugger
                        var $envInfo = $("#detail");
                        var html = "<div class=\"div-item\">\n" +
                                "                    <div>\n" +
                                "                        <div class=\"d-item\">利用率</div>" +
                                "                        <div class=\"d-item\">速度</div>" +
                                "                    </div>" +
                                "                    <div class=\"mb20\">\n" +
                                "                        <div class=\"c-content\">"+envData.userPerc+"%</div>" +
                                "                        <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\">"+envData.model.substring(envData.model.length-8)+"</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\">"+envData.cores+"</span></div>\n" +
                                "                    <div class=\"div-right-item\">逻辑处理器:<span class=\"f-fs14 c-fwb\">"+envData.totalCores+"</span></div>\n" +
                                "                    <div class=\"div-right-item\">物理处理器:<span class=\"f-fs14 c-fwb\">"+envData.totalSockets+"</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>";
    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>";
                        $envInfo.html(html);
                    }
                }
                else{
                    $.ligerDialog.error(re.message);
                }
            },
            error :function(data){
                $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
            }
        });
    }
</script>

+ 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>