Authored by simba

update

@@ -10,5 +10,7 @@ public class ZookeeperInfo { @@ -10,5 +10,7 @@ public class ZookeeperInfo {
10 private int id; 10 private int id;
11 private String hostIp; 11 private String hostIp;
12 private int isLive; 12 private int isLive;
  13 + private String redcordTime;
  14 +
13 15
14 } 16 }
1 package com.monitor.middleware.zookeeper; 1 package com.monitor.middleware.zookeeper;
2 2
  3 +import org.apache.zookeeper.KeeperException;
  4 +import org.apache.zookeeper.WatchedEvent;
  5 +import org.apache.zookeeper.Watcher;
  6 +import org.apache.zookeeper.ZooKeeper;
3 import org.slf4j.Logger; 7 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
5 import org.springframework.scheduling.annotation.Scheduled; 9 import org.springframework.scheduling.annotation.Scheduled;
6 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
7 11
  12 +import java.io.IOException;
  13 +import java.util.ArrayList;
  14 +import java.util.List;
  15 +
8 /** 16 /**
9 * Created by yoho on 2016/6/21. 17 * Created by yoho on 2016/6/21.
10 */ 18 */
@@ -17,9 +25,50 @@ public class ZookeeperMonitorTask { @@ -17,9 +25,50 @@ public class ZookeeperMonitorTask {
17 @Scheduled(fixedRate=10000) 25 @Scheduled(fixedRate=10000)
18 public void run() { 26 public void run() {
19 log.info("task start..."); 27 log.info("task start...");
20 - System.out.println("************************************************************"); 28 + List<String> ipList=new ArrayList<String>();
  29 + ipList.add("172.31.50.190");
  30 + ipList.add("172.31.50.191");
  31 + ipList.add("172.31.50.192");
  32 + ipList.add("172.31.50.193");
  33 + ipList.add("172.31.50.194");
  34 + ipList.add("10.66.4.3");
  35 + ipList.add("10.66.4.4");
  36 + ipList.add("10.66.4.5");
  37 + ipList.add("10.66.4.8");
  38 + ipList.add("10.66.4.9");
  39 +
  40 + for(String ip:ipList){
  41 + boolean result=true;
  42 + try {
  43 + result=checkConnection(ip);
  44 + } catch (Exception e) {
  45 + result=false;
  46 + }
  47 + }
  48 +
21 log.info("task end..."); 49 log.info("task end...");
22 50
23 } 51 }
24 52
  53 +
  54 + public static boolean checkConnection(String ip) throws IOException, KeeperException, InterruptedException {
  55 + ZooKeeper zk = new ZooKeeper("192.168.102.205:2181", 500000,
  56 + new Watcher() {
  57 +
  58 + @Override
  59 + public void process(WatchedEvent event) {
  60 + // TODO Auto-generated method stub
  61 +
  62 + }
  63 + });
  64 + // 获取某路径下所有节点
  65 + List<String> children = zk.getChildren("/", false);
  66 + for (String child : children)
  67 + {
  68 + System.out.println("this---->"+child);
  69 + }
  70 + System.out.println("--------get children ok-----------");
  71 + return true;
  72 + }
  73 +
25 } 74 }