|
|
package com.monitor.middleware.zookeeper.service;
|
|
|
|
|
|
import com.monitor.influxdb.mapper.IZookeeperMapper;
|
|
|
import com.monitor.influxdb.model.ZookeeperInfo;
|
|
|
import org.apache.zookeeper.KeeperException;
|
|
|
import org.apache.zookeeper.ZooKeeper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2016/6/21.
|
|
|
*/
|
|
|
@Service
|
|
|
public class IZookeeperMonitorService {
|
|
|
|
|
|
Logger log = LoggerFactory.getLogger(IZookeeperMonitorService.class);
|
|
|
|
|
|
@Autowired
|
|
|
IZookeeperMapper zookeeperMapper;
|
|
|
|
|
|
public void zookeeperMonitor(){
|
|
|
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<ZookeeperInfo> zkList=new ArrayList<ZookeeperInfo>();
|
|
|
ZookeeperInfo zk=null;
|
|
|
for(String ip:ipList){
|
|
|
int result=1;
|
|
|
try {
|
|
|
result=checkConnection(ip);
|
|
|
} catch (Exception e) {
|
|
|
result=0;
|
|
|
}
|
|
|
zookeeperMapper.insert(new ZookeeperInfo(ip,result));
|
|
|
}
|
|
|
|
|
|
log.info("task end...");
|
|
|
}
|
|
|
|
|
|
|
|
|
private int 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 1;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|