|
|
package com.monitor.middleware.zookeeper.task;
|
|
|
|
|
|
import com.monitor.influxdb.model.ZkInfo;
|
|
|
import org.apache.zookeeper.KeeperException;
|
|
|
import org.apache.zookeeper.ZooKeeper;
|
|
|
import com.monitor.middleware.zookeeper.service.IZkMonitorService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2016/6/21.
|
|
|
*/
|
...
|
...
|
@@ -20,43 +15,13 @@ public class ZookeeperMonitorTask { |
|
|
|
|
|
Logger log = LoggerFactory.getLogger(ZookeeperMonitorTask.class);
|
|
|
|
|
|
@Autowired
|
|
|
IZkMonitorService zkMonitorService;
|
|
|
|
|
|
@Scheduled(fixedRate=10000)
|
|
|
public void run() {
|
|
|
log.info("task start...");
|
|
|
List<String> ipList=new ArrayList<String>();
|
|
|
ipList.add("172.31.50.190");
|
|
|
ipList.add("172.31.50.191");
|
|
|
ipList.add("172.31.50.192");
|
|
|
ipList.add("172.31.50.193");
|
|
|
ipList.add("172.31.50.194");
|
|
|
ipList.add("10.66.4.3");
|
|
|
ipList.add("10.66.4.4");
|
|
|
ipList.add("10.66.4.5");
|
|
|
ipList.add("10.66.4.8");
|
|
|
ipList.add("10.66.4.9");
|
|
|
|
|
|
List<ZkInfo> zkList=new ArrayList<ZkInfo>();
|
|
|
for(String ip:ipList){
|
|
|
boolean result=true;
|
|
|
try {
|
|
|
result=checkConnection(ip);
|
|
|
} catch (Exception e) {
|
|
|
result=false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.info("task end...");
|
|
|
|
|
|
@Scheduled(fixedRate=5000)
|
|
|
public void zookeeperMonitor() {
|
|
|
zkMonitorService.zookeeperMonitor();
|
|
|
}
|
|
|
|
|
|
|
|
|
public static boolean checkConnection(String ip) throws IOException, KeeperException, InterruptedException {
|
|
|
ZooKeeper zk = new ZooKeeper("192.168.102.205:2181", 2000,null);
|
|
|
// 获取某路径下所有节点
|
|
|
List<String> children = zk.getChildren("/", false);
|
|
|
// log.info("checkConnection is param { },size is { }",ip,null==children?0:children.size());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|