Authored by FengRuwei

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

... ... @@ -7,5 +7,5 @@ import com.monitor.influxdb.model.ZookeeperInfo;
*/
public interface IZookeeperMapper {
public void insert(String influxDBName,ZookeeperInfo zkInfo);
public void insert(ZookeeperInfo zkInfo);
}
... ...
... ... @@ -24,7 +24,7 @@ public class ZookeeperMapper implements IZookeeperMapper{
Random random = new Random();
@Override
public void insert(String influxDBName, ZookeeperInfo zkInfo) {
public void insert(ZookeeperInfo zkInfo) {
Point point = Point.measurement(InfluxDBContants.ZOOKEEPER_ALARM)
.addField("id", zkInfo.getId())
... ...
... ... @@ -9,8 +9,21 @@ import lombok.Data;
public class ZookeeperInfo {
private int id;
private String hostIp;
private int isLive;
private int isLive; //0是不活动,1是活动
private String redcordTime;
public ZookeeperInfo() {
super();
}
public ZookeeperInfo(String hostIp, int isLive) {
super();
this.hostIp = hostIp;
this.isLive = isLive;
}
}
... ...
package com.monitor.middleware.zookeeper;
/**
* Created by zhengyouwei on 2016/6/20.
*/
public class Test {
}
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;
}
}
... ...
package com.monitor.middleware.zookeeper;
package com.monitor.middleware.zookeeper.task;
import com.monitor.influxdb.model.ZookeeperInfo;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -37,6 +36,7 @@ public class ZookeeperMonitorTask {
ipList.add("10.66.4.8");
ipList.add("10.66.4.9");
List<ZookeeperInfo> zkList=new ArrayList<ZookeeperInfo>();
for(String ip:ipList){
boolean result=true;
try {
... ... @@ -52,22 +52,10 @@ public class ZookeeperMonitorTask {
public static boolean checkConnection(String ip) throws IOException, KeeperException, InterruptedException {
ZooKeeper zk = new ZooKeeper("192.168.102.205:2181", 500000,
new Watcher() {
@Override
public void process(WatchedEvent event) {
// TODO Auto-generated method stub
}
});
ZooKeeper zk = new ZooKeeper("192.168.102.205:2181", 2000,null);
// 获取某路径下所有节点
List<String> children = zk.getChildren("/", false);
for (String child : children)
{
System.out.println("this---->"+child);
}
System.out.println("--------get children ok-----------");
// log.info("checkConnection is param { },size is { }",ip,null==children?0:children.size());
return true;
}
... ...