|  | @ -3,14 +3,13 @@ package com.yihu.hos.broker.common.scheduler;
 | 
	
		
			
				|  |  | import com.mongodb.*;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.common.constants.MonitorConstant;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.daos.BrokerDao;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.util.MongodbUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemServiceEndpoint;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemServiceFlow;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.services.ServiceMonitorService;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.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.broker.models.SystemServiceEndpoint;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemServiceFlow;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.services.ServiceMonitorService;
 | 
	
		
			
				|  |  | import net.sf.json.JSONArray;
 | 
	
		
			
				|  |  | import net.sf.json.JSONObject;
 | 
	
		
			
				|  |  | import org.bson.Document;
 | 
	
	
		
			
				|  | @ -36,17 +35,14 @@ import java.util.List;
 | 
	
		
			
				|  |  | @Component
 | 
	
		
			
				|  |  | public class MonitorScheduler {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     static private final Logger logger = LoggerFactory.getLogger(MonitorScheduler.class);
 | 
	
		
			
				|  |  |     private static String host = SigarUtil.getHost();
 | 
	
		
			
				|  |  |     @Value("${hos.tenant.name}")
 | 
	
		
			
				|  |  |     private String tenant;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MongoOperations mongoOperations;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private Mongo mongo;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     static private final Logger logger = LoggerFactory.getLogger(MonitorScheduler.class);
 | 
	
		
			
				|  |  |     private static String host = SigarUtil.getHost();
 | 
	
		
			
				|  |  |     @Resource(name = ServiceMonitorService.BEAN_ID)
 | 
	
		
			
				|  |  |     private ServiceMonitorService serviceMonitorService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
	
		
			
				|  | @ -67,41 +63,45 @@ public class MonitorScheduler {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 服务器健康指标采集
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String collectEnvHealth() {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             MongodbUtil monoEnv = new MongodbUtil(MonitorConstant.MONITOR);
 | 
	
		
			
				|  |  |             mongoOperations = new MongoTemplate(mongo, MonitorConstant.MONITOR);
 | 
	
		
			
				|  |  |             Document result = null;
 | 
	
		
			
				|  |  |             result = new Document();
 | 
	
		
			
				|  |  |             result.put("tenant",tenant);
 | 
	
		
			
				|  |  |             result.put("tenant", tenant);
 | 
	
		
			
				|  |  |             result.put("create_date", DateUtil.getCurrentString(DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
 | 
	
		
			
				|  |  |             result.put("create_time", new Date());
 | 
	
		
			
				|  |  |             result.put("host",host);
 | 
	
		
			
				|  |  |             result.put("host", host);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //cpu
 | 
	
		
			
				|  |  |             JSONObject cpu = JSONObject.fromObject(SigarUtil.cpu());
 | 
	
		
			
				|  |  |             result.put("data", cpu);
 | 
	
		
			
				|  |  |             result.put("type", MonitorConstant.CPU);
 | 
	
		
			
				|  |  |             monoEnv.insert(MonitorConstant.SERVER, result);
 | 
	
		
			
				|  |  |             mongoOperations.insert(result, MonitorConstant.SERVER);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //内存
 | 
	
		
			
				|  |  |             JSONObject memory = JSONObject.fromObject(SigarUtil.memory());
 | 
	
		
			
				|  |  |             result.put("data", memory);
 | 
	
		
			
				|  |  |             result.put("type", MonitorConstant.MEMORY);
 | 
	
		
			
				|  |  |             result.remove("_id");
 | 
	
		
			
				|  |  |             monoEnv.insert(MonitorConstant.SERVER, result);
 | 
	
		
			
				|  |  |             mongoOperations.insert(result, MonitorConstant.SERVER);
 | 
	
		
			
				|  |  |             //硬盘
 | 
	
		
			
				|  |  |             List<JSONObject> files = JSONArray.fromObject(SigarUtil.file());
 | 
	
		
			
				|  |  |             result.put("data", files);
 | 
	
		
			
				|  |  |             result.put("type", MonitorConstant.FILES);
 | 
	
		
			
				|  |  |             result.remove("_id");
 | 
	
		
			
				|  |  |             monoEnv.insert(MonitorConstant.SERVER, result);
 | 
	
		
			
				|  |  |             mongoOperations.insert(result, MonitorConstant.SERVER);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //网络
 | 
	
		
			
				|  |  |             JSONObject net = JSONObject.fromObject(SigarUtil.net());
 | 
	
		
			
				|  |  |             result.put("data", net);
 | 
	
		
			
				|  |  |             result.put("type", MonitorConstant.NET);
 | 
	
		
			
				|  |  |             result.remove("_id");
 | 
	
		
			
				|  |  |             monoEnv.insert(MonitorConstant.SERVER, result);
 | 
	
		
			
				|  |  |             mongoOperations.insert(result, MonitorConstant.SERVER);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
	
		
			
				|  | @ -131,21 +131,12 @@ public class MonitorScheduler {
 | 
	
		
			
				|  |  |         serviceMonitorService.usage(beginTime, endTime, codeList);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //    @Scheduled(fixedRate=10000)
 | 
	
		
			
				|  |  | //    public void testTasks() {
 | 
	
		
			
				|  |  | //        logger.info("每10秒执行一次。开始……");
 | 
	
		
			
				|  |  | //        //statusTask.healthCheck();
 | 
	
		
			
				|  |  | //        logger.info("每10秒执行一次。结束。");
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 服务器列表保存
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  | //    @Scheduled(cron = "0 0 12 * * ?") //每天中午12点触发
 | 
	
		
			
				|  |  |     @Scheduled(fixedDelay = 3600*24*1000,initialDelay=3000) //每天中午12点触发
 | 
	
		
			
				|  |  |     @Scheduled(fixedDelay = 3600 * 24 * 1000, initialDelay = 3000) //每天中午12点触发
 | 
	
		
			
				|  |  |     public void checkHost() {
 | 
	
		
			
				|  |  |         MongodbUtil monoEnv = new MongodbUtil(MonitorConstant.MONITOR);
 | 
	
		
			
				|  |  |         mongoOperations = new MongoTemplate(mongo, MonitorConstant.MONITOR);
 | 
	
		
			
				|  |  |         DBCollection envCollection = mongoOperations.getCollection(MonitorConstant.HOST);
 | 
	
		
			
				|  |  |         BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
 | 
	
	
		
			
				|  | @ -159,10 +150,10 @@ public class MonitorScheduler {
 | 
	
		
			
				|  |  |                 Document result = new Document();
 | 
	
		
			
				|  |  |                 String host = SigarUtil.getHost();
 | 
	
		
			
				|  |  |                 String hostName = SigarUtil.getHostName();
 | 
	
		
			
				|  |  |                 result.put("tenant",tenant);
 | 
	
		
			
				|  |  |                 result.put("name",  hostName);
 | 
	
		
			
				|  |  |                 result.put("host",  host);
 | 
	
		
			
				|  |  |                 monoEnv.insert(MonitorConstant.HOST, result);
 | 
	
		
			
				|  |  |                 result.put("tenant", tenant);
 | 
	
		
			
				|  |  |                 result.put("name", hostName);
 | 
	
		
			
				|  |  |                 result.put("host", host);
 | 
	
		
			
				|  |  |                 mongoOperations.insert(result, MonitorConstant.HOST);
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 |