├── .gitignore ├── README.txt ├── pom.xml ├── taokeeper-build ├── .gitignore ├── build.cmd ├── etc │ ├── config-daily-etao.properties │ ├── config-daily-tbdw.properties │ ├── config-daily.properties │ ├── config-online-etao.properties │ ├── config-online.properties │ ├── config-qdcm5.properties │ ├── config-tencent.properties │ ├── config-test.properties │ └── taokeeper.sql └── pom.xml ├── taokeeper-common ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── taobao │ └── taokeeper │ ├── common │ ├── GlobalInstance.java │ ├── SystemInfo.java │ ├── constant │ │ ├── SqlTemplate.java │ │ └── SystemConstant.java │ ├── type │ │ └── NodePathCheckRule.java │ └── util │ │ └── AlarmSettingUtil.java │ ├── dao │ ├── AlarmSettingsDAO.java │ ├── ReportDAO.java │ ├── SettingsDAO.java │ ├── ZooKeeperClusterDAO.java │ └── impl │ │ ├── AlarmSettingsDAOImpl.java │ │ ├── ReportDAOImpl.java │ │ ├── SettingsDAOImpl.java │ │ └── ZooKeeperClusterDAOImpl.java │ └── model │ ├── AlarmSettings.java │ ├── Subscriber.java │ ├── TaoKeeperSettings.java │ ├── TaoKeeperStat.java │ ├── ZooKeeperCluster.java │ ├── ZooKeeperStatus.java │ └── type │ ├── EnvType.java │ └── Message.java ├── taokeeper-monitor ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── taobao │ │ └── taokeeper │ │ └── monitor │ │ ├── core │ │ ├── Initialization.java │ │ ├── ThreadPoolManager.java │ │ └── task │ │ │ ├── CheckerJob.java │ │ │ ├── HostPerformanceCollectTask.java │ │ │ ├── ZooKeeperALiveCheckerJob.java │ │ │ ├── ZooKeeperClusterMapDumpJob.java │ │ │ ├── ZooKeeperNodeChecker.java │ │ │ ├── ZooKeeperStatusCollectJob.java │ │ │ └── runable │ │ │ ├── ClientThroughputStatJob.java │ │ │ ├── ZKClusterConfigDumper.java │ │ │ ├── ZKServerAliveCheck.java │ │ │ ├── ZKServerPerformanceCollector.java │ │ │ └── ZKServerStatusCollector.java │ │ ├── service │ │ ├── ReportService.java │ │ └── impl │ │ │ ├── BaseService.java │ │ │ └── ReportServiceImpl.java │ │ └── web │ │ ├── AdminController.java │ │ ├── AlarmSettingsController.java │ │ ├── BaseController.java │ │ ├── DefaultController.java │ │ ├── HostPerformanceController.java │ │ ├── ReportController.java │ │ ├── ZooKeeperController.java │ │ └── ZooKeeperStatusController.java │ ├── resources │ └── log4j.properties │ └── webapp │ ├── 404.jsp │ ├── 500.jsp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ ├── common │ │ ├── footer.jsp │ │ ├── header.jsp │ │ └── taglibs.jsp │ ├── decorators.xml │ ├── decorators │ │ └── default.jsp │ ├── jsp │ │ ├── admin │ │ │ ├── setSystemConfigPAGE.jsp │ │ │ └── switchOfNeedAlarmPAGE.jsp │ │ ├── index.jsp │ │ ├── monitor │ │ │ ├── alarmSettingsPAGE.jsp │ │ │ ├── showHostPerformancePAGE.jsp │ │ │ ├── zooKeeperRegisterPAGE.jsp │ │ │ ├── zooKeeperSettingsPAGE.jsp │ │ │ └── zooKeeperStatusPAGE.jsp │ │ └── report │ │ │ └── report.jsp │ ├── sitemesh.xml │ ├── spring-beans.xml │ ├── spring-common.xml │ └── web.xml │ ├── css │ ├── default.css │ ├── displaytag.css │ ├── popDiv.css │ ├── smoothness │ │ ├── images │ │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ │ ├── ui-bg_flat_75_ffffff_40x100.png │ │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ │ ├── ui-bg_highlight-soft_75_cccccc_1x100.png │ │ │ ├── ui-icons_222222_256x240.png │ │ │ ├── ui-icons_2e83ff_256x240.png │ │ │ ├── ui-icons_454545_256x240.png │ │ │ ├── ui-icons_888888_256x240.png │ │ │ └── ui-icons_cd0a0a_256x240.png │ │ └── jquery-ui-1.8.5.custom.css │ └── table.css │ ├── favicon.ico │ ├── images │ ├── addOps.png │ ├── addPermission.png │ ├── authorise_process.png │ ├── breadcrumbs.png │ ├── list.png │ ├── menu-list.gif │ ├── menu-title.gif │ └── users.png │ ├── img │ ├── arrow_down.png │ ├── arrow_off.png │ ├── arrow_up.png │ ├── bg.gif │ ├── calendar │ │ ├── calendar.jpg │ │ ├── next.gif │ │ └── prev.gif │ ├── displaytag.png │ ├── error.gif │ ├── external.png │ ├── favicon.ico │ ├── help.gif │ ├── hi.gif │ ├── ico_file_csv.png │ ├── ico_file_excel.png │ ├── ico_file_pdf.png │ ├── ico_file_rtf.png │ ├── ico_file_xml.png │ ├── lock.png │ ├── login_btn.png │ ├── logo.png │ ├── ops-list.png │ ├── ops-security.png │ ├── paginazione.png │ ├── paginazione_ahead.png │ ├── paginazione_back.png │ ├── psd │ │ └── taokeeper-logo.psd │ ├── report │ │ ├── dragIcon.gif │ │ ├── dragIconH.gif │ │ └── lens.png │ ├── ribbon.png │ ├── seeDetail.png │ ├── taokeeper-logo.png │ ├── text_field.png │ ├── valid-xhtml10.png │ └── viewsource.png │ ├── index.jsp │ ├── js │ ├── calendarDateInput.js │ ├── jquery-1.4.2.min.js │ ├── jquery-ui-1.8.5.custom.min.js │ ├── popDiv.js │ ├── report │ │ ├── amcharts.js │ │ └── raphael.js │ └── table.js │ └── ruok.htm ├── taokeeper-reporter ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── taobao │ └── taokeeper │ └── reporter │ └── alarm │ ├── MessageSender.java │ └── TbMessageSender.java └── taokeeper-research ├── eclipse.cmd ├── pom.xml └── src └── main ├── java └── com │ └── taobao │ ├── taokeeper │ └── research │ │ ├── NodeSizeLimit.java │ │ ├── sample │ │ ├── JavaApiSample.java │ │ └── SessionTimeoutSample.java │ │ ├── test │ │ └── performance │ │ │ ├── onlygetdata │ │ │ ├── PressDataGet.java │ │ │ └── Subscriber.java │ │ │ ├── onlysetdata │ │ │ ├── PressDataSet.java │ │ │ └── Publisher.java │ │ │ ├── session │ │ │ ├── SessionCreator.java │ │ │ └── SessionPressTest.java │ │ │ └── setdataandwatcher │ │ │ ├── PressDataSetAndWatcher.java │ │ │ └── WatchedPublisher.java │ │ └── watcher │ │ ├── AllZooKeeperWatcher.java │ │ ├── AuthFailedEvent.java │ │ ├── NodeChildrenChangedEvent.java │ │ ├── NodeDataChangedEvent.java │ │ └── PushOrPullTest.java │ └── zookeeper │ └── presstest │ ├── createnode │ ├── SequenceNodeCreator.java │ └── SequenceNodeTest.java │ └── watcher │ ├── PressWatcher.java │ ├── Publisher.java │ └── Subscriber.java └── resources └── log4j.properties /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore files 2 | .project 3 | .settings/ 4 | taokeeper-monitor/target/ 5 | taokeeper-common/.classpath 6 | taokeeper-common/target/ 7 | taokeeper-monitor/.classpath 8 | logs/ 9 | taokeeper-build/.classpath 10 | taokeeper-reporter/.classpath 11 | taokeeper-research/target/ 12 | taokeeper-research/.classpath -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | 如何正确地编译taokeeper: 2 | 1.下载这两个项目: 3 | git clone https://github.com/hengyunabc/common-toolkit.git 4 | git clone https://github.com/nileader/zkclient.git 5 | 6 | 先分别执行 mvn -Dmaven.test.skip install 7 | 2.下载本项目: 8 | git clone https://github.com/hengyunabc/taokeeper.git 9 | 10 | 执行 mvn -Dmaven.test.skip clean package 11 | 到taokeeper-monitor/target/目录就可以看到生成的War包了。 12 | 13 | 3.部署: 14 | 原项目的部署说明有问题。 15 | 要有mysql数据库,导入taokeeper-build/etc/taokeeper.sql 文件; 16 | 配置tomcat启动参数,增加JVM启动参数: 17 | JAVA_OPTS=-DconfigFilePath="~/taokeeper/taokeeper-monitor-config.properties" 18 | 并在上面的配置中配置好参数,例如: 19 | systemInfo.envName=TEST 20 | #DBCP 21 | dbcp.driverClassName=com.mysql.jdbc.Driver 22 | dbcp.dbJDBCUrl=jdbc:mysql://localhost:3306/taokeeper 23 | dbcp.characterEncoding=GBK 24 | dbcp.username=root 25 | dbcp.password=root 26 | dbcp.maxActive=30 27 | dbcp.maxIdle=10 28 | dbcp.maxWait=10000 29 | #SystemConstant 30 | SystemConstent.dataStoreBasePath=~/taokeeper/ 31 | #SSH account of zk server 32 | SystemConstant.userNameOfSSH=hello 33 | SystemConstant.passwordOfSSH=hello 34 | 35 | 其中SSH用户密码要配置对,zookeeper部署的机器要开放SSH服务。 36 | 把生成的War包改为ROOT.war,放到tomcat的webapps目录下,启动tomcat。 37 | 如果报log4j错误,则还要配置webapps/ROOT/WEB-INF/classes/log4j.properties 文件。 38 | 也可以在编绎前先修改好。 39 | 40 | 打开 http://localhost:8080/ ,就可以看到taokeeper的界面了。 41 | 42 | 4.注意 43 | 在chrome浏览器下,“机器监控”这个功能有时会把信息显示下浏览器的下面,要拉到最后才能看到,并不是这个功能不能工作。 44 | 45 | 46 | ================下面的配置已过时,可以参考======================== 47 | 48 | 49 | Notice:The file is encoded by UTF-8 50 | 51 | HomePage: http://jm.taobao.org/2012/01/12/zookeeper%E7%9B%91%E6%8E%A7/ 52 | CopyRight by Taobao.com 53 | Any question to: nileader@qq.com 54 | 55 | 56 | 1. Use To manage projects dependence using maven 57 | 2. Database Initialization: taokeeper-build/sql/taokeeper.sql 58 | 3. Implements com.taobao.taokeeper.reporter.alarm.MessageSender to send message. 59 | 4. Exec taokeeper-build/build.cmd to generate taokeeper-monitor.war 60 | 61 | 62 | How to deploy(See more,please to http://jm.taobao.org/2012/01/12/zookeeper%E7%9B%91%E6%8E%A7/ ) 63 | 64 | 1. Download taokeeper.sql( http://pan.baidu.com/share/link?shareid=515952&uk=2064399439 ),init mysql. 65 | 66 | 2. Download taokeeper-monitor.tar.gz ( http://pan.baidu.com/share/link?shareid=515943&uk=2064399439 ), 67 | tar -zxvf taokeeper-monitor.tar.gz to webapps of tomcat, 68 | make sure the path is %TOMCAT_HOME%\webapps\taokeeper-monitor\WEB-INF 69 | 70 | 3. Download taokeeper-monitor-config.properties http://pan.baidu.com/share/link?shareid=515942&uk=2064399439 ), 71 | store it such as /home/admin/taokeeper-monitor/config/taokeeper-monitor-config.properties 72 | 73 | ---------------------------------------------------------------- 74 | systemInfo.envName=TEST 75 | #DBCP 76 | dbcp.driverClassName=com.mysql.jdbc.Driver 77 | dbcp.dbJDBCUrl=jdbc:mysql://1.1.1.1:3306/taokeeper 78 | dbcp.characterEncoding=GBK 79 | dbcp.username=xiaoming 80 | dbcp.password=123456 81 | dbcp.maxActive=30 82 | dbcp.maxIdle=10 83 | dbcp.maxWait=10000 84 | #SystemConstant 85 | SystemConstent.dataStoreBasePath=/home/xiaoming/taokeeper-monitor/ZookeeperStore 86 | #SSH account of zk server 87 | SystemConstant.userNameOfSSH=xiaoming 88 | SystemConstant.passwordOfSSH=123456 89 | ------------------------------------------------------------------ 90 | 91 | 4. Add JAVA_OPTS to tomcat catalina.bat or catalina.sh: 92 | windows:set JAVA_OPTS=-DconfigFilePath="D:\server\tomcat-6.0.33\webapps\taokeeper-monitor-config.properties" 93 | linux:JAVA_OPTS=-DconfigFilePath="/home/admin/taokeeper-monitor/config/taokeeper-monitor-config.properties" 94 | 95 | 5. Startup tomcat 96 | 97 | 6. Visit the page: http://127.0.0.1:8080/taokeeper-monitor 98 | 99 | 100 | 101 | 102 | 103 | Alibaba OpenSource Maven Repository 104 | 105 | 106 | opensource 107 | 108 | 109 | taocodeReleases 110 | taocode nexus 111 | http://mvnrepo.code.taobao.org/nexus/content/repositories/releases/ 112 | 113 | 114 | taocodeSnapshots 115 | taocode nexus 116 | http://mvnrepo.code.taobao.org/nexus/content/repositories/snapshots/ 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /taokeeper-build/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /taokeeper-build/build.cmd: -------------------------------------------------------------------------------- 1 | mvn clean package -U -f ../pom.xml -Dmaven.test.skip -e -------------------------------------------------------------------------------- /taokeeper-build/etc/config-daily-etao.properties: -------------------------------------------------------------------------------- 1 | #Daily 2 | 3 | systemInfo.envName=DAILY-ETAO 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-daily-tbdw.properties: -------------------------------------------------------------------------------- 1 | #Daily-TBDW 2 | 3 | systemInfo.envName=DAILY-TBDW 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-daily.properties: -------------------------------------------------------------------------------- 1 | #Daily-TB 2 | 3 | systemInfo.envName=DAILY-TB 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-online-etao.properties: -------------------------------------------------------------------------------- 1 | #ONLINE-ETAO 2 | 3 | systemInfo.envName=ONLINE-ETAO 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-online.properties: -------------------------------------------------------------------------------- 1 | #ONLINE-TB 2 | 3 | systemInfo.envName=ONLINE-TB 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-qdcm5.properties: -------------------------------------------------------------------------------- 1 | #ONLINE-TB-QD 2 | 3 | systemInfo.envName=ONLINE-TB-QD 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-tencent.properties: -------------------------------------------------------------------------------- 1 | #DAILY-TENCENT 2 | 3 | systemInfo.envName=DAILY-TENCENT 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/config-test.properties: -------------------------------------------------------------------------------- 1 | #TEST 2 | 3 | systemInfo.envName=TEST 4 | 5 | #DBCP 6 | dbcp.driverClassName=com.mysql.jdbc.Driver 7 | dbcp.dbJDBCUrl=jdbc:mysql://:3306/taokeeper 8 | dbcp.characterEncoding=GBK 9 | dbcp.username= 10 | dbcp.password= 11 | dbcp.maxActive=30 12 | dbcp.maxIdle=10 13 | dbcp.maxWait=10000 14 | 15 | #SystemConstant 16 | SystemConstent.dataStoreBasePath=/home/admin/taokeeper-monitor/datastore/ 17 | SystemConstant.userNameOfSSH= 18 | SystemConstant.passwordOfSSH= 19 | #Optional 20 | SystemConstant.configOfMsgCenter= -------------------------------------------------------------------------------- /taokeeper-build/etc/taokeeper.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE taokeeper; 2 | USE taokeeper; 3 | 4 | -- ---------------------------- 5 | -- Table: alarm_settings 6 | -- ---------------------------- 7 | DROP TABLE IF EXISTS `alarm_settings`; 8 | CREATE TABLE `alarm_settings` ( 9 | `alarm_settings_id` int(11) NOT NULL AUTO_INCREMENT, 10 | `cluster_id` int(11) NOT NULL, 11 | `wangwang_list` varchar(255) DEFAULT NULL, 12 | `phone_list` varchar(255) DEFAULT NULL, 13 | `email_list` varchar(255) DEFAULT NULL, 14 | `max_delay_of_check` varchar(255) DEFAULT NULL, 15 | `max_cpu_usage` varchar(255) DEFAULT NULL, 16 | `max_memory_usage` varchar(255) DEFAULT NULL, 17 | `max_load` varchar(255) DEFAULT NULL, 18 | `max_connection_per_ip` varchar(255) DEFAULT NULL, 19 | `max_watch_per_ip` varchar(255) DEFAULT NULL, 20 | `data_dir` varchar(255) DEFAULT NULL, 21 | `data_log_dir` varchar(255) DEFAULT NULL, 22 | `max_disk_usage` varchar(255) DEFAULT NULL, 23 | `node_path_check_rule` text, 24 | PRIMARY KEY (`alarm_settings_id`), 25 | UNIQUE KEY `uk_alarm_settings_cid` (`cluster_id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=gbk; 27 | 28 | -- ---------------------------- 29 | -- Table taokeeper_settings 30 | -- ---------------------------- 31 | DROP TABLE IF EXISTS `taokeeper_settings`; 32 | CREATE TABLE `taokeeper_settings` ( 33 | `settings_id` int(11) NOT NULL AUTO_INCREMENT, 34 | `env_name` varchar(20) DEFAULT NULL, 35 | `max_threads_of_zookeeper_check` int(5) DEFAULT NULL, 36 | `description` varchar(10) DEFAULT NULL, 37 | PRIMARY KEY (`settings_id`), 38 | UNIQUE KEY `uk_alarm_settings_cid` (`env_name`) 39 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk; 40 | 41 | -- ---------------------------- 42 | -- Records of taokeeper_settings 43 | -- ---------------------------- 44 | INSERT INTO `taokeeper_settings` VALUES ('1', 'My TaoKeeper', '5', '我的TaoKeeper'); 45 | 46 | 47 | -- ---------------------------- 48 | -- Table: taokeeper_stat 49 | -- ---------------------------- 50 | DROP TABLE IF EXISTS `taokeeper_stat`; 51 | CREATE TABLE `taokeeper_stat` ( 52 | `cluster_id` int(11) NOT NULL, 53 | `server` varchar(30) NOT NULL COMMENT '127.0.0.1:2181', 54 | `stat_date_time` datetime NOT NULL COMMENT '统计时间 2012-01-05 14:56:20', 55 | `stat_date` date NOT NULL, 56 | `connections` int(11) DEFAULT NULL, 57 | `watches` int(11) DEFAULT NULL COMMENT '订阅者数目', 58 | `send_times` bigint(20) unsigned DEFAULT 0, 59 | `receive_times` bigint(20) unsigned DEFAULT 0, 60 | `node_count` int(11) DEFAULT 0, 61 | PRIMARY KEY (`cluster_id`,`server`,`stat_date_time`) 62 | ) ENGINE=InnoDB DEFAULT CHARSET=gbk; 63 | 64 | 65 | -- ---------------------------- 66 | -- Table: zookeeper_cluster 67 | -- ---------------------------- 68 | DROP TABLE IF EXISTS `zookeeper_cluster`; 69 | CREATE TABLE `zookeeper_cluster` ( 70 | `cluster_id` int(11) NOT NULL auto_increment, 71 | `cluster_name` varchar(255) NOT NULL, 72 | `server_list` varchar(255) NOT NULL, 73 | `description` varchar(255) default NULL, 74 | PRIMARY KEY (`cluster_id`) 75 | ) ENGINE=InnoDB DEFAULT CHARSET=gbk; -------------------------------------------------------------------------------- /taokeeper-build/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.taobao.taokeeper 7 | taokeeper 8 | 1.1.2 9 | 10 | 11 | taokeeper-build 12 | taokeeper-build 13 | jar 14 | 15 | 16 | -------------------------------------------------------------------------------- /taokeeper-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.taobao.taokeeper 8 | taokeeper 9 | 1.1.2 10 | 11 | 12 | taokeeper-common 13 | taokeeper-common 14 | jar 15 | 16 | 17 | 18 | 19 | 20 | org.apache.zookeeper 21 | zookeeper 22 | 23 | 24 | org.apache.zookeeper 25 | zookeeper 26 | sources 27 | 28 | 29 | 30 | com.taobao.taokeeper 31 | zkclient 32 | 33 | 34 | 35 | common.toolkit 36 | common-toolkit 37 | 38 | 39 | 40 | common.toolkit 41 | common-toolkit 42 | sources 43 | 44 | 45 | 46 | 47 | mysql 48 | mysql-connector-java 49 | 50 | 51 | 52 | commons-lang 53 | commons-lang 54 | 55 | 56 | 57 | commons-dbcp 58 | commons-dbcp 59 | 60 | 61 | commons-codec 62 | commons-codec 63 | 1.7 64 | 65 | 66 | 67 | 68 | 69 | junit 70 | junit 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/common/SystemInfo.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.common; 2 | 3 | /** 4 | * Description: 系统环境 5 | * 6 | * @author yinshi.nc 7 | * @Date 2011-10-31 8 | */ 9 | public class SystemInfo { 10 | 11 | public static String systemHost; 12 | public static String systemJavaRuntimeInfo; 13 | public static String envName; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/common/constant/SystemConstant.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.common.constant; 2 | 3 | 4 | import common.toolkit.java.constant.SymbolConstant; 5 | import common.toolkit.java.util.StringUtil; 6 | 7 | /** 8 | * Description: System constant,有些变量在Spring初始化的时候会注入。 9 | * 10 | * @author yinshi.nc 11 | * @Date 2011-10-26 12 | */ 13 | public class SystemConstant { 14 | 15 | public final static String ZOOKEEPER_MONITOR_PATH = "/YINSHI.MONITOR.ALIVE.CHECK"; 16 | 17 | public final static String AUTHENTICATION_TYPE = "digest"; 18 | 19 | public final static String AUTHENTICATION_KEY = "yinshi.nc:taobao"; 20 | 21 | /** delay of check zookeeper watcher notify */ 22 | public final static int DELAY_SECS_OF_TWO_SERVER_ALIVE_CHECK_ZOOKEEPER = 5; // 两个ip检测的间隔 23 | // s 24 | public final static int DELAY_MINS_OF_TWO_CYCLE_ALIVE_CHECK_ZOOKEEPER = 1; // 两次存活性检查间隔 25 | // mins 26 | public final static int MINS_RATE_OF_CHECK_ZOOKEEPER = 1; 27 | 28 | public final static int MINS_RATE_OF_COLLECT_ZOOKEEPER = 1; 29 | public final static int MINS_RATE_OF_COLLECT_HOST_PERFORMANCE = 2; 30 | public final static int MINS_RATE_OF_DUMP_ZOOKEEPER_CLUSTER = 1; 31 | 32 | public final static int HOURS_RATE_OF_ZOOKEEPER_NODE_CHECK = 1; 33 | 34 | public final static String COMMAND_CONS = "echo cons | nc {0} {1}"; 35 | public final static String COMMAND_STAT = "echo stat | nc {0} {1}"; 36 | public final static String COMMAND_WCHS = "echo wchs | nc {0} {1}"; 37 | public final static String COMMAND_WCHC = "echo wchc | nc {0} {1}"; 38 | 39 | public static String userNameOfSSH = "nobody"; 40 | public static String passwordOfSSH = "look"; 41 | 42 | public static int portOfSSH = 22; 43 | 44 | /** ZooKeeper监控信息存储设置客户端统计信息文件存放目录 */ 45 | public static String dataStoreBasePath = "/home/yinshi.nc/zookeeper-monitor"; 46 | 47 | public static String dataStoreCategoryPath_clientStat = "/ZooKeeperClientThroughputStat/"; 48 | public static String PREFIX_OF_ZOOKEEPER_CLIENT_STAT_FILE_NAME = "zookeeper-client-"; 49 | 50 | public static String URL_TEMPLEMENT_OF_MESSAG_SEND = "http://${ip}/mchttpapi/module/api/${messageType}.htm?nickname=${targetAddress}&title=${subject}&message=${content}"; 51 | public static String IP_OF_MESSAGE_SEND = ""; 52 | 53 | 54 | 55 | public static String serverOfMsgCenter = ""; 56 | public static String sourceIdOfMsgCenter = ""; 57 | public static String templateIdOfMsgCenter = ""; 58 | public static String messageTypeIdOfMsgCenter = ""; 59 | 60 | public void setDataStoreBasePath( String dataStoreBasePath ) { 61 | SystemConstant.dataStoreBasePath = StringUtil.defaultIfBlank( dataStoreBasePath, SystemConstant.dataStoreBasePath ); 62 | } 63 | 64 | 65 | public static void parseConfigOfMsgCenter( String configOfMsgCenter ) { 66 | try { 67 | if ( StringUtil.isBlank( configOfMsgCenter ) ) 68 | throw new Exception( "configOfMsgCenter can't be null" ); 69 | 70 | String[] configOfMsgCenterArray = configOfMsgCenter.split( SymbolConstant.SLASH ); 71 | if ( 4 != configOfMsgCenterArray.length ) 72 | throw new Exception( "Illegal configOfMsgCenter formart" ); 73 | 74 | SystemConstant.serverOfMsgCenter = StringUtil.defaultIfBlank( configOfMsgCenterArray[0], SystemConstant.serverOfMsgCenter ); 75 | SystemConstant.sourceIdOfMsgCenter = StringUtil.defaultIfBlank( configOfMsgCenterArray[1], SystemConstant.sourceIdOfMsgCenter ); 76 | SystemConstant.templateIdOfMsgCenter = StringUtil.defaultIfBlank( configOfMsgCenterArray[2], SystemConstant.templateIdOfMsgCenter ); 77 | SystemConstant.messageTypeIdOfMsgCenter = StringUtil.defaultIfBlank( configOfMsgCenterArray[3], SystemConstant.messageTypeIdOfMsgCenter ); 78 | } catch ( Exception e ) { 79 | throw new RuntimeException( "Parse configOfMsgCenter( " + configOfMsgCenter 80 | + " ) error, please config like this:1.2.3.4:9999,1.2.3.5:9999/a*b/3545656/67657" + e.getMessage(), e ); 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/common/type/NodePathCheckRule.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.common.type; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | * ZooKeeper Node的path检查规则 8 | * @author nileader/nileader@gmail.com 9 | * @date 2012-10-22 10 | */ 11 | public class NodePathCheckRule { 12 | 13 | /** 只能够出现这些path */ 14 | private Map> pathOnlyCanBeExist; 15 | /** 不能出现这些path */ 16 | private Map> pathCanNotBeExist; 17 | 18 | 19 | public Map> getPathOnlyCanBeExist() { 20 | return pathOnlyCanBeExist; 21 | } 22 | public void setPathOnlyCanBeExist( Map> pathOnlyCanBeExist ) { 23 | this.pathOnlyCanBeExist = pathOnlyCanBeExist; 24 | } 25 | public Map> getPathCanNotBeExist() { 26 | return pathCanNotBeExist; 27 | } 28 | public void setPathCanNotBeExist( Map> pathCanNotBeExist ) { 29 | this.pathCanNotBeExist = pathCanNotBeExist; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Node的path检查规则[只能出现的节点:" + this.pathOnlyCanBeExist + 35 | "不能出现的节点:" + this.pathCanNotBeExist + "]"; 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/common/util/AlarmSettingUtil.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.common.util; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.taobao.taokeeper.common.type.NodePathCheckRule; 8 | 9 | import common.toolkit.java.util.StringUtil; 10 | import common.toolkit.java.util.collection.ListUtil; 11 | 12 | /** 13 | * 14 | * @author nileader/nileader@gmail.com 15 | * @date 2012-10-22 16 | */ 17 | public class AlarmSettingUtil { 18 | 19 | /** 20 | * 将字符串解析成NodePathCheckRule 21 | * @param str 类似于的 [/:nileader,yinshi;/nileader:test]^{/:nileader,yinshi;/nileader:test} 22 | * @return 可能会返回null 23 | * @throws Exception 24 | */ 25 | public static NodePathCheckRule parseNodePathCheckRuleFromString( String str ) throws Exception{ 26 | if( StringUtil.isBlank( str ) ){ 27 | return null; 28 | } 29 | 30 | String[] temp = str.split( "\\^" ); 31 | if( 0 == temp.length ){ 32 | //不合法的配置 33 | return null; 34 | } 35 | 36 | try { 37 | //可能是一个:/:nileader,yinshi;/nileader:test 38 | String strPathOnlyCanBeExist = StringUtil.replaceAll( temp[0], "", "\\|" ); 39 | //可能是一个:/:nileader,yinshi;/nileader:test 40 | String strPathCanNotBeExist = StringUtil.replaceAll( temp[1], "", "\\|" ); 41 | 42 | /** 只能够出现这些path */ 43 | Map> pathOnlyCanBeExist = new HashMap>(); 44 | /** 不能出现这些path */ 45 | Map> pathCanNotBeExist = new HashMap>(); 46 | 47 | if( !StringUtil.isBlank( strPathOnlyCanBeExist ) ){ 48 | String[] ruleArray = strPathOnlyCanBeExist.split( ";" ); 49 | for( String rule : ruleArray ){ 50 | if( StringUtil.isBlank( rule ) ){ 51 | continue; 52 | } 53 | String[] pathArray = StringUtil.trimToEmpty( rule ).split( ":" ); 54 | String nodeName = StringUtil.trimToEmpty( pathArray[0] ); 55 | List pathList = ListUtil.parseList( pathArray[1] ); 56 | pathOnlyCanBeExist.put( nodeName, pathList ); 57 | } 58 | } 59 | 60 | if( !StringUtil.isBlank( strPathCanNotBeExist ) ){ 61 | String[] ruleArray = strPathCanNotBeExist.split( ";" ); 62 | for( String rule : ruleArray ){ 63 | if( StringUtil.isBlank( rule ) ){ 64 | continue; 65 | } 66 | String[] pathArray = StringUtil.trimToEmpty( rule ).split( ":" ); 67 | String nodeName = pathArray[0]; 68 | List pathList = ListUtil.parseList( pathArray[1] ); 69 | pathCanNotBeExist.put( nodeName, pathList ); 70 | } 71 | } 72 | 73 | NodePathCheckRule nodePathCheckRule = new NodePathCheckRule(); 74 | nodePathCheckRule.setPathCanNotBeExist( pathCanNotBeExist ); 75 | nodePathCheckRule.setPathOnlyCanBeExist( pathOnlyCanBeExist ); 76 | 77 | return nodePathCheckRule; 78 | } catch ( Exception e ) { 79 | throw new Exception( "Error when parseNodePathCheckRuleFromString, String: " + str + ", Error: " + e.getMessage(), e ); 80 | } 81 | 82 | 83 | 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/dao/AlarmSettingsDAO.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.dao; 2 | 3 | import com.taobao.taokeeper.model.AlarmSettings; 4 | import common.toolkit.java.exception.DaoException; 5 | 6 | /** 7 | * Description: Access DB for alarm settings 8 | * @author yinshi.nc 9 | * @Date 2011-10-31 10 | */ 11 | public interface AlarmSettingsDAO { 12 | 13 | public AlarmSettings getAlarmSettingsByCulsterId( int clusterId )throws DaoException; 14 | 15 | public boolean updateAlarmSettingsByClusterId( AlarmSettings alarmSettings ) throws DaoException; 16 | 17 | /** 添加一个报警设置 */ 18 | public boolean addAlarmSettings( AlarmSettings alarmSettings ) throws DaoException; 19 | } 20 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/dao/ReportDAO.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.dao; 2 | import java.util.List; 3 | import java.util.Map; 4 | 5 | import com.taobao.taokeeper.model.TaoKeeperStat; 6 | import common.toolkit.java.exception.DaoException; 7 | 8 | /** 9 | * Description: Access DB for taokeeper_stat 10 | * @author yinshi.nc 11 | * @since 2012-01-05 12 | */ 13 | public interface ReportDAO { 14 | 15 | /** 16 | * 添加一条统计信息 17 | * @param taoKeeperStat 18 | * @throws DaoException 19 | */ 20 | public void addTaoKeeperStat( TaoKeeperStat taoKeeperStat ) throws DaoException; 21 | 22 | 23 | /** 24 | * 根据cluster_id, server, stat_date 来查询一个统计信息 25 | * @param clusterId 26 | * @param server ip 27 | * @param statDate 2012-01-05 28 | * @throws DaoException 29 | */ 30 | public List queryTaoKeeperStatByClusterIdAndServerAndStatDate( int clusterId, String server, String statDate ) throws DaoException; 31 | 32 | 33 | /** 34 | * 根据cluster_id, stat_date 来查询一个集群的统计信息 35 | * @param clusterId 36 | * @param statDate 2012-01-05 37 | * @throws DaoException 38 | */ 39 | public Map > queryStatByClusterIdAndStatDate( int clusterId, String statDate ) throws DaoException; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/dao/SettingsDAO.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.dao; 2 | 3 | import com.taobao.taokeeper.model.TaoKeeperSettings; 4 | import common.toolkit.java.exception.DaoException; 5 | 6 | /** 7 | * Description: Access DB for taokeeper settings 8 | * @author yinshi.nc 9 | * @Date 2011-11-13 10 | */ 11 | public interface SettingsDAO { 12 | 13 | /** 添加taokeeper配置信息 */ 14 | public boolean addTaoKeeperSettings( TaoKeeperSettings taoKeeperSettings )throws DaoException; 15 | /** 获取指定 settingsId的 taokeeper配置信息 */ 16 | public TaoKeeperSettings getTaoKeeperSettingsBySettingsId( int settingsId )throws DaoException; 17 | /** 更新taokeeper信息 */ 18 | public boolean updateTaoKeeperSettingsBySettingsId( TaoKeeperSettings taoKeeperSettings ) throws DaoException; 19 | } 20 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/dao/ZooKeeperClusterDAO.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.dao; 2 | import java.util.List; 3 | 4 | import com.taobao.taokeeper.model.ZooKeeperCluster; 5 | import common.toolkit.java.exception.DaoException; 6 | 7 | /** 8 | * Description: Access DB for zookeeper cluster 9 | * @author yinshi.nc 10 | * @version 11 | * @since 12 | * @Date 2011-10-28 13 | */ 14 | public interface ZooKeeperClusterDAO { 15 | 16 | public ZooKeeperCluster getZooKeeperClusterByCulsterId( int clusterId )throws DaoException; 17 | 18 | public List getAllDetailZooKeeperCluster( )throws DaoException; 19 | 20 | /** 获取所有clusterid name*/ 21 | public List getAllZooKeeperClusterIdAndName( )throws DaoException; 22 | 23 | 24 | public boolean updateZooKeeperSettingsByClusterId( ZooKeeperCluster zooKeeperCluster ) throws DaoException; 25 | 26 | /*** 27 | * 添加一个zookeeper集群 28 | */ 29 | public int addZooKeeper( ZooKeeperCluster zooKeeperCluster ) throws DaoException; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/dao/impl/SettingsDAOImpl.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.dao.impl; 2 | import static com.taobao.taokeeper.common.constant.SqlTemplate.SQL_INSERT_TAOKEEPER_SETTINGS_BY_ID; 3 | import static com.taobao.taokeeper.common.constant.SqlTemplate.SQL_QUERY_TAOKEEPER_SETTINGS_BY_ID; 4 | import static com.taobao.taokeeper.common.constant.SqlTemplate.SQL_UPDATE_TAOKEEPER_SETTINGS_BY_ID; 5 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 6 | 7 | import java.sql.ResultSet; 8 | 9 | import com.taobao.taokeeper.dao.SettingsDAO; 10 | import com.taobao.taokeeper.model.TaoKeeperSettings; 11 | import common.toolkit.java.entity.db.DBConnectionResource; 12 | import common.toolkit.java.exception.DaoException; 13 | import common.toolkit.java.util.StringUtil; 14 | import common.toolkit.java.util.db.DbcpUtil; 15 | /** 16 | * Description: Access DB for taokeeper settings 17 | * @author yinshi.nc 18 | * @Date 2011-10-28 19 | */ 20 | public class SettingsDAOImpl implements SettingsDAO{ 21 | 22 | public TaoKeeperSettings getTaoKeeperSettingsBySettingsId( int settingsId )throws DaoException{ 23 | 24 | TaoKeeperSettings taoKeeperSettings = null; 25 | ResultSet rs = null; 26 | DBConnectionResource dbConnectionResource = null; 27 | try { 28 | String querySQL = StringUtil.replaceSequenced( SQL_QUERY_TAOKEEPER_SETTINGS_BY_ID, settingsId + EMPTY_STRING ); 29 | dbConnectionResource = DbcpUtil.executeQuery( querySQL ); 30 | if( null == dbConnectionResource ) 31 | throw new DaoException( "没有返回结果" ); 32 | rs = dbConnectionResource.resultSet; 33 | if( null != rs && rs.next() ){ 34 | 35 | String envName = rs.getString( "env_name" ); 36 | int maxThreadsOfZooKeeperCheck = rs.getInt( "max_threads_of_zookeeper_check" ); 37 | String description = rs.getString( "description" ); 38 | 39 | taoKeeperSettings = new TaoKeeperSettings(); 40 | taoKeeperSettings.setSettingsId( settingsId ); 41 | taoKeeperSettings.setEnvName( envName ); 42 | taoKeeperSettings.setMaxThreadsOfZooKeeperCheck( maxThreadsOfZooKeeperCheck ); 43 | taoKeeperSettings.setDescription( description ); 44 | } 45 | return taoKeeperSettings; 46 | } catch ( Exception e ) { 47 | throw new DaoException( "Error when query TaoKeeperSettings by settings_id: " + settingsId + ", Error: " + e.getMessage(), e ); 48 | }finally{ 49 | if( null != dbConnectionResource ){ 50 | DbcpUtil.closeResultSetAndStatement( rs, dbConnectionResource.statement ); 51 | DbcpUtil.returnBackConnectionToPool( dbConnectionResource.connection ); 52 | } 53 | } 54 | } 55 | 56 | @Override 57 | public boolean updateTaoKeeperSettingsBySettingsId( TaoKeeperSettings taoKeeperSettings ) throws DaoException { 58 | 59 | if( null == taoKeeperSettings ) 60 | return false; 61 | 62 | //从数据库中获取指定settings_id配置 63 | try { 64 | String updateSql = StringUtil.replaceSequenced( SQL_UPDATE_TAOKEEPER_SETTINGS_BY_ID, taoKeeperSettings.getEnvName(), taoKeeperSettings.getMaxThreadsOfZooKeeperCheck() + EMPTY_STRING, taoKeeperSettings.getDescription(), taoKeeperSettings.getSettingsId() + EMPTY_STRING ); 65 | int num = DbcpUtil.executeUpdate( updateSql ); 66 | if( 1 == num ){ 67 | return true; 68 | } 69 | throw new DaoException( "Not exist such record" ); 70 | } catch ( Exception e ) { 71 | throw new DaoException( "Error when update taoKeeperSettings by settingsId: " + taoKeeperSettings + ", Error: " + e.getMessage(), e ); 72 | } 73 | } 74 | 75 | @Override 76 | public boolean addTaoKeeperSettings( TaoKeeperSettings taoKeeperSettings ) throws DaoException { 77 | 78 | if( null == taoKeeperSettings ) 79 | return false; 80 | 81 | try { 82 | String insertSql = StringUtil.replaceSequenced( SQL_INSERT_TAOKEEPER_SETTINGS_BY_ID, taoKeeperSettings.getEnvName(), taoKeeperSettings.getMaxThreadsOfZooKeeperCheck() + EMPTY_STRING, taoKeeperSettings.getDescription() ); 83 | int num = DbcpUtil.executeInsert( insertSql ); 84 | if( 1 == num ){ 85 | return true; 86 | } 87 | throw new DaoException( "Not exist such record" ); 88 | } catch ( Exception e ) { 89 | throw new DaoException( "Error when insert taoKeeperSettings: " + taoKeeperSettings + ", Error: " + e.getMessage(), e ); 90 | } 91 | 92 | 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/Subscriber.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model; 2 | import static com.taobao.taokeeper.common.constant.SystemConstant.DELAY_SECS_OF_TWO_SERVER_ALIVE_CHECK_ZOOKEEPER; 3 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.I0Itec.zkclient.IZkDataListener; 9 | import org.I0Itec.zkclient.ZkClient; 10 | import org.apache.zookeeper.CreateMode; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | /** 14 | * ��˵��: 15 | * @author yinshi.nc 16 | */ 17 | public class Subscriber{ 18 | 19 | private static Logger log = LoggerFactory.getLogger( Subscriber.class ); 20 | 21 | private int okTimes = 0; 22 | private String serverList; 23 | private String path; 24 | private ZkClient zkClient = null; 25 | private int maxDelaySecsForNotify = 1; 26 | //�������������ֱ������һ����server�ύ�ĸ�����ݺ�����õ�����ݣ�����ֵһ��˵����� 27 | private String lastedUpdateToServer = EMPTY_STRING; 28 | public void setLastedUpdateToServer( String lastedUpdateToServer ) { 29 | this.lastedUpdateToServer = lastedUpdateToServer; 30 | } 31 | 32 | public Subscriber( String serverList, String path, int maxDelaySecsForNotify ){ 33 | this.serverList = serverList; 34 | this.path = path; 35 | zkClient = new ZkClient( serverList, 10000 ); 36 | log.info( "====zk conn log====>start conn to zk server: " + this.serverList ); 37 | this.maxDelaySecsForNotify = maxDelaySecsForNotify; 38 | //�������� 39 | this.mointorData( path ); 40 | 41 | } 42 | 43 | 44 | 45 | /** 46 | * ��� parentPath Ŀ¼��������ݵı�� 47 | * ע��, ����ļ���������, ֻ�ܼ����Լ�. 48 | * @param parentPath 49 | */ 50 | private void mointorData( String path) { 51 | zkClient.subscribeDataChanges( path, new IZkDataListener() { 52 | public void handleDataChange(String dataPath, Object data) throws Exception { 53 | if( lastedUpdateToServer.equalsIgnoreCase( data.toString() ) ){ 54 | okTimes++; 55 | return; 56 | } 57 | } 58 | public void handleDataDeleted(String dataPath) throws Exception { 59 | //ingore 60 | } 61 | }); 62 | } 63 | 64 | /** 65 | * ����Ƿ����鷽���ǣ���һ��ip������ݣ�Ҫ����ָ��ʱ�����յ�֪ͨ����ȡ��ȷ��ݡ��������������3�Σ�������һ��ʧ�ܼ�ʧ�ܡ� 66 | */ 67 | public boolean checkIfAlive(){ 68 | createNodeNotExist( this.path ); 69 | for( int i=0; i<3; i++ ){ 70 | this.lastedUpdateToServer = this.serverList + System.currentTimeMillis(); 71 | try { 72 | this.updateData( this.lastedUpdateToServer ); 73 | Thread.sleep( 1000 * this.maxDelaySecsForNotify );//ָ��ʱ���� 74 | } catch ( InterruptedException e ) { 75 | //ingore 76 | } catch ( Exception e ) { 77 | return false; 78 | } 79 | } 80 | 81 | return okTimes == 3; 82 | } 83 | 84 | public void close(){ 85 | this.zkClient.close(); 86 | this.zkClient = null; 87 | log.info( "====zk conn log====>start disconn to zk server: " + this.serverList ); 88 | } 89 | 90 | 91 | /** �����ڣ������ڵ� */ 92 | private void createNodeNotExist( String defaultData){ 93 | if( !zkClient.exists( this.path ) ){ 94 | zkClient.create( this.path, this.serverList + System.currentTimeMillis(), CreateMode.PERSISTENT ); 95 | } 96 | } 97 | 98 | /**�������*/ 99 | private void updateData( String newData )throws Exception{ 100 | zkClient.writeData( this.path, newData ); 101 | } 102 | 103 | 104 | 105 | public static void main( String[] args ) throws InterruptedException { 106 | 107 | List serverList = new ArrayList< String >(); 108 | serverList.add( "10.232.37.129:2181" ); 109 | serverList.add( "10.232.37.128:2181" ); 110 | serverList.add( "10.232.37.126:2181" ); 111 | serverList.add( "10.13.44.47:2181" ); 112 | 113 | while( true ){ 114 | for( String server : serverList ){ 115 | 116 | Subscriber sub = null; 117 | try { 118 | sub = new Subscriber( server, "/yinshi.test", 1 ); 119 | //�ж�һ���ڵ��Ѿ����ˣ��������μ���ʧ�ܡ� 120 | if( !sub.checkIfAlive() ){ 121 | if( !sub.checkIfAlive() ){ 122 | log.error( server + "����Լ��ʧ��" ); 123 | }else{ 124 | log.info( server + "����Լ��ͨ��" ); 125 | } 126 | }else{ 127 | log.info( server + "����Լ��ͨ��" ); 128 | } 129 | Thread.sleep( 1000 * DELAY_SECS_OF_TWO_SERVER_ALIVE_CHECK_ZOOKEEPER ); 130 | } catch ( Exception e ) { 131 | log.error( server + "����Լ��ʧ�ܣ�ԭ����" + e.getMessage() ); 132 | }finally{ 133 | if( null != sub ) 134 | sub.close(); 135 | } 136 | } 137 | Thread.sleep( 5000 ); 138 | } 139 | 140 | } 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | } 149 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/TaoKeeperSettings.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model; 2 | 3 | 4 | /** 5 | * Description: Model: TaoKeeper 系统设置 6 | * @author yinshi.nc 7 | * @Date 2011-11-13 8 | */ 9 | public class TaoKeeperSettings { 10 | 11 | 12 | private int settingsId; 13 | private String envName; 14 | private int maxThreadsOfZooKeeperCheck; 15 | private String description; 16 | 17 | public TaoKeeperSettings(){} 18 | public TaoKeeperSettings(int settingsId, // 19 | String envName, // 20 | int maxThreadsOfZooKeeperCheck, // 21 | String description ){ 22 | this.settingsId = settingsId; 23 | this.envName = envName; 24 | this.maxThreadsOfZooKeeperCheck = maxThreadsOfZooKeeperCheck; 25 | this.description = description; 26 | } 27 | 28 | 29 | public int getSettingsId() { 30 | return settingsId; 31 | } 32 | public void setSettingsId( int settingsId ) { 33 | this.settingsId = settingsId; 34 | } 35 | public String getEnvName() { 36 | return envName; 37 | } 38 | public void setEnvName( String envName ) { 39 | this.envName = envName; 40 | } 41 | public int getMaxThreadsOfZooKeeperCheck() { 42 | return maxThreadsOfZooKeeperCheck; 43 | } 44 | public void setMaxThreadsOfZooKeeperCheck( int maxThreadsOfZooKeeperCheck ) { 45 | this.maxThreadsOfZooKeeperCheck = maxThreadsOfZooKeeperCheck; 46 | } 47 | public String getDescription() { 48 | return description; 49 | } 50 | public void setDescription( String description ) { 51 | this.description = description; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "TaoKeeperSettings:[settingsId=" + settingsId+ ", envName=" + envName + 57 | ", maxThreadsOfZooKeeperCheck="+ maxThreadsOfZooKeeperCheck + ", description=" + 58 | description + ", description=" + description; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/TaoKeeperStat.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model; 2 | 3 | 4 | /** 5 | * Description: Model: TaoKeeper_Stat_DAO 6 | * @author yinshi.nc 7 | */ 8 | public class TaoKeeperStat { 9 | 10 | private int clusterId; 11 | private String server; 12 | private String statDateTime; 13 | private String statDate; 14 | private int connections; 15 | private int watches; 16 | private long sendTimes; 17 | private long receiveTimes; 18 | private long nodeCount; 19 | 20 | 21 | 22 | 23 | public TaoKeeperStat(){} 24 | public TaoKeeperStat(int clusterId, String server, String statDateTime, String statDate, int connections, int watches, long sendTimes, long receiveTimes, long nodeCount ){ 25 | this.clusterId = clusterId; 26 | this.server = server; 27 | this.statDateTime = statDateTime; 28 | this.statDate = statDate; 29 | this.connections = connections; 30 | this.watches = watches; 31 | this.sendTimes = sendTimes; 32 | this.receiveTimes = receiveTimes; 33 | this.nodeCount = nodeCount; 34 | } 35 | 36 | 37 | public int getClusterId() { 38 | return clusterId; 39 | } 40 | public void setClusterId( int clusterId ) { 41 | this.clusterId = clusterId; 42 | } 43 | public String getServer() { 44 | return server; 45 | } 46 | public void setServer( String server ) { 47 | this.server = server; 48 | } 49 | public String getStatDateTime() { 50 | return statDateTime; 51 | } 52 | public void setStatDateTime( String statDateTime ) { 53 | this.statDateTime = statDateTime; 54 | } 55 | public String getStatDate() { 56 | return statDate; 57 | } 58 | public void setStatDate( String statDate ) { 59 | this.statDate = statDate; 60 | } 61 | public int getWatches() { 62 | return watches; 63 | } 64 | public void setWatches( int watches ) { 65 | this.watches = watches; 66 | } 67 | public long getSendTimes() { 68 | return sendTimes; 69 | } 70 | public void setSendTimes( int sendTimes ) { 71 | this.sendTimes = sendTimes; 72 | } 73 | public long getReceiveTimes() { 74 | return receiveTimes; 75 | } 76 | public void setReceiveTimes( int receiveTimes ) { 77 | this.receiveTimes = receiveTimes; 78 | } 79 | public long getNodeCount() { 80 | return nodeCount; 81 | } 82 | public void setNodeCount( int nodeCount ) { 83 | this.nodeCount = nodeCount; 84 | } 85 | public int getConnections() { 86 | return connections; 87 | } 88 | public void setConnections( int connections ) { 89 | this.connections = connections; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/ZooKeeperCluster.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Description: Model: ZooKeeperCluster 7 | * 8 | * @author yinshi.nc 9 | * @Date 2011-10-26 10 | */ 11 | public class ZooKeeperCluster { 12 | 13 | public List< String > getServerList() { 14 | return serverList; 15 | } 16 | 17 | public void setServerList( List< String > serverList ) { 18 | this.serverList = serverList; 19 | } 20 | 21 | private int clusterId; 22 | private String clusterName; 23 | /** ip:prot */ 24 | private List< String > serverList; 25 | private String description; 26 | 27 | public int getClusterId() { 28 | return clusterId; 29 | } 30 | 31 | public void setClusterId( int clusterId ) { 32 | this.clusterId = clusterId; 33 | } 34 | 35 | public String getClusterName() { 36 | return clusterName; 37 | } 38 | 39 | public void setClusterName( String clusterName ) { 40 | this.clusterName = clusterName; 41 | } 42 | 43 | public String getDescription() { 44 | return description; 45 | } 46 | 47 | public void setDescription( String description ) { 48 | this.description = description; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "[clusterId: " + this.clusterId + ", clusterName: " + this.clusterName + ", serverList: " + this.serverList; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/ZooKeeperStatus.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model; 2 | import static common.toolkit.java.constant.HtmlTagConstant.BR; 3 | 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import common.toolkit.java.entity.io.Connection; 8 | import common.toolkit.java.util.StringUtil; 9 | 10 | /** 11 | * Description: Model: ZooKeeperStat 12 | * 13 | * @author yinshi.nc 14 | * @Date 2011-10-28 15 | */ 16 | public class ZooKeeperStatus { 17 | 18 | private String ip; 19 | private List< String > clientConnectionList; 20 | private Map< String,Connection > connections; 21 | @SuppressWarnings("unused") 22 | private String connectionsContent; 23 | /** watch nums */ 24 | private int watches; 25 | private int watchedPaths; 26 | private boolean isLeader; 27 | private String mode; 28 | private long nodeCount; 29 | private String statContent; 30 | /** 0:不确定 1:OK 2: ERROR*/ 31 | private int statusType = 0; 32 | 33 | private String sent; 34 | private String Received; 35 | 36 | private Map /** watched path list */ > watchedPathMap; 37 | private String watchedPathMapContent; 38 | 39 | 40 | public String getIp() { 41 | return ip; 42 | } 43 | 44 | public void setIp( String ip ) { 45 | this.ip = ip; 46 | } 47 | 48 | public boolean isLeader() { 49 | return isLeader; 50 | } 51 | 52 | public void setLeader( boolean isLeader ) { 53 | this.isLeader = isLeader; 54 | } 55 | 56 | public String getStatContent() { 57 | return statContent; 58 | } 59 | 60 | public void setStatContent( String statContent ) { 61 | this.statContent = statContent; 62 | } 63 | 64 | public List< String > getClientConnectionList() { 65 | return clientConnectionList; 66 | } 67 | 68 | public void setClientConnectionList( List< String > clientConnectionList ) { 69 | this.clientConnectionList = clientConnectionList; 70 | } 71 | 72 | public long getNodeCount() { 73 | return nodeCount; 74 | } 75 | 76 | public void setNodeCount( long nodeCount ) { 77 | this.nodeCount = nodeCount; 78 | } 79 | 80 | public String getMode() { 81 | return mode; 82 | } 83 | 84 | public void setMode( String mode ) { 85 | this.mode = mode; 86 | } 87 | 88 | public int getWatches() { 89 | return watches; 90 | } 91 | 92 | public void setWatches( int watches ) { 93 | this.watches = watches; 94 | } 95 | public Map< String,Connection > getConnections() { 96 | return connections; 97 | } 98 | 99 | public void setConnections( Map< String,Connection > connections ) { 100 | this.connections = connections; 101 | } 102 | 103 | public int getWatchedPaths() { 104 | return watchedPaths; 105 | } 106 | 107 | public void setWatchedPaths( int watchedPaths ) { 108 | this.watchedPaths = watchedPaths; 109 | } 110 | 111 | public int getStatusType() { 112 | return statusType; 113 | } 114 | 115 | public void setStatusType( int statusType ) { 116 | this.statusType = statusType; 117 | } 118 | 119 | public Map > getWatchedPathMap() { 120 | return watchedPathMap; 121 | } 122 | 123 | public void setWatchedPathMap( Map > watchedPathMap ) { 124 | this.watchedPathMap = watchedPathMap; 125 | } 126 | 127 | public String getWatchedPathMapContent() { 128 | return watchedPathMapContent; 129 | } 130 | 131 | public void setWatchedPathMapContent( String watchedPathMapContent ) { 132 | this.watchedPathMapContent = watchedPathMapContent; 133 | } 134 | 135 | public String getSent() { 136 | return sent; 137 | } 138 | 139 | public void setSent( String sent ) { 140 | this.sent = sent; 141 | } 142 | 143 | public String getReceived() { 144 | return Received; 145 | } 146 | 147 | public void setReceived( String received ) { 148 | Received = received; 149 | } 150 | 151 | @Override 152 | public String toString() { 153 | return "ZooKeeperStatus[ip: " + ip + ", isLeader: " + isLeader + ", nodeCount: " + nodeCount + ", " 154 | + connections + " 个客户端连接" + "在" + watchedPaths + "个path上注册了" + watches + "个watch" + clientConnectionList; 155 | } 156 | 157 | public String getConnectionsContent() { 158 | return convertConnsToHtmlContent(); 159 | } 160 | 161 | /** 把一个Map< String,Connection > connections 转换成html内容 */ 162 | private String convertConnsToHtmlContent(){ 163 | if( null == this.connections || connections.isEmpty() ) 164 | return "No conn on this server!"; 165 | StringBuffer sb = new StringBuffer(); 166 | 167 | // 这里可以统计连接数个数 168 | 169 | 170 | for( String sessionId : connections.keySet() ){ 171 | Connection conn = null; 172 | if( StringUtil.isBlank( sessionId ) || null == ( conn = connections.get( sessionId ) ) ) 173 | continue; 174 | sb.append( sessionId ).append( ": " ).append( conn.getClientIp() ).append( ", send to server: " ).append( conn.getReceiveTimes() ).append( ", receive from server: ").append( conn.getSendTimes() ).append( BR ); 175 | } 176 | return sb.toString(); 177 | } 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | } 189 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/type/EnvType.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model.type; 2 | 3 | /** 4 | * 类说明: 各种环境 5 | * 6 | * @author yinshi.nc 7 | */ 8 | public enum EnvType { 9 | 10 | TEST("TEST"), DAILY("DAILY"), ONLINE("ONLINE"), PREPARE("PREPARE"), SANDBOX("SANBOX"); 11 | 12 | private String envName; 13 | 14 | private EnvType(String envName) { 15 | this.envName = envName; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return this.envName; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /taokeeper-common/src/main/java/com/taobao/taokeeper/model/type/Message.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.model.type; 2 | 3 | /** 4 | * Description: 消息实体 5 | * 6 | * @author 银时 yinshi.nc@taobao.com 7 | * @Date Dec 26, 2011 8 | */ 9 | public class Message { 10 | 11 | /** 12 | * 邮件 13 | */ 14 | public static final String MAIL_TYPE = "1"; 15 | 16 | /** 17 | * 短信 18 | */ 19 | public static final String SMS_TYPE = "2"; 20 | 21 | /** 22 | * 站内信 23 | */ 24 | public static final String SITE_TYPE = "4"; 25 | 26 | /** 27 | * 旺旺 28 | */ 29 | public static final String WANGWANG_TYPE = "8"; 30 | 31 | /** 32 | * 消息类型 33 | */ 34 | public enum MessageType { 35 | SMS(SMS_TYPE), EMAIL(MAIL_TYPE), WANGWANG(WANGWANG_TYPE); 36 | 37 | private String type; 38 | private MessageType( String type ) { 39 | this.type = type; 40 | } 41 | public String toString() { 42 | return this.type; 43 | } 44 | } 45 | 46 | private String targetAddresses; 47 | private String subject; 48 | private String content; 49 | private Message.MessageType type; 50 | 51 | public Message( String targetAddresses, String subject, String content, Message.MessageType type ) { 52 | this.targetAddresses = targetAddresses; 53 | this.subject = subject; 54 | this.content = content; 55 | this.type = type; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "[targetAddresses: " + this.targetAddresses + ", subject: " + this.subject + ", content: " + this.content + ", type: " + this.type 61 | + "]"; 62 | } 63 | 64 | public String getTargetAddresses() { 65 | return targetAddresses; 66 | } 67 | 68 | public void setTargetAddresses( String targetAddresses ) { 69 | this.targetAddresses = targetAddresses; 70 | } 71 | 72 | public String getSubject() { 73 | return subject; 74 | } 75 | 76 | public void setSubject( String subject ) { 77 | this.subject = subject; 78 | } 79 | 80 | public String getContent() { 81 | return content; 82 | } 83 | 84 | public void setContent( String content ) { 85 | this.content = content; 86 | } 87 | 88 | public Message.MessageType getType() { 89 | return type; 90 | } 91 | 92 | public void setType( Message.MessageType type ) { 93 | this.type = type; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /taokeeper-monitor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.taobao.taokeeper 7 | taokeeper 8 | 1.1.2 9 | 10 | 11 | taokeeper-monitor 12 | taokeeper-monitor 13 | war 14 | 15 | 16 | taokeeper-monitor 17 | 18 | 19 | 20 | 21 | 22 | com.taobao.taokeeper 23 | taokeeper-common 24 | ${taokeeper.version} 25 | 26 | 27 | 28 | com.taobao.taokeeper 29 | taokeeper-reporter 30 | ${taokeeper.version} 31 | 32 | 33 | 34 | 35 | 36 | org.springframework 37 | spring-web 38 | 39 | 40 | org.springframework 41 | spring-webmvc 42 | 43 | 44 | org.springframework 45 | spring-test 46 | 47 | 48 | 49 | javax.servlet 50 | servlet-api 51 | 52 | 53 | 54 | commons-lang 55 | commons-lang 56 | 57 | 58 | commons-fileupload 59 | commons-fileupload 60 | 61 | 62 | commons-beanutils 63 | commons-beanutils 64 | 65 | 66 | commons-collections 67 | commons-collections 68 | 69 | 70 | 71 | commons-dbcp 72 | commons-dbcp 73 | 74 | 75 | 76 | 77 | 78 | junit 79 | junit 80 | 81 | 82 | 83 | 84 | 85 | 86 | ch.ethz.ganymed 87 | ganymed-ssh2 88 | 89 | 90 | 91 | 92 | commons-net 93 | commons-net 94 | 95 | 96 | 97 | 98 | displaytag 99 | displaytag 100 | 101 | 102 | javax.servlet 103 | jstl 104 | 105 | 106 | opensymphony 107 | sitemesh 108 | 109 | 110 | 111 | 112 | com.sdicons.jsontools 113 | jsontools-core 114 | 115 | 116 | org.json 117 | json 118 | 119 | 120 | 121 | 122 | commons-logging 123 | commons-logging 124 | 125 | 126 | log4j 127 | log4j 128 | 129 | 130 | org.slf4j 131 | jcl104-over-slf4j 132 | 133 | 134 | org.slf4j 135 | slf4j-log4j12 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/core/ThreadPoolManager.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.core; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | /** 10 | * Description: 线程池管理 11 | * 12 | * @author 银时 yinshi.nc@taobao.com 13 | * @Date Dec 25, 2011 14 | */ 15 | public class ThreadPoolManager { 16 | 17 | private static Logger LOG = LoggerFactory.getLogger( ThreadPoolManager.class ); 18 | 19 | private static int SIZE_OF_ZKNODEALIVECHECK_EXECUTOR = 5; 20 | private static int SIZE_OF_MESSAGESEND_EXECUTOR = 5; 21 | private static int SIZE_OF_ZKSERVERSTATUS_COLLECTOR_EXECUTOR = 3; 22 | private static int SIZE_OF_ZKSERVERPERFORMAN_CECOLLECTOR_EXECUTOR = 3; 23 | private static int SIZE_OF_ZKCLUSTERCONFIG_DUMPER_EXECUTOR = 2; 24 | 25 | 26 | public static void init(){ 27 | if( null == zooKeeperNodeAliveCheckExecutor ){ 28 | LOG.info( "Start init ThreadPoolManager..." ); 29 | zooKeeperNodeAliveCheckExecutor = Executors.newFixedThreadPool( SIZE_OF_ZKNODEALIVECHECK_EXECUTOR ); 30 | messageSendExecutor = Executors.newFixedThreadPool( SIZE_OF_MESSAGESEND_EXECUTOR ); 31 | zkServerStatusCollectorExecutor = Executors.newFixedThreadPool( SIZE_OF_ZKSERVERSTATUS_COLLECTOR_EXECUTOR ); 32 | zkServerPerformanceCollectorExecutor = Executors.newFixedThreadPool( SIZE_OF_ZKSERVERPERFORMAN_CECOLLECTOR_EXECUTOR ); 33 | zkClusterConfigDumperExecutor = Executors.newFixedThreadPool( SIZE_OF_ZKCLUSTERCONFIG_DUMPER_EXECUTOR ); 34 | } 35 | } 36 | 37 | 38 | 39 | /** 节点自检 线程池 */ 40 | private static ExecutorService zooKeeperNodeAliveCheckExecutor; 41 | public static void addJobToZooKeeperNodeAliveCheckExecutor( Runnable command ){ 42 | init(); 43 | zooKeeperNodeAliveCheckExecutor.execute( command ); 44 | } 45 | 46 | /** 消息发送 线程池 */ 47 | private static ExecutorService messageSendExecutor; 48 | public static void addJobToMessageSendExecutor( Runnable command ){ 49 | init(); 50 | messageSendExecutor.execute( command ); 51 | } 52 | 53 | /** 收集ZKServer状态信息 线程池 */ 54 | private static ExecutorService zkServerStatusCollectorExecutor; 55 | public static void addJobToZKServerStatusCollectorExecutor( Runnable command ){ 56 | init(); 57 | zkServerStatusCollectorExecutor.execute( command ); 58 | } 59 | 60 | 61 | /** 收集ZKServer机器信息 线程池 */ 62 | private static ExecutorService zkServerPerformanceCollectorExecutor; 63 | public static void addJobToZKServerPerformanceCollectorExecutor( Runnable command ){ 64 | init(); 65 | zkServerPerformanceCollectorExecutor.execute( command ); 66 | } 67 | 68 | /** Dump zk cluster config info to memeory*/ 69 | private static ExecutorService zkClusterConfigDumperExecutor; 70 | public static void addJobToZKClusterDumperExecutor( Runnable command ){ 71 | init(); 72 | zkClusterConfigDumperExecutor.execute( command ); 73 | } 74 | 75 | 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/core/task/CheckerJob.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.core.task; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.I0Itec.zkclient.ZkClient; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import common.toolkit.java.entity.DateFormat; 13 | import common.toolkit.java.util.DateUtil; 14 | 15 | /** 16 | * Description: Check if alive one node(ip). 17 | * 18 | * @author 银时 yinshi.nc@taobao.com 19 | * @Date 2011-10-28 20 | */ 21 | public class CheckerJob implements Runnable { 22 | 23 | private static final Logger LOG = LoggerFactory.getLogger( CheckerJob.class ); 24 | private static final Logger LOG_checkData = LoggerFactory.getLogger( "checkData" ); 25 | 26 | private Map< String, ZkClient > zkClientList = new HashMap< String, ZkClient >(); 27 | 28 | private String[] paths = { "/jingwei-v2/tasks/IC-DATA-DB2/locks", "/jingwei-v2/tasks/IC-DATA-DB3/locks", "/jingwei-v2/tasks/IC-DATA-DB4/locks", 29 | "/jingwei-v2/tasks/IC-DATA-DB5/locks", "/jingwei-v2/tasks/IC-DATA-DB6/locks", "/jingwei-v2/tasks/IC-DATA-DB7/locks", }; 30 | 31 | @Override 32 | public void run() { 33 | 34 | String[] serlist = { "172.24.113.124", "172.24.113.125", "172.24.113.126" }; 35 | // String[] serlist={ "10.232.102.188:2181", "10.232.102.189:2181" }; 36 | try { 37 | 38 | for ( String server : serlist ) { 39 | ZkClient zkClient = new ZkClient( server, 50000 ); 40 | zkClientList.put( server, zkClient ); 41 | } 42 | } catch ( Throwable e1 ) { 43 | // TODO Auto-generated catch block 44 | e1.printStackTrace(); 45 | } 46 | 47 | while ( true ) { 48 | try { 49 | 50 | for ( String path : paths ) { 51 | 52 | LOG_checkData.warn( "Path: " + path ); 53 | // System.err.println( "Path: " + path ); 54 | for ( String server : zkClientList.keySet() ) { 55 | StringBuffer sb = new StringBuffer( DateUtil.getNowTime( DateFormat.DateTime ) ); 56 | sb.append( " [server: " + server ).append( "] ,data: " ); 57 | List< String > lsit = new ArrayList< String >(); 58 | try { 59 | lsit = zkClientList.get( server ).getChildren( path ); 60 | } catch ( Throwable e ) { 61 | LOG.error( e.getMessage(), e ); 62 | } 63 | for ( String str : lsit ) { 64 | sb.append( str ); 65 | } 66 | LOG_checkData.warn( sb.toString() ); 67 | // System.err.println( sb.toString() ); 68 | } 69 | LOG.warn( "-------------------" ); 70 | // System.err.println("------------------"); 71 | Thread.sleep( 1 * 1000 ); 72 | } 73 | Thread.sleep( 10 * 1000 ); 74 | } catch ( Throwable e ) { 75 | LOG.error( e.getMessage(), e ); 76 | } 77 | } 78 | } 79 | 80 | public static void main( String[] args ) { 81 | Thread thread = new Thread( new CheckerJob() ); 82 | thread.start(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/core/task/HostPerformanceCollectTask.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.core.task; 2 | 3 | import static com.taobao.taokeeper.common.constant.SystemConstant.DELAY_MINS_OF_TWO_CYCLE_ALIVE_CHECK_ZOOKEEPER; 4 | import static com.taobao.taokeeper.common.constant.SystemConstant.MINS_RATE_OF_COLLECT_HOST_PERFORMANCE; 5 | import static common.toolkit.java.constant.SymbolConstant.COLON; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Date; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.web.context.ContextLoader; 15 | import org.springframework.web.context.WebApplicationContext; 16 | 17 | import com.taobao.taokeeper.common.GlobalInstance; 18 | import com.taobao.taokeeper.dao.AlarmSettingsDAO; 19 | import com.taobao.taokeeper.dao.ZooKeeperClusterDAO; 20 | import com.taobao.taokeeper.model.AlarmSettings; 21 | import com.taobao.taokeeper.model.ZooKeeperCluster; 22 | import com.taobao.taokeeper.monitor.core.ThreadPoolManager; 23 | import com.taobao.taokeeper.monitor.core.task.runable.ZKServerPerformanceCollector; 24 | import common.toolkit.java.exception.DaoException; 25 | import common.toolkit.java.util.DateUtil; 26 | import common.toolkit.java.util.StringUtil; 27 | import common.toolkit.java.util.ThreadUtil; 28 | 29 | /** 30 | * Description: Collect info of host performance 31 | * @author yinshi.nc 32 | * @Date 2011-10-28 33 | */ 34 | public class HostPerformanceCollectTask implements Runnable { 35 | 36 | private static final Logger LOG = LoggerFactory.getLogger( HostPerformanceCollectTask.class ); 37 | 38 | @Override 39 | public void run() { 40 | 41 | while ( true ) { 42 | 43 | if( !GlobalInstance.need_host_performance_collect ){ 44 | LOG.info( "No need to host_performance_collect, need_host_performance_collect=" + GlobalInstance.need_host_performance_collect ); 45 | ThreadUtil.sleep( 1000 * 60 * MINS_RATE_OF_COLLECT_HOST_PERFORMANCE ); 46 | continue; 47 | } 48 | 49 | try { 50 | // 根据clusterId来获取一个zk集群 51 | WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 52 | ZooKeeperClusterDAO zooKeeperClusterDAO = ( ZooKeeperClusterDAO ) wac.getBean( "zooKeeperClusterDAO" ); 53 | AlarmSettingsDAO alarmSettingsDAO = ( AlarmSettingsDAO ) wac.getBean( "alarmSettingsDAO" ); 54 | try { 55 | List< ZooKeeperCluster > zooKeeperClusterSet = null; 56 | Map< Integer, ZooKeeperCluster > zooKeeperClusterMap = GlobalInstance.getAllZooKeeperCluster(); 57 | if ( null == zooKeeperClusterMap ) { 58 | zooKeeperClusterSet = zooKeeperClusterDAO.getAllDetailZooKeeperCluster(); 59 | } else { 60 | zooKeeperClusterSet = new ArrayList< ZooKeeperCluster >(); 61 | zooKeeperClusterSet.addAll( zooKeeperClusterMap.values() ); 62 | } 63 | 64 | if ( null == zooKeeperClusterSet || zooKeeperClusterSet.isEmpty() ) { 65 | LOG.warn( "No zookeeper cluster config" ); 66 | } else { 67 | for ( ZooKeeperCluster zookeeperCluster : zooKeeperClusterSet ) { // 对每个cluster处理 68 | if ( null != zookeeperCluster && null != zookeeperCluster.getServerList() ) { 69 | AlarmSettings alarmSettings = alarmSettingsDAO.getAlarmSettingsByCulsterId( zookeeperCluster.getClusterId() ); 70 | for ( String server : zookeeperCluster.getServerList() ) { 71 | server = StringUtil.trimToEmpty( server ); 72 | if ( StringUtil.isBlank( server ) ) 73 | continue; 74 | String ip = StringUtil.trimToEmpty( server.split( COLON )[0] ); 75 | ThreadPoolManager.addJobToZKServerPerformanceCollectorExecutor( 76 | new ZKServerPerformanceCollector( ip, alarmSettings, zookeeperCluster ) 77 | ); 78 | }// for each server 79 | }// for each cluster 80 | } 81 | }//Finish all cluster HostPerformanceEntity collect 82 | LOG.info( "Finish all cluster HostPerformanceEntity collect" ); 83 | GlobalInstance.timeOfUpdateHostPerformanceSet = DateUtil.convertDate2String( new Date() ); 84 | } catch ( DaoException daoException ) { 85 | LOG.warn( "Error when handle data base" + daoException.getMessage() ); 86 | } catch ( Throwable e ) { 87 | LOG.error( "System Error:" + e.getMessage() ); 88 | e.printStackTrace(); 89 | } 90 | // collect per 2 mins 91 | Thread.sleep( 1000 * 60 * MINS_RATE_OF_COLLECT_HOST_PERFORMANCE ); 92 | } catch ( Throwable e ) { 93 | LOG.error( "Error when HostPerformanceEntityCollectJob: " + e.getMessage() ); 94 | e.printStackTrace(); 95 | } 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/core/task/ZooKeeperClusterMapDumpJob.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.core.task; 2 | import static com.taobao.taokeeper.common.constant.SystemConstant.MINS_RATE_OF_DUMP_ZOOKEEPER_CLUSTER; 3 | 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import com.taobao.taokeeper.monitor.core.ThreadPoolManager; 8 | import com.taobao.taokeeper.monitor.core.task.runable.ZKClusterConfigDumper; 9 | 10 | 11 | /** 12 | * Description:Dump ZooKeeper cluster info to memory 13 | * @author nileader / nileader@gmail.com 14 | * @Date Feb 16, 2012 15 | */ 16 | public class ZooKeeperClusterMapDumpJob implements Runnable { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger( ZooKeeperClusterMapDumpJob.class ); 19 | 20 | @Override 21 | public void run() { 22 | 23 | while( true ){ 24 | 25 | try{ 26 | ThreadPoolManager.addJobToZKClusterDumperExecutor( new ZKClusterConfigDumper() ); 27 | Thread.sleep( 1000 * 60 * MINS_RATE_OF_DUMP_ZOOKEEPER_CLUSTER ); 28 | }catch( Throwable e ){ 29 | LOG.error( "Error when dump zk cluster config info to memory: " + e.getMessage() ); 30 | e.printStackTrace(); 31 | } 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/core/task/ZooKeeperStatusCollectJob.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.core.task; 2 | 3 | import static com.taobao.taokeeper.common.constant.SystemConstant.MINS_RATE_OF_COLLECT_ZOOKEEPER; 4 | import static common.toolkit.java.constant.SymbolConstant.COLON; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Date; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.web.context.ContextLoader; 14 | import org.springframework.web.context.WebApplicationContext; 15 | 16 | import com.taobao.taokeeper.common.GlobalInstance; 17 | import com.taobao.taokeeper.dao.AlarmSettingsDAO; 18 | import com.taobao.taokeeper.dao.ZooKeeperClusterDAO; 19 | import com.taobao.taokeeper.model.AlarmSettings; 20 | import com.taobao.taokeeper.model.ZooKeeperCluster; 21 | import com.taobao.taokeeper.monitor.core.Initialization; 22 | import com.taobao.taokeeper.monitor.core.ThreadPoolManager; 23 | import com.taobao.taokeeper.monitor.core.task.runable.ZKServerStatusCollector; 24 | import common.toolkit.java.exception.DaoException; 25 | import common.toolkit.java.util.DateUtil; 26 | import common.toolkit.java.util.StringUtil; 27 | import common.toolkit.java.util.ThreadUtil; 28 | /** 29 | * Description: Collect info of zookeeper by jmx. 30 | * 31 | * @author yinshi.nc 32 | * @Date 2011-10-28 33 | */ 34 | public class ZooKeeperStatusCollectJob implements Runnable { 35 | 36 | private static final Logger LOG = LoggerFactory.getLogger( Initialization.class ); 37 | 38 | private boolean isFirst = true; 39 | 40 | @Override 41 | public void run() { 42 | 43 | while ( true ) { 44 | 45 | if( !GlobalInstance.need_zk_status_collect ){ 46 | LOG.info( "No need to zk status collect, need_zk_status_collect=" + GlobalInstance.need_zk_status_collect ); 47 | ThreadUtil.sleep( 1000 * 60 * MINS_RATE_OF_COLLECT_ZOOKEEPER ); 48 | continue; 49 | } 50 | 51 | 52 | try { 53 | // 根据clusterId来获取一个zk集群 54 | WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 55 | ZooKeeperClusterDAO zooKeeperClusterDAO = ( ZooKeeperClusterDAO ) wac.getBean( "zooKeeperClusterDAO" ); 56 | AlarmSettingsDAO alarmSettingsDAO = ( AlarmSettingsDAO ) wac.getBean( "alarmSettingsDAO" ); 57 | AlarmSettings alarmSettings = null; 58 | try { 59 | List< ZooKeeperCluster > zooKeeperClusterSet = null; 60 | Map< Integer, ZooKeeperCluster > zooKeeperClusterMap = GlobalInstance.getAllZooKeeperCluster(); 61 | if ( null == zooKeeperClusterMap ) { 62 | zooKeeperClusterSet = zooKeeperClusterDAO.getAllDetailZooKeeperCluster(); 63 | } else { 64 | zooKeeperClusterSet = new ArrayList< ZooKeeperCluster >(); 65 | zooKeeperClusterSet.addAll( zooKeeperClusterMap.values() ); 66 | } 67 | 68 | if ( null == zooKeeperClusterSet || zooKeeperClusterSet.isEmpty() ) { 69 | LOG.warn( "No zookeeper cluster" ); 70 | } else { 71 | for ( ZooKeeperCluster zookeeperCluster : zooKeeperClusterSet ) { // 对每个cluster处理 72 | alarmSettings = alarmSettingsDAO.getAlarmSettingsByCulsterId( zookeeperCluster.getClusterId() ); 73 | if ( null != zookeeperCluster && null != zookeeperCluster.getServerList() ) { 74 | 75 | for ( String server : zookeeperCluster.getServerList() ) { 76 | if ( StringUtil.isBlank( server ) ) 77 | continue; 78 | String ip = StringUtil.trimToEmpty( server.split( COLON )[0] ); 79 | String port = StringUtil.trimToEmpty( server.split( COLON )[1] ); 80 | 81 | //这里插入一个任务 82 | if( isFirst ){ 83 | ThreadPoolManager.addJobToZKServerStatusCollectorExecutor( new ZKServerStatusCollector( ip, port, alarmSettings, zookeeperCluster, false ) ); 84 | isFirst = false; 85 | }else{ 86 | ThreadPoolManager.addJobToZKServerStatusCollectorExecutor( new ZKServerStatusCollector( ip, port, alarmSettings, zookeeperCluster, true ) ); 87 | } 88 | }// for each server 89 | }// for each cluster 90 | } 91 | } 92 | LOG.info( "Finish all cluster status collect" ); 93 | GlobalInstance.timeOfUpdateZooKeeperStatusSet = DateUtil.convertDate2String( new Date() ); 94 | } catch ( DaoException daoException ) { 95 | LOG.warn( "Error when handle data base" + daoException.getMessage() ); 96 | } catch ( Exception e ) { 97 | LOG.error( "程序出错:" + e.getMessage() ); 98 | e.printStackTrace(); 99 | } 100 | // 每2分钟收集一次检测 101 | Thread.sleep( 1000 * 60 * MINS_RATE_OF_COLLECT_ZOOKEEPER ); 102 | } catch ( Throwable e ) { 103 | e.printStackTrace(); 104 | } 105 | } 106 | } 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/core/task/runable/ZKClusterConfigDumper.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.core.task.runable; 2 | 3 | import java.util.List; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.web.context.ContextLoader; 8 | import org.springframework.web.context.WebApplicationContext; 9 | 10 | import com.taobao.taokeeper.common.GlobalInstance; 11 | import com.taobao.taokeeper.dao.ZooKeeperClusterDAO; 12 | import com.taobao.taokeeper.model.ZooKeeperCluster; 13 | import common.toolkit.java.exception.DaoException; 14 | 15 | /** 16 | * Description: Dump zooKeeper cluster config info from database. 17 | * @author nileader / nileader@gmail.com 18 | * @Date Feb 16, 2012 19 | */ 20 | public class ZKClusterConfigDumper implements Runnable { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger( ZKClusterConfigDumper.class ); 23 | 24 | @Override 25 | public void run() { 26 | try { 27 | dumpZooKeeperClusterMapToMemory(); 28 | } catch ( DaoException daoException ) { 29 | LOG.error( "Error when dump zookeeper cluster config info to memeory: " + daoException.getMessage() ); 30 | daoException.printStackTrace(); 31 | } catch ( Throwable e ) { 32 | LOG.error( "Error when dump zookeeper cluster config info to memeory: " + e.getMessage() ); 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | /** 38 | * Dump zooKeeper cluster config info from database 39 | */ 40 | private boolean dumpZooKeeperClusterMapToMemory() throws DaoException { 41 | WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 42 | ZooKeeperClusterDAO zooKeeperClusterDAO = ( ZooKeeperClusterDAO ) wac.getBean( "zooKeeperClusterDAO" ); 43 | List< ZooKeeperCluster > zookeeperClusterSet = zooKeeperClusterDAO.getAllDetailZooKeeperCluster(); 44 | if ( null == zookeeperClusterSet || zookeeperClusterSet.isEmpty() ) { 45 | LOG.warn( "No zookeeper cluster" ); 46 | } else { 47 | // First clean up catch. 48 | GlobalInstance.clearZooKeeperCluster(); 49 | 50 | for ( ZooKeeperCluster zooKeeperCluster : zookeeperClusterSet ) { 51 | GlobalInstance.putZooKeeperCluster( zooKeeperCluster.getClusterId(), zooKeeperCluster ); 52 | } 53 | LOG.info( "Finsh dump all cluster info from db: " + GlobalInstance.getAllZooKeeperCluster() ); 54 | } 55 | return true; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/service/ReportService.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.service; 2 | 3 | /** 4 | * Description: Service of taokeeper_stat 5 | * @author yinshi.nc 6 | * @since 2012-01-05 7 | */ 8 | public interface ReportService { 9 | 10 | /** generate the content of server conns of each ip in cluster 11 | * @throws Exception 12 | * */ 13 | public String getReportContentOfServerConnectionByClusterIdAndServerAndStatDate( int clusterId, String server, String statDate ) throws Exception; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/service/impl/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.service.impl; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | import com.taobao.taokeeper.dao.AlarmSettingsDAO; 5 | import com.taobao.taokeeper.dao.ReportDAO; 6 | import com.taobao.taokeeper.dao.SettingsDAO; 7 | import com.taobao.taokeeper.dao.ZooKeeperClusterDAO; 8 | 9 | /** 10 | * 11 | * Description: Base Service 12 | * @author nileader / nileader@gmail.com 13 | * @Date Feb 18, 2012 14 | */ 15 | public class BaseService { 16 | 17 | @Autowired 18 | protected ZooKeeperClusterDAO zooKeeperClusterDAO; 19 | @Autowired 20 | protected AlarmSettingsDAO alarmSettingsDAO; 21 | @Autowired 22 | protected SettingsDAO taoKeeperSettingsDAO; 23 | @Autowired 24 | protected ReportDAO reportDAO; 25 | } -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/service/impl/ReportServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.service.impl; 2 | 3 | import static common.toolkit.java.constant.SymbolConstant.COLON; 4 | 5 | import java.util.List; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.taobao.taokeeper.model.TaoKeeperStat; 11 | import com.taobao.taokeeper.monitor.service.ReportService; 12 | import common.toolkit.java.constant.EmptyObjectConstant; 13 | import common.toolkit.java.exception.DaoException; 14 | import common.toolkit.java.util.ObjectUtil; 15 | import common.toolkit.java.util.StringUtil; 16 | 17 | /** 18 | * Description: Service of taokeeper_stat 19 | * @author yinshi.nc 20 | * @since 2012-01-05 21 | */ 22 | public class ReportServiceImpl extends BaseService implements ReportService { 23 | 24 | 25 | private static final Logger LOG = LoggerFactory.getLogger( ReportServiceImpl.class ); 26 | 27 | 28 | /** generate the content of server conns of each ip in cluster 29 | * @throws Exception */ 30 | public String getReportContentOfServerConnectionByClusterIdAndServerAndStatDate( int clusterId, String server, String statDate ) throws Exception { 31 | 32 | if ( StringUtil.isBlank( server ) ) 33 | return EmptyObjectConstant.EMPTY_STRING; 34 | 35 | List< TaoKeeperStat > taoKeeperStatList; 36 | try { 37 | taoKeeperStatList = reportDAO.queryTaoKeeperStatByClusterIdAndServerAndStatDate( clusterId, server, statDate ); 38 | } catch ( DaoException e ) { 39 | throw new Exception( "Error when get stat," + e.getMessage(), e.getCause() ); 40 | } 41 | 42 | StringBuffer contentOfReport = new StringBuffer( "[" ); 43 | for ( TaoKeeperStat taoKeeperStat : taoKeeperStatList ) { 44 | try { 45 | if ( ObjectUtil.isBlank( taoKeeperStat ) ) 46 | continue; 47 | 48 | String statDateTime = StringUtil.trimToEmpty( taoKeeperStat.getStatDateTime() ); 49 | String xValue = StringUtil.replaceAll( statDateTime.substring( 0, statDateTime.indexOf( "." ) ), EmptyObjectConstant.EMPTY_STRING, COLON ); 50 | int watchers = taoKeeperStat.getWatches(); 51 | int conns = taoKeeperStat.getConnections(); 52 | long nodeConut = taoKeeperStat.getNodeCount(); 53 | if( StringUtil.trimToEmpty( xValue ).startsWith( "0" ) ) 54 | xValue = xValue.replaceFirst( "0", EmptyObjectConstant.EMPTY_STRING ); 55 | contentOfReport.append( "{date: " + xValue + ",watchers: " + watchers + ",conns: " + conns + ",znodes: " + nodeConut + "}," ); 56 | } catch ( Throwable e ) { 57 | LOG.error( "Error when parse:" + taoKeeperStat ); 58 | // TODO Auto-generated catch block 59 | e.printStackTrace(); 60 | } 61 | 62 | } 63 | 64 | contentOfReport.append( "]" ); 65 | 66 | return contentOfReport.toString(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/AdminController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.servlet.ModelAndView; 15 | 16 | import com.taobao.taokeeper.common.GlobalInstance; 17 | import com.taobao.taokeeper.model.TaoKeeperSettings; 18 | import common.toolkit.java.util.StringUtil; 19 | import common.toolkit.java.util.io.ServletUtil; 20 | 21 | /** 22 | * Admin 23 | * 24 | * @author yinshi.nc@taobao.com 25 | * @since 2011-08-10 26 | */ 27 | @Controller 28 | @RequestMapping("/admin.do") 29 | public class AdminController extends BaseController { 30 | 31 | 32 | private static final Logger LOG = LoggerFactory.getLogger( AdminController.class ); 33 | 34 | /** PAGE 是否开启报警开关 */ 35 | @RequestMapping(params = "method=switchOfNeedAlarmPAGE") 36 | public ModelAndView switchOfNeedAlarmPAGE( HttpServletRequest request, HttpServletResponse response, String handleMessage ) { 37 | 38 | Map< String, Object > model = new HashMap< String, Object >(); 39 | model.put( "needAlarm", GlobalInstance.needAlarm.get() ); 40 | model.put( "handleMessage", handleMessage ); 41 | return new ModelAndView( "admin/switchOfNeedAlarmPAGE", model ); 42 | } 43 | 44 | /** HANDLE 是否开启报警开关 */ 45 | @RequestMapping(params = "method=updateSwitchOfNeedAlarmHandle") 46 | public String updateSwitchOfNeedAlarmHandle( HttpServletRequest request, HttpServletResponse response, String needAlarm ) { 47 | 48 | String handleMessage = EMPTY_STRING; 49 | if ( "true".equalsIgnoreCase( needAlarm ) ) { 50 | GlobalInstance.needAlarm.set( true ); 51 | handleMessage = "Success, now open alarm!"; 52 | } else { 53 | GlobalInstance.needAlarm.set( false ); 54 | handleMessage = "Success, now close alarm!"; 55 | } 56 | return "redirect:admin.do?method=switchOfNeedAlarmPAGE&handleMessage=" + handleMessage; 57 | } 58 | 59 | /** PAGE 系统设置 */ 60 | @RequestMapping(params = "method=setSystemConfigPAGE") 61 | public ModelAndView setSystemConfigPAGE( HttpServletRequest request, HttpServletResponse response, String handleMessage ) { 62 | 63 | try { 64 | TaoKeeperSettings taoKeeperSettings = GlobalInstance.taoKeeperSettings; 65 | if( null == taoKeeperSettings ){ 66 | taoKeeperSettings = taoKeeperSettingsDAO.getTaoKeeperSettingsBySettingsId( 1 ); 67 | if( null == taoKeeperSettings ){ 68 | ServletUtil.writeToResponse( response, "目前还没有TaoKeeper配置" ); 69 | return null; 70 | } 71 | } 72 | Map< String, Object > model = new HashMap< String, Object >(); 73 | model.put( "settingsId", taoKeeperSettings.getSettingsId() ); 74 | model.put( "envName", taoKeeperSettings.getEnvName() ); 75 | model.put( "maxThreadsOfZooKeeperCheck", taoKeeperSettings.getMaxThreadsOfZooKeeperCheck() ); 76 | model.put( "description", taoKeeperSettings.getDescription() ); 77 | model.put( "handleMessage", handleMessage ); 78 | return new ModelAndView( "admin/setSystemConfigPAGE", model ); 79 | } catch ( Exception e ) { 80 | ServletUtil.showSystemErrorToResponse( response, e ); 81 | e.printStackTrace(); 82 | return null; 83 | } 84 | } 85 | 86 | 87 | /** Handle 系统配置 */ 88 | @RequestMapping(params = "method=setSystemConfigHANDLE") 89 | public String setSystemConfigHandle( HttpServletRequest request, HttpServletResponse response, 90 | String handleMessage, 91 | String settingsId, 92 | String envName, 93 | String description, 94 | String maxThreadsOfZooKeeperCheck ) { 95 | maxThreadsOfZooKeeperCheck = StringUtil.defaultIfBlank( maxThreadsOfZooKeeperCheck, GlobalInstance.taoKeeperSettings.getMaxThreadsOfZooKeeperCheck() + EMPTY_STRING ); 96 | try { 97 | 98 | TaoKeeperSettings taoKeeperSettings = new TaoKeeperSettings(); 99 | int settingsIdInt = Integer.parseInt( settingsId ) != 0 ? Integer.parseInt( settingsId ) : 1; 100 | taoKeeperSettings.setSettingsId( settingsIdInt ); 101 | taoKeeperSettings.setEnvName( envName ); 102 | taoKeeperSettings.setDescription( description ); 103 | taoKeeperSettings.setMaxThreadsOfZooKeeperCheck( Integer.parseInt( maxThreadsOfZooKeeperCheck ) ); 104 | 105 | //先查询下是否存在这样的记录,如果不存在,先进行添加 106 | TaoKeeperSettings taoKeeperSettings_Old = taoKeeperSettingsDAO.getTaoKeeperSettingsBySettingsId( taoKeeperSettings.getSettingsId() ); 107 | if( null == taoKeeperSettings_Old ){ 108 | //进行添加 109 | taoKeeperSettingsDAO.addTaoKeeperSettings( taoKeeperSettings ); 110 | }else{ 111 | //更新数据库 112 | taoKeeperSettingsDAO.updateTaoKeeperSettingsBySettingsId( taoKeeperSettings ); 113 | } 114 | //更新缓存 115 | GlobalInstance.taoKeeperSettings = taoKeeperSettings; 116 | handleMessage = "Success to update system config."; 117 | LOG.info( "Success to update system config." ); 118 | } catch ( Exception e ) { 119 | handleMessage = "Fail to update system config, error: " + e.getMessage(); 120 | LOG.error( "Fail to update system config, error: " + e.getMessage() ); 121 | } 122 | return "redirect:admin.do?method=setSystemConfigPAGE&handleMessage=" + handleMessage; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/AlarmSettingsController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.servlet.ModelAndView; 13 | 14 | import com.taobao.taokeeper.common.GlobalInstance; 15 | import com.taobao.taokeeper.model.AlarmSettings; 16 | import com.taobao.taokeeper.model.ZooKeeperCluster; 17 | import common.toolkit.java.exception.DaoException; 18 | import common.toolkit.java.util.StringUtil; 19 | import common.toolkit.java.util.io.ServletUtil; 20 | 21 | /** 22 | * @author yinshi.nc@taobao.com 23 | * @since 2011-08-10 24 | */ 25 | @Controller 26 | @RequestMapping("/alarmSettings.do") 27 | public class AlarmSettingsController extends BaseController { 28 | 29 | @RequestMapping(params = "method=alarmSettingsPAGE") 30 | public ModelAndView alarmSettingsPAGE(HttpServletRequest request, HttpServletResponse response, String clusterId, String handleMessage ) { 31 | 32 | clusterId = StringUtil.defaultIfBlank( clusterId, 1 + EMPTY_STRING ); 33 | 34 | try { 35 | Map zooKeeperClusterMap = GlobalInstance.getAllZooKeeperCluster(); 36 | Map alarmSettingsMap = GlobalInstance.getAllAlarmSettings(); 37 | AlarmSettings alarmSettings = GlobalInstance.getAlarmSettingsByClusterId( Integer.parseInt( clusterId ) ); 38 | if( null == alarmSettings ){ 39 | alarmSettings = alarmSettingsDAO.getAlarmSettingsByCulsterId( Integer.parseInt( clusterId) ); 40 | } 41 | if( null == alarmSettings ){ 42 | ServletUtil.writeToResponse( response, "目前还没有这样的ZK集群 加入监控" ); 43 | return null; 44 | } 45 | 46 | 47 | Map model = new HashMap(); 48 | model.put( "alarmSettings", alarmSettings ); 49 | model.put( "alarmSettingsMap", alarmSettingsMap ); 50 | model.put("clusterId", clusterId ); 51 | model.put( "zooKeeperClusterMap", zooKeeperClusterMap ); 52 | model.put( "handleMessage", StringUtil.trimToEmpty( handleMessage ) ); 53 | return new ModelAndView("monitor/alarmSettingsPAGE", model ); 54 | } catch ( NumberFormatException e ) { 55 | // TODO Auto-generated catch block 56 | e.printStackTrace(); 57 | } catch ( DaoException e ) { 58 | // TODO Auto-generated catch block 59 | e.printStackTrace(); 60 | } catch ( Exception e ) { 61 | // TODO Auto-generated catch block 62 | e.printStackTrace(); 63 | } 64 | 65 | return null; 66 | 67 | } 68 | 69 | 70 | @RequestMapping(params = "method=updateAlarmSettingsHandle") 71 | public String updateAlarmSettingsHandle( HttpServletRequest request, HttpServletResponse response, 72 | String clusterId, 73 | String maxDelayOfCheck, 74 | String maxCpuUsage, 75 | String maxMemoryUsage, 76 | String maxLoad, 77 | String wangwangList, 78 | String phoneList, 79 | String emailList, 80 | String maxConnectionPerIp, 81 | String maxWatchPerIp, 82 | String dataDir, 83 | String dataLogDir, 84 | String maxDiskUsage, 85 | String nodePathCheckRule ) { 86 | 87 | try { 88 | if( StringUtil.isBlank( clusterId ) ) 89 | throw new Exception( "clusterId 不能为空" ); 90 | 91 | AlarmSettings alarmSettings = new AlarmSettings(); 92 | alarmSettings.setClusterId( Integer.parseInt( clusterId) ); 93 | alarmSettings.setMaxDelayOfCheck( StringUtil.trimToEmpty( maxDelayOfCheck ) ); 94 | alarmSettings.setMaxCpuUsage( StringUtil.trimToEmpty( maxCpuUsage ) ); 95 | alarmSettings.setMaxMemoryUsage( StringUtil.trimToEmpty( maxMemoryUsage ) ); 96 | alarmSettings.setMaxLoad( StringUtil.trimToEmpty( maxLoad ) ); 97 | alarmSettings.setWangwangList( StringUtil.trimToEmpty( wangwangList ) ); 98 | alarmSettings.setPhoneList( StringUtil.trimToEmpty( phoneList ) ); 99 | alarmSettings.setEmailList( StringUtil.trimToEmpty( emailList ) ); 100 | alarmSettings.setMaxConnectionPerIp( StringUtil.trimToEmpty( maxConnectionPerIp ) ); 101 | alarmSettings.setMaxWatchPerIp( StringUtil.trimToEmpty( maxWatchPerIp ) ); 102 | alarmSettings.setDataDir( StringUtil.trimToEmpty( dataDir ) ); 103 | alarmSettings.setDataLogDir( StringUtil.trimToEmpty( dataLogDir ) ); 104 | alarmSettings.setMaxDiskUsage( StringUtil.trimToEmpty( maxDiskUsage ) ); 105 | alarmSettings.setNodePathCheckRule( StringUtil.trimToEmpty( nodePathCheckRule ) ); 106 | //进行Update 107 | String handleMessage = null; 108 | if( alarmSettingsDAO.updateAlarmSettingsByClusterId( alarmSettings ) ){ 109 | handleMessage = "Update Success"; 110 | }else{ 111 | handleMessage = "Update Fail"; 112 | } 113 | return "redirect:/alarmSettings.do?method=alarmSettingsPAGE&clusterId=" + clusterId + "&handleMessage=" + handleMessage; 114 | } catch ( NumberFormatException e ) { 115 | // TODO Auto-generated catch block 116 | e.printStackTrace(); 117 | } catch ( DaoException e ) { 118 | // TODO Auto-generated catch block 119 | e.printStackTrace(); 120 | } catch ( Exception e ) { 121 | // TODO Auto-generated catch block 122 | e.printStackTrace(); 123 | } 124 | return null; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | import com.taobao.taokeeper.dao.AlarmSettingsDAO; 5 | import com.taobao.taokeeper.dao.SettingsDAO; 6 | import com.taobao.taokeeper.dao.ZooKeeperClusterDAO; 7 | import com.taobao.taokeeper.monitor.service.ReportService; 8 | 9 | /** 10 | * Description: Base Controller 11 | * @author yinshi.nc 12 | * @Date 2011-11-11 13 | */ 14 | public class BaseController { 15 | 16 | @Autowired 17 | protected ZooKeeperClusterDAO zooKeeperClusterDAO; 18 | @Autowired 19 | protected AlarmSettingsDAO alarmSettingsDAO; 20 | @Autowired 21 | protected SettingsDAO taoKeeperSettingsDAO; 22 | @Autowired 23 | protected ReportService reportService; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/DefaultController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | 10 | 11 | /** 12 | * Admin 13 | * @author yinshi.nc@taobao.com 14 | * @since 2011-11-15 15 | */ 16 | @Controller 17 | @RequestMapping("/default.do") 18 | public class DefaultController extends BaseController { 19 | 20 | 21 | @RequestMapping( method = RequestMethod.GET ) 22 | public String switchOfNeedAlarmPAGE(HttpServletRequest request, HttpServletResponse response ) { 23 | return "redirect:/zooKeeperStatus.do?method=showZooKeeperStatusPAGE"; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/HostPerformanceController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 3 | import static common.toolkit.java.constant.SymbolConstant.COLON; 4 | 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.servlet.ModelAndView; 15 | 16 | import com.taobao.taokeeper.common.GlobalInstance; 17 | import com.taobao.taokeeper.model.ZooKeeperCluster; 18 | import common.toolkit.java.entity.HostPerformanceEntity; 19 | import common.toolkit.java.exception.DaoException; 20 | import common.toolkit.java.util.StringUtil; 21 | import common.toolkit.java.util.io.ServletUtil; 22 | 23 | /** 24 | * @author yinshi.nc@taobao.com 25 | * @since 2011-08-10 26 | */ 27 | @Controller 28 | @RequestMapping("/hostPerformance.do") 29 | public class HostPerformanceController extends BaseController { 30 | 31 | @RequestMapping(params = "method=showHostPerformancePAGE") 32 | public ModelAndView showSystemPerformancePAGE(HttpServletRequest request, HttpServletResponse response, String clusterId ) { 33 | 34 | clusterId = StringUtil.defaultIfBlank( clusterId, 1 + EMPTY_STRING ); 35 | 36 | try { 37 | Map zooKeeperClusterMap = GlobalInstance.getAllZooKeeperCluster(); 38 | ZooKeeperCluster zooKeeperCluster = GlobalInstance.getZooKeeperClusterByClusterId( Integer.parseInt( clusterId) ); 39 | Map hostPerformanceEntityMap = new HashMap< String, HostPerformanceEntity >(); 40 | if( null == zooKeeperCluster ){ 41 | zooKeeperCluster = zooKeeperClusterDAO.getZooKeeperClusterByCulsterId( Integer.parseInt( clusterId) ); 42 | } 43 | if( null == zooKeeperCluster ){ 44 | ServletUtil.writeToResponse( response, "目前还没有这样的ZK集群 加入监控" ); 45 | return null; 46 | } 47 | 48 | 49 | //进行系统数据采集 50 | List serverList = zooKeeperCluster.getServerList(); 51 | if( null != serverList ){ 52 | for( String server : serverList ){ 53 | String ip = StringUtil.trimToEmpty( server.split( COLON )[0] ); 54 | hostPerformanceEntityMap.put( ip, GlobalInstance.getHostPerformanceEntity( ip ) ); 55 | } 56 | } 57 | 58 | Map model = new HashMap(); 59 | model.put( "hostPerformanceEntityMap", hostPerformanceEntityMap ); 60 | model.put( "zooKeeperClusterMap", zooKeeperClusterMap ); 61 | model.put( "description", zooKeeperCluster.getDescription() ); 62 | model.put("clusterId", zooKeeperCluster.getClusterId() ); 63 | model.put( "timeOfUpdateHostPerformanceSet", GlobalInstance.timeOfUpdateHostPerformanceSet ); 64 | return new ModelAndView("monitor/showHostPerformancePAGE", model ); 65 | } catch ( NumberFormatException e ) { 66 | // TODO Auto-generated catch block 67 | e.printStackTrace(); 68 | } catch ( DaoException e ) { 69 | // TODO Auto-generated catch block 70 | e.printStackTrace(); 71 | } catch ( Exception e ) { 72 | // TODO Auto-generated catch block 73 | e.printStackTrace(); 74 | } 75 | 76 | return null; 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/ReportController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.servlet.ModelAndView; 15 | 16 | import common.toolkit.java.entity.DateFormat; 17 | import common.toolkit.java.exception.DaoException; 18 | import common.toolkit.java.util.DateUtil; 19 | import common.toolkit.java.util.StringUtil; 20 | import common.toolkit.java.util.io.ServletUtil; 21 | 22 | /** 23 | * Report 24 | * 25 | * @author yinshi.nc@taobao.com 26 | * @since 2011-08-10 27 | */ 28 | @Controller 29 | @RequestMapping("/report.do") 30 | public class ReportController extends BaseController { 31 | 32 | 33 | private static final Logger LOG = LoggerFactory.getLogger( ReportController.class ); 34 | 35 | /** PAGE 是否开启报警开关 */ 36 | @RequestMapping(params = "method=reportPAGE") 37 | public ModelAndView reportPAGE( HttpServletRequest request, HttpServletResponse response, String clusterId, String server, String statDate ){ 38 | 39 | try { 40 | clusterId = StringUtil.defaultIfBlank( clusterId, 1 + EMPTY_STRING ); 41 | statDate = StringUtil.defaultIfBlank( statDate, DateUtil.getNowTime( DateFormat.Date ) ); 42 | 43 | String contentOfReport = reportService.getReportContentOfServerConnectionByClusterIdAndServerAndStatDate( Integer.parseInt( clusterId ), server, statDate ); 44 | 45 | Map model = new HashMap(); 46 | model.put( "contentOfReport", contentOfReport ); 47 | model.put("clusterId", clusterId ); 48 | model.put("server", server ); 49 | model.put("statDate", statDate ); 50 | return new ModelAndView( "report/report", model ); 51 | 52 | } catch (NumberFormatException e) { 53 | LOG.error( "不合法的clusterId:" + clusterId ); 54 | ServletUtil.writeToResponse(response, "不合法的clusterId:" + clusterId ); 55 | e.printStackTrace(); 56 | } catch ( DaoException e ) { 57 | LOG.error( "Error when handle db: " + e.getMessage() ); 58 | ServletUtil.writeToResponse(response, "Error when handle db: " + e.getMessage() ); 59 | e.printStackTrace(); 60 | } catch ( Exception e ) { 61 | LOG.error( "Server error : " + e.getMessage() ); 62 | ServletUtil.writeToResponse(response, "Server error: " + e.getMessage() ); 63 | e.printStackTrace(); 64 | } 65 | 66 | return null; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/java/com/taobao/taokeeper/monitor/web/ZooKeeperStatusController.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.monitor.web; 2 | import static common.toolkit.java.constant.EmptyObjectConstant.EMPTY_STRING; 3 | import static common.toolkit.java.constant.SymbolConstant.COLON; 4 | 5 | import java.io.IOException; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.servlet.ModelAndView; 18 | 19 | import com.taobao.taokeeper.common.GlobalInstance; 20 | import com.taobao.taokeeper.model.ZooKeeperCluster; 21 | import com.taobao.taokeeper.model.ZooKeeperStatus; 22 | import common.toolkit.java.exception.DaoException; 23 | import common.toolkit.java.util.StringUtil; 24 | import common.toolkit.java.util.io.ServletUtil; 25 | 26 | /** 27 | * Control of ZooKeeperStatus 28 | * @author yinshi.nc@taobao.com 29 | * @since 2011-08-10 30 | */ 31 | @Controller 32 | @RequestMapping("/zooKeeperStatus.do") 33 | public class ZooKeeperStatusController extends BaseController { 34 | 35 | private static final Logger LOG = LoggerFactory.getLogger( ZooKeeperStatusController.class ); 36 | 37 | @RequestMapping(params = "method=showZooKeeperStatusPAGE") 38 | public ModelAndView showZooKeeperStatusPAGE(HttpServletRequest request, HttpServletResponse response, String clusterId ) throws IOException{ 39 | 40 | try { 41 | clusterId = StringUtil.defaultIfBlank( clusterId, 1 + EMPTY_STRING ); 42 | 43 | ZooKeeperCluster zooKeeperCluster = GlobalInstance.getZooKeeperClusterByClusterId( Integer.parseInt( clusterId) ); 44 | Map zooKeeperClusterMap = GlobalInstance.getAllZooKeeperCluster(); 45 | if( null == zooKeeperCluster ){ 46 | zooKeeperCluster = zooKeeperClusterDAO.getZooKeeperClusterByCulsterId( Integer.parseInt( clusterId) ); 47 | } 48 | 49 | if( null == zooKeeperCluster ){ 50 | ServletUtil.writeToResponse( response, "目前还没有这样的ZK集群 加入监控" ); 51 | return null; 52 | } 53 | 54 | Map zooKeeperStatusMap = new HashMap(); 55 | 56 | //进行系统数据采集 57 | List serverList = zooKeeperCluster.getServerList(); 58 | if( null != serverList ){ 59 | for( String server : serverList ){ 60 | String ip = StringUtil.trimToEmpty( server.split( COLON )[0] ); 61 | //获取自检状态 62 | int statusType = GlobalInstance.getZooKeeperStatusType( ip ); 63 | ZooKeeperStatus zooKeeperStatus = GlobalInstance.getZooKeeperStatus(ip); 64 | if( null != zooKeeperStatus ){ 65 | zooKeeperStatus.setStatusType( statusType ); 66 | }else{ 67 | zooKeeperStatus = new ZooKeeperStatus(); 68 | zooKeeperStatus.setStatusType( statusType ); 69 | } 70 | zooKeeperStatusMap.put( ip, zooKeeperStatus ); 71 | } 72 | } 73 | 74 | Map model = new HashMap(); 75 | model.put( "zooKeeperStatusMap", zooKeeperStatusMap ); 76 | model.put("clusterId", zooKeeperCluster.getClusterId() ); 77 | model.put("clusterName", zooKeeperCluster.getClusterName() ); 78 | model.put("description", zooKeeperCluster.getDescription() ); 79 | model.put("zooKeeperClusterMap", zooKeeperClusterMap ); 80 | model.put( "timeOfUpdateZooKeeperStatusSet", GlobalInstance.timeOfUpdateZooKeeperStatusSet ); 81 | return new ModelAndView( "monitor/zooKeeperStatusPAGE", model ); 82 | 83 | } catch (NumberFormatException e) { 84 | LOG.error( "不合法的clusterId:" + clusterId ); 85 | ServletUtil.writeToResponse(response, "不合法的clusterId:" + clusterId ); 86 | e.printStackTrace(); 87 | } catch ( DaoException e ) { 88 | LOG.error( "Error when handle db: " + e.getMessage() ); 89 | ServletUtil.writeToResponse(response, "Error when handle db: " + e.getMessage() ); 90 | e.printStackTrace(); 91 | } catch ( Exception e ) { 92 | LOG.error( "Server error : " + e.getMessage() ); 93 | ServletUtil.writeToResponse(response, "Server error: " + e.getMessage() ); 94 | e.printStackTrace(); 95 | } 96 | 97 | return null; 98 | } 99 | 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | 2 | # DEFAULT 3 | log4j.rootLogger=INFO,ROLLINGFILE,CONSOLE 4 | 5 | # 6 | # Log INFO level and above messages to the console 7 | # 8 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 9 | log4j.appender.CONSOLE.Threshold=INFO 10 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{2}@%L] - %m%n 12 | 13 | # 14 | # Add ROLLINGFILE to rootLogger to get log file output 15 | # Log DEBUG level and above messages to a log file 16 | log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender 17 | log4j.appender.ROLLINGFILE.Threshold=INFO 18 | log4j.appender.ROLLINGFILE.File=/home/admin/taokeeper-monitor/logs/taokeeper-monitor.log 19 | log4j.appender.ROLLINGFILE.DatePattern='.'yyyy-MM-dd 20 | 21 | log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout 22 | log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{2}@%L] - %m%n 23 | 24 | 25 | log4j.appender.CHECKDATAFILE=org.apache.log4j.DailyRollingFileAppender 26 | log4j.appender.CHECKDATAFILE.Threshold=INFO 27 | log4j.appender.CHECKDATAFILE.File=/home/admin/taokeeper-monitor/logs/taokeeper-check-data.log 28 | log4j.appender.CHECKDATAFILE.DatePattern='.'yyyy-MM-dd 29 | 30 | log4j.appender.CHECKDATAFILE.layout=org.apache.log4j.PatternLayout 31 | log4j.appender.CHECKDATAFILE.layout.ConversionPattern=%m%n 32 | 33 | log4j.logger.org.displaytag=WARN 34 | log4j.logger.org.springframework=WARN 35 | log4j.logger.org.I0Itec=WARN 36 | log4j.logger.org.apache.zookeeper=WARN 37 | log4j.logger.checkData=INFO,CHECKDATAFILE -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/404.jsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/404.jsp -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/500.jsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/500.jsp -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/common/footer.jsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/WEB-INF/common/footer.jsp -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/common/header.jsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/WEB-INF/common/header.jsp -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/common/taglibs.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK" isELIgnored="false"%> 2 | 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 5 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 6 | 7 | <%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%> 8 | <%@ taglib prefix="display" uri="http://displaytag.sf.net"%> 9 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/decorators.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/WEB-INF/decorators.xml -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/decorators/default.jsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/WEB-INF/decorators/default.jsp -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/jsp/admin/setSystemConfigPAGE.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" pageEncoding="UTF-8"%><%@ include 2 | file="/WEB-INF/common/taglibs.jsp"%> 3 | 4 | 5 | 6 | 7 | 8 |

管理员-ZooKeeper 节点自检 线程数

9 |
10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 |
ID${settingsId}
环境名称
节点自检 线程数
描述
31 | 32 | ${handleMessage}
36 | 37 |
38 |
39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/jsp/admin/switchOfNeedAlarmPAGE.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" pageEncoding="UTF-8"%><%@ include 2 | file="/WEB-INF/common/taglibs.jsp"%> 3 | 4 | 5 | 12 | 13 | 19 | 20 | 21 | 22 |

管理员-ZooKeeper 监控报警开关

23 |
24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 37 | 38 | 39 |
监控报警开关
32 | 33 | 开启 关闭 34 | 开启 关闭 35 | 36 | ${handleMessage}
40 | 41 |
42 |
43 | 44 | 62 | 63 | 64 | 65 | 66 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" pageEncoding="GBK"%> 2 | <%@ include file="/WEB-INF/common/taglibs.jsp"%> 3 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/jsp/monitor/showHostPerformancePAGE.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" pageEncoding="UTF-8"%><%@ include 2 | file="/WEB-INF/common/taglibs.jsp"%> 3 | 4 | 5 | 12 | 13 | 19 | 20 | 21 | 22 |

ZooKeeper机器状态 更新时间:${timeOfUpdateHostPerformanceSet }

23 | 24 | 32 | ${description}

33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
Node IPCpu UsageMemory UsageLoadDisk
${ hostPerformanceEntity.key }${ hostPerformanceEntity.value.cpuUsage }${ hostPerformanceEntity.value.memoryUsage }${ hostPerformanceEntity.value.load }${ hostPerformanceEntity.value.diskUsageMap }
54 |
55 | 56 | 57 | 77 | 78 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/jsp/monitor/zooKeeperRegisterPAGE.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" pageEncoding="UTF-8"%><%@ include 2 | file="/WEB-INF/common/taglibs.jsp"%> 3 | 4 | 5 | 12 | 13 | 19 |

ZooKeeper 注册

20 | 21 |
22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
配置项设置参数
ZooKeeper集群名称
机器列表
描述
${handleMessage}
46 |
47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 76 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/jsp/monitor/zooKeeperSettingsPAGE.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%@ page language="java" pageEncoding="UTF-8"%><%@ include 8 | file="/WEB-INF/common/taglibs.jsp"%> 9 | 10 | 11 | 18 | 19 | 25 |

ZooKeeper 集群信息 加入监控

26 | 27 | 35 |
36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
配置项设置参数
ZooKeeper集群名称
机器列表
描述
${handleMessage}
60 | 61 |
62 | 63 | 64 |
65 | 66 | 67 | 68 | 69 | 70 | 71 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/sitemesh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/spring-beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/spring-common.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | TaoKeeper Web Application 7 | 8 | 9 | 10 | contextConfigLocation 11 | /WEB-INF/spring-common.xml 12 | 13 | 14 | 15 | 16 | 17 | org.springframework.web.context.ContextLoaderListener 18 | 19 | 20 | TaoKeeper-Monitor 21 | org.springframework.web.servlet.DispatcherServlet 22 | 23 | contextConfigLocation 24 | /WEB-INF/spring-common.xml 25 | 26 | 1 27 | 28 | 29 | TaoKeeper-Monitor 30 | *.do 31 | 32 | 33 | 34 | 35 | sitemesh 36 | com.opensymphony.sitemesh.webapp.SiteMeshFilter 37 | 38 | 39 | sitemesh 40 | /* 41 | 42 | 43 | 44 | TaskStartup 45 | com.taobao.taokeeper.monitor.core.Initialization 46 | 2 47 | 48 | 49 | 50 | 51 | 52 | 53 | CharacterEncoding 54 | common.toolkit.java.filter.RequestCharacterEncodingFilter 55 | 56 | request-encoding-post 57 | GBK 58 | 59 | 60 | request-encoding-get 61 | GBK 62 | 63 | 64 | 65 | CharacterEncoding 66 | /* 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | index.jsp 88 | 89 | 90 | 404 91 | /404.jsp 92 | 93 | 94 | 500 95 | /500.jsp 96 | 97 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/default.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0px auto; 3 | padding: 0px; 4 | min-width: 720px; 5 | font-family: Verdana, Helvetica, Arial, sans-serif; 6 | font-size: 12px; 7 | font-weight: normal; 8 | } 9 | 10 | img { 11 | border: none; 12 | } 13 | 14 | table { 15 | margin: 0px; 16 | padding: 0px; 17 | width: 100%; 18 | } 19 | 20 | div.clear { 21 | clear: both; 22 | visibility: hidden; 23 | } 24 | 25 | div.clear hr { 26 | display: none; 27 | } 28 | 29 | ul { 30 | margin: 0px; 31 | padding: 0px; 32 | list-style-type: none; 33 | } 34 | 35 | ul li { 36 | margin-top: 5px; 37 | padding: 0px; 38 | } 39 | 40 | ul li li { 41 | margin-left: 15px; 42 | } 43 | 44 | a { 45 | text-decoration: none; 46 | } 47 | 48 | a:link { 49 | color: #36a; 50 | } 51 | 52 | a:visited { 53 | color: #47a; 54 | } 55 | 56 | a:active,a:hover { 57 | color: #69c; 58 | } 59 | 60 | #leftColumn { 61 | margin-top: 10px; 62 | padding: 0px; 63 | float: left; 64 | width: 120px; 65 | } 66 | 67 | #rightColumn { 68 | margin-top: 10px; 69 | margin-left: 15px; 70 | padding: 0px; 71 | float: left; 72 | min-width: 600px; 73 | min-height: 400px; 74 | } 75 | 76 | #bodyColumn { 77 | margin: 0px; 78 | } 79 | 80 | #bannerLeft,#bannerRight { 81 | font-size: xx-large; 82 | font-weight: bold; 83 | } 84 | 85 | #bannerLeft img,#bannerRight img { 86 | margin: 0px; 87 | } 88 | 89 | #banner { 90 | height: 75px; 91 | background-color: #e2f3b8; 92 | } 93 | 94 | #banner a#bannerRight img { 95 | margin: 10px 10px 0 0 !important; 96 | } 97 | 98 | #banner a#bannerLeft img { 99 | margin: 10px 0 0 10px !important; 100 | } 101 | 102 | #legend { 103 | padding: 8px 0 8px 0; 104 | } 105 | 106 | #navcolumn { 107 | padding: 8px 4px 0 8px; 108 | } 109 | 110 | #navcolumn h5 { 111 | margin: 0; 112 | padding: 0; 113 | font-size: small; 114 | } 115 | 116 | #navcolumn ul { 117 | 118 | } 119 | 120 | #navcolumn ul li { 121 | margin: 3px 0px; 122 | padding: 3px 0 0 10px; 123 | font-size: 14px; 124 | font-weight: bold; 125 | background: url(../images/menu-title.gif) no-repeat 0% 7px; 126 | } 127 | 128 | #navcolumn ul li ul { 129 | 130 | } 131 | 132 | #navcolumn ul li ul li { 133 | margin: 0px; 134 | font-size: 13px; 135 | font-weight: normal; 136 | background: url(../images/menu-list.gif) no-repeat 0% 7px; 137 | border-bottom: 1px solid #ebebeb; 138 | } 139 | 140 | #navcolumn ul li ul li:hover { 141 | background-color: #E2F3B8; 142 | } 143 | 144 | #poweredBy { 145 | text-align: center; 146 | } 147 | 148 | #navcolumn img { 149 | margin-top: 10px; 150 | margin-bottom: 3px; 151 | } 152 | 153 | #poweredBy img { 154 | display: block; 155 | margin: 20px 0 20px 17px; 156 | border: 1px solid black; 157 | width: 90px; 158 | height: 30px; 159 | } 160 | 161 | #search img { 162 | margin: 0px; 163 | display: block; 164 | } 165 | 166 | #search #q,#search #btnG { 167 | border: 1px solid #999; 168 | margin-bottom: 10px; 169 | } 170 | 171 | #search form { 172 | margin: 0px; 173 | } 174 | 175 | #lastPublished { 176 | 177 | } 178 | 179 | #footer { 180 | padding: 10px; 181 | margin: 20px 0px 20px 0px; 182 | border-top: solid #ccc 1px; 183 | color: #333333; 184 | } 185 | 186 | #breadcrumbs { 187 | margin: 0px; 188 | padding: 1px 5px 3px 1px; 189 | overflow: hidden; 190 | background-image: url(../images/breadcrumbs.png); 191 | background-color: #ccc; 192 | background-repeat: repeat-x; 193 | border-bottom: 1px solid #aaa; 194 | } 195 | 196 | #breadcrumbs a { 197 | font-weight: bold; 198 | color: #999; 199 | text-decoration: underline; 200 | } 201 | 202 | .xleft,#bannerLeft img { 203 | float: left; 204 | text-shadow: #7CFC00; 205 | } 206 | 207 | .xright,#bannerRight img { 208 | float: right; 209 | text-shadow: #7CFC00; 210 | } 211 | 212 | .xright a:link,.xright a:visited,.xright a:active { 213 | color: #666; 214 | } 215 | 216 | .xright a:hover { 217 | color: #003300; 218 | } -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/displaytag.css: -------------------------------------------------------------------------------- 1 | table { 2 | border: 1px solid #ccc; 3 | } 4 | 5 | th,td { 6 | padding: 2px 4px 2px 4px !important; 7 | text-align: left; 8 | vertical-align: top; 9 | } 10 | 11 | thead tr { 12 | background-color: #ccc; 13 | } 14 | 15 | th.sorted { 16 | background-color: orange; 17 | } 18 | 19 | th a,th a:visited { 20 | color: black; 21 | } 22 | 23 | th a:hover { 24 | text-decoration: underline; 25 | color: black; 26 | } 27 | 28 | th.sorted a,th.sortable a { 29 | background-position: right; 30 | display: block; 31 | width: 100%; 32 | } 33 | 34 | th.sortable a { 35 | background-image: url(../img/arrow_off.png); 36 | } 37 | 38 | th.order1 a { 39 | background-image: url(../img/arrow_down.png); 40 | } 41 | 42 | th.order2 a { 43 | background-image: url(../img/arrow_up.png); 44 | } 45 | 46 | tr.odd { 47 | background-color: #fff; 48 | } 49 | 50 | tr.tableRowEven,tr.even { 51 | background-color: #eee; 52 | } 53 | 54 | div.exportlinks { 55 | background-color: #eee; 56 | border: 1px dotted #999; 57 | padding: 2px 4px 2px 4px; 58 | margin: 2px 0 10px 0; 59 | width: 79%; 60 | } 61 | 62 | span.export { 63 | padding: 0 4px 1px 20px; 64 | display: inline; 65 | display: inline-block; 66 | cursor: pointer; 67 | } 68 | 69 | span.excel { 70 | background-image: url(../img/ico_file_excel.png); 71 | } 72 | 73 | span.csv { 74 | background-image: url(../img/ico_file_csv.png); 75 | } 76 | 77 | span.xml { 78 | background-image: url(../img/ico_file_xml.png); 79 | } 80 | 81 | span.pdf { 82 | background-image: url(../img/ico_file_pdf.png); 83 | } 84 | 85 | span.rtf { 86 | background-image: url(../img/ico_file_rtf.png); 87 | } 88 | 89 | span.pagebanner { 90 | background-color: #eee; 91 | border: 1px dotted #999; 92 | padding: 2px 4px 2px 4px; 93 | width: 79%; 94 | margin-top: 10px; 95 | display: block; 96 | border-bottom: none; 97 | } 98 | 99 | span.pagelinks { 100 | background-color: #eee; 101 | border: 1px dotted #999; 102 | padding: 2px 4px 2px 4px; 103 | width: 79%; 104 | display: block; 105 | border-top: none; 106 | margin-bottom: -5px; 107 | } 108 | 109 | .group-1 { 110 | font-weight: bold; 111 | padding-bottom: 10px; 112 | border-top: 1px solid black; 113 | } 114 | 115 | .group-2 { 116 | font-style: italic; 117 | border-top: 1px solid black; 118 | } 119 | 120 | .subtotal-sum,.grandtotal-sum { 121 | font-weight: bold; 122 | text-align: right; 123 | } 124 | 125 | .subtotal-header { 126 | padding-bottom: 0px; 127 | border-top: 1px solid white; 128 | } 129 | 130 | .subtotal-label,.grandtotal-label { 131 | border-top: 1px solid white; 132 | font-weight: bold; 133 | } 134 | 135 | .grouped-table tr.even { 136 | background-color: #fff; 137 | } 138 | 139 | .grouped-table tr.odd { 140 | background-color: #fff; 141 | } 142 | 143 | .grandtotal-row { 144 | border-top: 2px solid black; 145 | } -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/popDiv.css: -------------------------------------------------------------------------------- 1 | 2 | DIV.neat-dialog-cont { 3 | Z-INDEX: 98; BACKGROUND: none transparent scroll repeat 0% 0%; LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100% 4 | } 5 | DIV.neat-dialog-bg { 6 | Z-INDEX: -1; FILTER: alpha(opacity=70); LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%; BACKGROUND-COLOR: #eee; opacity: 0.7 7 | } 8 | DIV.neat-dialog { 9 | BORDER-RIGHT: #555 1px solid; BORDER-TOP: #555 1px solid; Z-INDEX: 99; MARGIN-LEFT: auto; BORDER-LEFT: #555 1px solid; WIDTH: 50%; MARGIN-RIGHT: auto; BORDER-BOTTOM: #555 1px solid; POSITION: relative; TOP: 25%; BACKGROUND-COLOR: #fff 10 | } 11 | DIV.neat-dialog-title { 12 | PADDING-RIGHT: 0.3em; PADDING-LEFT: 0.3em; FONT-SIZE: 1.2em; 13 | PADDING-BOTTOM: 0.1em; MARGIN: 0px; LINE-HEIGHT: 1.2em; PADDING-TOP: 0.1em; BORDER-BOTTOM: #444 1px solid; 14 | POSITION: relative; 15 | background-color:#EEEEEE; 16 | } 17 | IMG.nd-cancel { 18 | RIGHT: 0.2em; POSITION: absolute; TOP: 0.2em 19 | } 20 | DIV.neat-dialog P { 21 | PADDING-RIGHT: 0.2em; PADDING-LEFT: 0.2em; PADDING-BOTTOM: 0.2em; PADDING-TOP: 0.2em; TEXT-ALIGN: center 22 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/smoothness/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/css/table.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/css/table.css -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/addOps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/addOps.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/addPermission.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/addPermission.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/authorise_process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/authorise_process.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/breadcrumbs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/breadcrumbs.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/list.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/menu-list.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/menu-list.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/menu-title.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/menu-title.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/images/users.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/images/users.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/arrow_down.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/arrow_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/arrow_off.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/arrow_up.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/bg.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/calendar/calendar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/calendar/calendar.jpg -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/calendar/next.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/calendar/next.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/calendar/prev.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/calendar/prev.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/displaytag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/displaytag.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/error.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/error.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/external.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/external.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/favicon.ico -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/help.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/help.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/hi.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/hi.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ico_file_csv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ico_file_csv.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ico_file_excel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ico_file_excel.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ico_file_pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ico_file_pdf.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ico_file_rtf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ico_file_rtf.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ico_file_xml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ico_file_xml.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/lock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/lock.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/login_btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/login_btn.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/logo.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ops-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ops-list.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ops-security.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ops-security.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/paginazione.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/paginazione.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/paginazione_ahead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/paginazione_ahead.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/paginazione_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/paginazione_back.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/psd/taokeeper-logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/psd/taokeeper-logo.psd -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/report/dragIcon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/report/dragIcon.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/report/dragIconH.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/report/dragIconH.gif -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/report/lens.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/report/lens.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/ribbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/ribbon.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/seeDetail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/seeDetail.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/taokeeper-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/taokeeper-logo.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/text_field.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/text_field.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/valid-xhtml10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/valid-xhtml10.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/img/viewsource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/img/viewsource.png -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ include file="/WEB-INF/common/taglibs.jsp"%> 2 | -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/js/popDiv.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyunabc/taokeeper/1cda4eb1ca7f1de2a981f7f204b094e8fdca562f/taokeeper-monitor/src/main/webapp/js/popDiv.js -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/js/table.js: -------------------------------------------------------------------------------- 1 | var Ptr = document.getElementById("tab").getElementsByTagName("tr"); 2 | function $() { 3 | for ( var i = 1; i < Ptr.length + 1; i++) { 4 | Ptr[i - 1].className = (i % 2 > 0) ? "t1" : "t2"; 5 | } 6 | } 7 | window.onload = $; 8 | for ( var i = 0; i < Ptr.length; i++) { 9 | Ptr[i].onmouseover = function() { 10 | this.tmpClass = this.className; 11 | this.className = "t3"; 12 | }; 13 | Ptr[i].onmouseout = function() { 14 | this.className = this.tmpClass; 15 | }; 16 | } -------------------------------------------------------------------------------- /taokeeper-monitor/src/main/webapp/ruok.htm: -------------------------------------------------------------------------------- 1 | IMOK -------------------------------------------------------------------------------- /taokeeper-reporter/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /taokeeper-reporter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.taobao.taokeeper 7 | taokeeper 8 | 1.1.2 9 | 10 | 11 | taokeeper-reporter 12 | taokeeper-reporter 13 | jar 14 | 15 | 16 | 17 | 18 | com.taobao.taokeeper 19 | taokeeper-common 20 | ${taokeeper.version} 21 | 22 | 23 | commons-httpclient 24 | commons-httpclient 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /taokeeper-reporter/src/main/java/com/taobao/taokeeper/reporter/alarm/MessageSender.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.reporter.alarm; 2 | 3 | 4 | /** 5 | * Description: 发送消息的接口 6 | * 7 | * @author 银时 yinshi.nc@taobao.com 8 | * @Date Dec 26, 2011 9 | */ 10 | public interface MessageSender extends Runnable { 11 | } 12 | -------------------------------------------------------------------------------- /taokeeper-reporter/src/main/java/com/taobao/taokeeper/reporter/alarm/TbMessageSender.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.reporter.alarm; 2 | 3 | import static common.toolkit.java.constant.SymbolConstant.COMMA; 4 | 5 | import java.net.URLEncoder; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import com.taobao.taokeeper.common.constant.SystemConstant; 14 | import com.taobao.taokeeper.model.type.Message; 15 | import common.toolkit.java.entity.Message.MessageType; 16 | import common.toolkit.java.util.StringUtil; 17 | import common.toolkit.java.util.collection.ListUtil; 18 | import common.toolkit.java.util.io.NetUtil; 19 | 20 | /** 21 | * Description: 淘宝内部使用:旺旺消息与手机短信 22 | * 23 | * @author 银时 yinshi.nc@taobao.com 24 | * @Date Dec 26, 2011 25 | */ 26 | public class TbMessageSender implements MessageSender { 27 | 28 | private static final Logger LOG = LoggerFactory.getLogger( TbMessageSender.class ); 29 | 30 | private Message[] messages; 31 | 32 | public TbMessageSender( Message... messages ) { 33 | this.messages = messages; 34 | } 35 | 36 | @Override 37 | public void run() { 38 | 39 | if ( null == messages || 0 == messages.length || StringUtil.isBlank( SystemConstant.IP_OF_MESSAGE_SEND ) ){ 40 | LOG.info( "[TaoKeeper]No need to send message: messages.length: " + messages + ", IP_OF_MESSAGE_SEND=" + SystemConstant.IP_OF_MESSAGE_SEND ); 41 | return; 42 | } 43 | 44 | for ( Message message : this.messages ) { 45 | try { 46 | this.sendMessage( StringUtil.trimToEmpty( message.getTargetAddresses() ), StringUtil.trimToEmpty( message.getSubject() ), 47 | StringUtil.trimToEmpty( message.getContent() ), StringUtil.trimToEmpty( message.getType().toString() ) ); 48 | LOG.info( "[TaoKeeper]Message send success: " + message ); 49 | } catch ( Exception e ) { 50 | e.printStackTrace(); 51 | LOG.error( "Message send error: " + message + e.getMessage() ); 52 | } 53 | } 54 | 55 | } 56 | 57 | /** 58 | * 发送消息 59 | * 60 | * @param targetAddresses 61 | * @param subject 62 | * @param content 63 | * message content 64 | * @param channel 65 | * messate tyep:sms,email,wangwang 66 | * @return 67 | * @throws Exception 68 | */ 69 | private boolean sendMessage( String targetAddresses, String subject, String content, String channel ) throws Exception { 70 | 71 | if ( StringUtil.isBlank( targetAddresses ) || StringUtil.isBlank( channel ) ) 72 | return false; 73 | 74 | 75 | List targetAddressList = ListUtil.parseList( StringUtil.trimToEmpty( targetAddresses ), COMMA ); 76 | 77 | Map map = new HashMap(); 78 | map.put( "ip", SystemConstant.IP_OF_MESSAGE_SEND ); 79 | map.put( "subject", URLEncoder.encode( subject, "UTF-8" ) ); 80 | map.put( "content", URLEncoder.encode( content, "UTF-8" ) ); 81 | String url = ""; 82 | if ( channel.equalsIgnoreCase( MessageType.WANGWANG.toString() ) ) { 83 | 84 | for ( String targetAddress : targetAddressList ) { 85 | 86 | map.put( "messageType", "sendWangWangMessage" ); 87 | map.put( "targetAddress", URLEncoder.encode( targetAddress,"UTF-8" ) ); 88 | url = StringUtil.replacePlaceholder( SystemConstant.URL_TEMPLEMENT_OF_MESSAG_SEND, map ); 89 | } 90 | } else if ( channel.equalsIgnoreCase( MessageType.SMS.toString() ) ) { 91 | 92 | for ( String targetAddress : targetAddressList ) { 93 | map.put( "messageType", "sendWangWangMessage" ); 94 | map.put( "targetAddress", URLEncoder.encode( targetAddress, "UTF-8" ) ); 95 | url = StringUtil.replacePlaceholder( SystemConstant.URL_TEMPLEMENT_OF_MESSAG_SEND, map ); 96 | } 97 | } 98 | return "ok".equalsIgnoreCase( NetUtil.getContentOfUrl( url ) ); 99 | 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /taokeeper-research/eclipse.cmd: -------------------------------------------------------------------------------- 1 | call mvn clean -U eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=false -Declipse.addVersionToProjectName=true 2 | @pause 3 | -------------------------------------------------------------------------------- /taokeeper-research/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | com.taobao.taokeeper 5 | taokeeper 6 | 1.1.2 7 | 8 | 9 | 4.0.0 10 | taokeeper-research 11 | taokeeper-research 12 | jar 13 | 14 | 15 | UTF-8 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-shade-plugin 23 | 1.5 24 | 25 | 26 | package 27 | 28 | shade 29 | 30 | 31 | 32 | 33 | com.taobao.taokeeper.research.test.performance.session.SessionPressTest 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-compiler-plugin 43 | 44 | 1.6 45 | 1.6 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | com.taobao.taokeeper 54 | taokeeper-common 55 | ${taokeeper.version} 56 | 57 | 58 | 59 | 60 | commons-logging 61 | commons-logging 62 | 1.1.1 63 | 64 | 65 | log4j 66 | log4j 67 | 1.2.16 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/NodeSizeLimit.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research; 2 | /** 3 | * 主要是为了测试ZK的节点大小限制以及如何修改节点大小限制 4 | * @author nileader/nileader@gmail.com 5 | */ 6 | public class NodeSizeLimit { 7 | 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/sample/JavaApiSample.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.sample; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.CountDownLatch; 5 | 6 | import org.apache.zookeeper.CreateMode; 7 | import org.apache.zookeeper.KeeperException; 8 | import org.apache.zookeeper.WatchedEvent; 9 | import org.apache.zookeeper.Watcher; 10 | import org.apache.zookeeper.Watcher.Event.KeeperState; 11 | import org.apache.zookeeper.ZooDefs.Ids; 12 | import org.apache.zookeeper.ZooKeeper; 13 | 14 | import common.toolkit.java.util.ObjectUtil; 15 | 16 | /** 17 | * ZooKeeper Java Api 使用样例
18 | * ZK Api Version: 3.4.3 19 | * 20 | * @author nileader/nileader@gmail.com 21 | */ 22 | public class JavaApiSample implements Watcher { 23 | 24 | private static final int SESSION_TIMEOUT = 10000; 25 | private static final String CONNECTION_STRING = "test.zookeeper.connection_string:2181"; 26 | private static final String ZK_PATH = "/nileader"; 27 | private ZooKeeper zk = null; 28 | 29 | private CountDownLatch connectedSemaphore = new CountDownLatch( 1 ); 30 | 31 | /** 32 | * 创建ZK连接 33 | * @param connectString ZK服务器地址列表 34 | * @param sessionTimeout Session超时时间 35 | */ 36 | public void createConnection( String connectString, int sessionTimeout ) { 37 | this.releaseConnection(); 38 | try { 39 | zk = new ZooKeeper( connectString, sessionTimeout, this ); 40 | connectedSemaphore.await(); 41 | } catch ( InterruptedException e ) { 42 | System.out.println( "连接创建失败,发生 InterruptedException" ); 43 | e.printStackTrace(); 44 | } catch ( IOException e ) { 45 | System.out.println( "连接创建失败,发生 IOException" ); 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | /** 51 | * 关闭ZK连接 52 | */ 53 | public void releaseConnection() { 54 | if ( !ObjectUtil.isBlank( this.zk ) ) { 55 | try { 56 | this.zk.close(); 57 | } catch ( InterruptedException e ) { 58 | // ignore 59 | e.printStackTrace(); 60 | } 61 | } 62 | } 63 | 64 | /** 65 | * 创建节点 66 | * @param path 节点path 67 | * @param data 初始数据内容 68 | * @return 69 | */ 70 | public boolean createPath( String path, String data ) { 71 | try { 72 | System.out.println( "节点创建成功, Path: " 73 | + this.zk.create( path, // 74 | data.getBytes(), // 75 | Ids.OPEN_ACL_UNSAFE, // 76 | CreateMode.EPHEMERAL ) 77 | + ", content: " + data ); 78 | } catch ( KeeperException e ) { 79 | System.out.println( "节点创建失败,发生KeeperException" ); 80 | e.printStackTrace(); 81 | } catch ( InterruptedException e ) { 82 | System.out.println( "节点创建失败,发生 InterruptedException" ); 83 | e.printStackTrace(); 84 | } 85 | return true; 86 | } 87 | 88 | /** 89 | * 读取指定节点数据内容 90 | * @param path 节点path 91 | * @return 92 | */ 93 | public String readData( String path ) { 94 | try { 95 | System.out.println( "获取数据成功,path:" + path ); 96 | return new String( this.zk.getData( path, false, null ) ); 97 | } catch ( KeeperException e ) { 98 | System.out.println( "读取数据失败,发生KeeperException,path: " + path ); 99 | e.printStackTrace(); 100 | return ""; 101 | } catch ( InterruptedException e ) { 102 | System.out.println( "读取数据失败,发生 InterruptedException,path: " + path ); 103 | e.printStackTrace(); 104 | return ""; 105 | } 106 | } 107 | 108 | /** 109 | * 更新指定节点数据内容 110 | * @param path 节点path 111 | * @param data 数据内容 112 | * @return 113 | */ 114 | public boolean writeData( String path, String data ) { 115 | try { 116 | System.out.println( "更新数据成功,path:" + path + ", stat: " + 117 | this.zk.setData( path, data.getBytes(), -1 ) ); 118 | } catch ( KeeperException e ) { 119 | System.out.println( "更新数据失败,发生KeeperException,path: " + path ); 120 | e.printStackTrace(); 121 | } catch ( InterruptedException e ) { 122 | System.out.println( "更新数据失败,发生 InterruptedException,path: " + path ); 123 | e.printStackTrace(); 124 | } 125 | return false; 126 | } 127 | 128 | /** 129 | * 删除指定节点 130 | * @param path 节点path 131 | */ 132 | public void deleteNode( String path ) { 133 | try { 134 | this.zk.delete( path, -1 ); 135 | System.out.println( "删除节点成功,path:" + path ); 136 | } catch ( KeeperException e ) { 137 | System.out.println( "删除节点失败,发生KeeperException,path: " + path ); 138 | e.printStackTrace(); 139 | } catch ( InterruptedException e ) { 140 | System.out.println( "删除节点失败,发生 InterruptedException,path: " + path ); 141 | e.printStackTrace(); 142 | } 143 | } 144 | 145 | public static void main( String[] args ) { 146 | 147 | JavaApiSample sample = new JavaApiSample(); 148 | sample.createConnection( CONNECTION_STRING, SESSION_TIMEOUT ); 149 | if ( sample.createPath( ZK_PATH, "我是节点初始内容" ) ) { 150 | System.out.println(); 151 | System.out.println( "数据内容: " + sample.readData( ZK_PATH ) + "\n" ); 152 | sample.writeData( ZK_PATH, "更新后的数据" ); 153 | System.out.println( "数据内容: " + sample.readData( ZK_PATH ) + "\n" ); 154 | sample.deleteNode( ZK_PATH ); 155 | } 156 | 157 | sample.releaseConnection(); 158 | } 159 | 160 | /** 161 | * 收到来自Server的Watcher通知后的处理。 162 | */ 163 | @Override 164 | public void process( WatchedEvent event ) { 165 | System.out.println( "收到事件通知:" + event.getState() +"\n" ); 166 | if ( KeeperState.SyncConnected == event.getState() ) { 167 | connectedSemaphore.countDown(); 168 | } 169 | 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/onlygetdata/PressDataGet.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.onlygetdata; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | import java.util.concurrent.atomic.AtomicLong; 10 | 11 | import org.apache.commons.logging.Log; 12 | import org.apache.commons.logging.LogFactory; 13 | import org.apache.zookeeper.CreateMode; 14 | import org.apache.zookeeper.KeeperException; 15 | import org.apache.zookeeper.WatchedEvent; 16 | import org.apache.zookeeper.Watcher; 17 | import org.apache.zookeeper.ZooDefs.Ids; 18 | import org.apache.zookeeper.ZooKeeper.States; 19 | import org.apache.zookeeper.ZooKeeper; 20 | 21 | import common.toolkit.java.constant.EmptyObjectConstant; 22 | import common.toolkit.java.util.StatisticsUtil; 23 | import common.toolkit.java.util.StringUtil; 24 | import common.toolkit.java.util.system.SystemUtil; 25 | 26 | /** 27 | * 类说明: 进行获取数据压力测试 28 | * 29 | * @author yinshi.nc 30 | */ 31 | public class PressDataGet implements Watcher { 32 | 33 | static Log log = LogFactory.getLog( PressDataGet.class ); 34 | 35 | static ZooKeeper zk = null; 36 | 37 | static String PATH = "/YINSHI.NC-PRESS-TEST"; 38 | static String SERVER_LIST = "10.13.44.47:2181"; 39 | final static int SESSION_TIMEOUT = 5000; 40 | static int TOTAL_SUBS = 6; 41 | static int N_BYTE = 1; // 1字节的倍数 42 | 43 | static AtomicLong failTimes = new AtomicLong(); 44 | 45 | /** 重连成功次数,这个表示这个session过期或断开后,重新建立连接并且成功的次数 */ 46 | static AtomicLong reConnectSuccessTimes = new AtomicLong(); 47 | /** 重连失败次数,这个表示这个session过期或断开后,重新建立连接,但是失败的次数 */ 48 | static AtomicLong reConnectFailTimes = new AtomicLong(); 49 | 50 | static List pubList = new ArrayList(); 51 | static Set pathList = new HashSet(); 52 | 53 | // 已完成任务的订阅者数量 54 | static AtomicInteger finshedSub = new AtomicInteger(); 55 | 56 | public static void main( String[] args ) throws IOException, KeeperException, InterruptedException { 57 | 58 | log.info( "全读压测程序开始" ); 59 | 60 | if ( args.length != 3 ) { 61 | throw new IllegalArgumentException( "请指定:zk服务器列表,订阅者数量, 数据大小(这里填写一个数字,表明是1字节的倍数),如1024,那么表示数据大小是1K" ); 62 | } 63 | PressDataGet.SERVER_LIST = StringUtil.defaultIfBlank( args[0], SERVER_LIST ); 64 | PressDataGet.TOTAL_SUBS = Integer.parseInt( StringUtil.defaultIfBlank( args[1], TOTAL_SUBS + EmptyObjectConstant.EMPTY_STRING ) ); 65 | PressDataGet.PATH += "-" 66 | + StringUtil.defaultIfBlank( SystemUtil.getHostName(), System.currentTimeMillis() + EmptyObjectConstant.EMPTY_STRING ); 67 | PressDataGet.N_BYTE = Integer.parseInt( StringUtil.defaultIfBlank( args[2], N_BYTE + EmptyObjectConstant.EMPTY_STRING ) ); 68 | 69 | try { 70 | // 准备订阅者 71 | for ( int i = 0; i < TOTAL_SUBS; i++ ) { 72 | String path = PATH + "-" + i; 73 | pubList.add( new Subscriber( SERVER_LIST, SESSION_TIMEOUT, path ) ); 74 | pathList.add( path ); 75 | } 76 | // 准备Path,并发布初始数据 77 | PressDataGet press = new PressDataGet(); 78 | if ( press.createAndInitPaths() ) { 79 | // 启动统计程序 80 | StatisticsUtil.start( 10 ); 81 | for ( Subscriber subscriber : pubList ) { 82 | subscriber.start(); 83 | } 84 | } 85 | } finally { 86 | while ( finshedSub.get() < TOTAL_SUBS ) { 87 | log.error( "错误次数: " + PressDataGet.failTimes ); 88 | log.warn( "重连成功次数:" + PressDataGet.reConnectSuccessTimes ); 89 | log.warn( "重连失败次数:" + PressDataGet.reConnectFailTimes ); 90 | Thread.sleep( 10000 ); 91 | } 92 | finalDeleteNode(); 93 | StatisticsUtil.stop(); 94 | } 95 | } 96 | 97 | boolean createAndInitPaths() { 98 | 99 | try { 100 | zk = new ZooKeeper( SERVER_LIST, SESSION_TIMEOUT, this ); 101 | log.info( "需要创建的PATH数是:" + pathList.size() ); 102 | log.info( "等待path创建" ); 103 | while ( null != zk && States.CONNECTED != zk.getState() ) { 104 | try { 105 | Thread.sleep( 20 ); 106 | } catch ( Throwable t ) { 107 | t.printStackTrace(); 108 | } 109 | } 110 | for ( String path : pathList ) { 111 | if( null != zk.exists( path, false ) ){ 112 | zk.delete( path, -1 ); 113 | } 114 | zk.create( path, EmptyObjectConstant.EMPTY_STRING.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL ); 115 | log.info( "Create path: " + path ); 116 | Thread.sleep( 20 ); 117 | zk.setData( path, new byte[N_BYTE * 1], -1 ); 118 | } 119 | log.info( "PATH创建完毕" ); 120 | return true; 121 | } catch ( Exception e ) { 122 | e.printStackTrace(); 123 | return false; 124 | } 125 | 126 | } 127 | 128 | /** 129 | * 删除节点 130 | */ 131 | static void finalDeleteNode() { 132 | 133 | try { 134 | ZooKeeper zk = new ZooKeeper( SERVER_LIST, SESSION_TIMEOUT, null ); 135 | for ( String path : pathList ) { 136 | try { 137 | int version = zk.exists( path, null ).getVersion(); 138 | zk.delete( path, version ); 139 | } catch ( Exception e ) { 140 | } 141 | } 142 | } catch ( Exception e ) { 143 | e.printStackTrace(); 144 | } 145 | 146 | } 147 | 148 | @Override 149 | public void process( WatchedEvent event ) { 150 | // TODO Auto-generated method stub 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/onlygetdata/Subscriber.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.onlygetdata; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.zookeeper.KeeperException; 8 | import org.apache.zookeeper.KeeperException.Code; 9 | import org.apache.zookeeper.WatchedEvent; 10 | import org.apache.zookeeper.Watcher; 11 | import org.apache.zookeeper.ZooKeeper; 12 | import org.apache.zookeeper.data.Stat; 13 | 14 | import common.toolkit.java.util.StatisticsUtil; 15 | import common.toolkit.java.util.ThreadUtil; 16 | 17 | /** 18 | * 数据订阅者 19 | * @author yinshi.nc 20 | * @since 2011-11-22 21 | */ 22 | public class Subscriber implements Watcher { 23 | 24 | private static Log log = LogFactory.getLog( Subscriber.class ); 25 | 26 | ZooKeeper zk = null; 27 | private String path; 28 | private String serverList; 29 | private int sessionTimeout; 30 | private boolean isFinish = false; 31 | 32 | /** 33 | * @param path znode的path 34 | * @param getTimes 获取数据次数 35 | * @throws IOException 36 | * @throws InterruptedException 37 | */ 38 | public Subscriber( String serverList, int sessionTimeout, String path ){ 39 | this.serverList = serverList; 40 | this.sessionTimeout = sessionTimeout; 41 | this.path = path; 42 | this.createZk(); 43 | } 44 | 45 | private boolean createZk(){ 46 | if( null != this.zk ){ 47 | try { 48 | this.zk.close(); 49 | } catch ( InterruptedException e ) { 50 | //ignore 51 | } 52 | this.zk = null; 53 | } 54 | try { 55 | this.zk = new ZooKeeper( this.serverList, this.sessionTimeout, this ); 56 | return true; 57 | } catch ( IOException e ) { 58 | return false; 59 | } 60 | } 61 | 62 | public void start() { 63 | if( null == this.zk ) 64 | return; 65 | ThreadUtil.startThread( new Runnable() { 66 | @Override 67 | public void run() { 68 | // 获取数据 69 | while ( !isFinish ) { 70 | try { 71 | zk.getData( path, false, new Stat() ); 72 | StatisticsUtil.totalTransactions.incrementAndGet(); 73 | }catch(KeeperException keeperException ){ 74 | //如果过期,那么要重新连接一个了。 75 | keeperException.code().equals( Code.SESSIONEXPIRED ); 76 | if( createZk() ) { 77 | PressDataGet.reConnectSuccessTimes.incrementAndGet(); 78 | }else{ 79 | PressDataGet.reConnectFailTimes.incrementAndGet(); 80 | } 81 | }catch ( Exception e ) { 82 | PressDataGet.failTimes.incrementAndGet(); 83 | log.error( "Fail get data: " + e.getMessage() ); 84 | } 85 | } 86 | PressDataGet.finshedSub.incrementAndGet(); 87 | } 88 | } ); 89 | } 90 | 91 | @Override 92 | public void process( WatchedEvent event ) { 93 | // Do nothing 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/onlysetdata/PressDataSet.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.onlysetdata; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.concurrent.atomic.AtomicLong; 9 | 10 | import org.apache.commons.logging.Log; 11 | import org.apache.commons.logging.LogFactory; 12 | import org.apache.zookeeper.CreateMode; 13 | import org.apache.zookeeper.KeeperException; 14 | import org.apache.zookeeper.WatchedEvent; 15 | import org.apache.zookeeper.Watcher; 16 | import org.apache.zookeeper.ZooDefs.Ids; 17 | import org.apache.zookeeper.ZooKeeper; 18 | import org.apache.zookeeper.ZooKeeper.States; 19 | 20 | import common.toolkit.java.constant.EmptyObjectConstant; 21 | import common.toolkit.java.util.StatisticsUtil; 22 | import common.toolkit.java.util.StringUtil; 23 | import common.toolkit.java.util.system.SystemUtil; 24 | 25 | /** 26 | * ZOOKEEPER压测:进行写入数据压力测试 27 | * 28 | * @author yinshi.nc 29 | */ 30 | public class PressDataSet implements Watcher { 31 | 32 | static Log log = LogFactory.getLog( PressDataSet.class ); 33 | 34 | static String PATH = "/YINSHI.NC-PRESS-TEST"; 35 | static String SERVER_LIST = "10.13.44.47:2181"; 36 | final static int SESSION_TIMEOUT = 5000; 37 | static int TOTAL_PUBS = 6; 38 | static int N_BYTE = 1; 39 | static boolean isFinish = false; 40 | 41 | static ZooKeeper zk = null; 42 | 43 | static AtomicLong failTimes = new AtomicLong(); 44 | 45 | /** 重连成功次数,这个表示这个session过期或断开后,重新建立连接并且成功的次数 */ 46 | static AtomicLong reConnectSuccessTimes = new AtomicLong(); 47 | /** 重连失败次数,这个表示这个session过期或断开后,重新建立连接,但是失败的次数 */ 48 | static AtomicLong reConnectFailTimes = new AtomicLong(); 49 | 50 | static List pubList = new ArrayList(); 51 | static Set pathList = new HashSet(); 52 | 53 | public static void main( String[] args ) throws IOException, KeeperException, InterruptedException { 54 | 55 | log.info( "全写压测程序开始" ); 56 | 57 | if ( args.length != 3 ) { 58 | throw new IllegalArgumentException( "请指定:zk服务器列表,发布者数量, 数据大小(这里填写一个数字,表明是1字节的倍数),如1024,那么表示数据大小是1K" ); 59 | } 60 | PressDataSet.SERVER_LIST = StringUtil.defaultIfBlank( args[0], SERVER_LIST ); 61 | PressDataSet.TOTAL_PUBS = Integer.parseInt( StringUtil.defaultIfBlank( args[1], TOTAL_PUBS + EmptyObjectConstant.EMPTY_STRING ) ); 62 | PressDataSet.PATH += "-" 63 | + StringUtil.defaultIfBlank( SystemUtil.getHostName(), System.currentTimeMillis() + EmptyObjectConstant.EMPTY_STRING ); 64 | PressDataSet.N_BYTE = Integer.parseInt( StringUtil.defaultIfBlank( args[2], N_BYTE + EmptyObjectConstant.EMPTY_STRING ) ); 65 | 66 | try { 67 | // 准备发布者 68 | for ( int i = 0; i < TOTAL_PUBS; i++ ) { 69 | String path = PATH + "-" + i; 70 | pubList.add( new Publisher( SERVER_LIST, SESSION_TIMEOUT, path, N_BYTE ) ); 71 | pathList.add( path ); 72 | } 73 | PressDataSet press = new PressDataSet(); 74 | if ( press.createAndInitPaths() ) { 75 | // 启动统计程序 76 | StatisticsUtil.start( 20 ); 77 | for ( Publisher publisher : pubList ) { 78 | publisher.start(); 79 | } 80 | } 81 | } finally { 82 | while ( !isFinish ) { 83 | log.error( "错误次数: " + PressDataSet.failTimes ); 84 | log.warn( "重连成功次数:" + PressDataSet.reConnectSuccessTimes ); 85 | log.warn( "重连失败次数:" + PressDataSet.reConnectFailTimes ); 86 | Thread.sleep( 10000 ); 87 | } 88 | StatisticsUtil.stop(); 89 | closeZk( zk ); 90 | } 91 | } 92 | 93 | boolean createAndInitPaths() { 94 | 95 | try { 96 | zk = new ZooKeeper( SERVER_LIST, SESSION_TIMEOUT, this ); 97 | log.info( "需要创建的PATH数是:" + pathList.size() ); 98 | log.info( "等待path创建" ); 99 | while ( null != zk && States.CONNECTED != zk.getState() ) { 100 | try { 101 | Thread.sleep( 20 ); 102 | } catch ( Throwable t ) { 103 | t.printStackTrace(); 104 | } 105 | } 106 | for ( String path : pathList ) { 107 | if ( null != zk.exists( path, false ) ) { 108 | zk.delete( path, -1 ); 109 | } 110 | zk.create( path, EmptyObjectConstant.EMPTY_STRING.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL ); 111 | log.info( "Create path: " + path ); 112 | Thread.sleep( 20 ); 113 | zk.setData( path, new byte[N_BYTE * 1], -1 ); 114 | } 115 | log.info( "PATH创建完毕" ); 116 | return true; 117 | } catch ( Exception e ) { 118 | e.printStackTrace(); 119 | return false; 120 | } 121 | 122 | } 123 | 124 | static void closeZk( ZooKeeper zk ) { 125 | if ( null != zk ) { 126 | try { 127 | zk.close(); 128 | } catch ( InterruptedException e ) { 129 | }finally{ 130 | zk = null; 131 | } 132 | } 133 | } 134 | 135 | @Override 136 | public void process( WatchedEvent event ) { 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/onlysetdata/Publisher.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.onlysetdata; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.zookeeper.KeeperException; 8 | import org.apache.zookeeper.KeeperException.Code; 9 | import org.apache.zookeeper.WatchedEvent; 10 | import org.apache.zookeeper.Watcher; 11 | import org.apache.zookeeper.ZooKeeper; 12 | import org.apache.zookeeper.ZooKeeper.States; 13 | 14 | import common.toolkit.java.util.StatisticsUtil; 15 | import common.toolkit.java.util.ThreadUtil; 16 | 17 | /** 18 | * ��ݷ����� 19 | * @author yinshi.nc 20 | * @Date 2011-11-10 21 | */ 22 | public class Publisher implements Watcher { 23 | 24 | protected static Log log = LogFactory.getLog( Publisher.class ); 25 | 26 | protected ZooKeeper zk = null; 27 | protected String path; 28 | protected String serverList; 29 | protected int sessionTimeout; 30 | protected int bytes = 256; 31 | 32 | public Publisher(String serverList, int sessionTimeout, String path, int bytes) throws IOException { 33 | this.serverList = serverList; 34 | this.sessionTimeout = sessionTimeout; 35 | this.path = path; 36 | this.bytes = bytes; 37 | this.createZk(); 38 | } 39 | 40 | protected void createZk() throws IOException{ 41 | PressDataSet.closeZk( this.zk ); 42 | this.zk = new ZooKeeper( this.serverList, this.sessionTimeout, this ); 43 | 44 | } 45 | 46 | public void start() { 47 | if( null == this.zk ) 48 | return; 49 | ThreadUtil.startThread( new Runnable() { 50 | @Override 51 | public void run() { 52 | //������� 53 | while ( !PressDataSet.isFinish ) { 54 | try { 55 | while( zk != null && States.CONNECTING == zk.getState() ){ 56 | Thread.sleep( 20 ); 57 | } 58 | zk.setData( path, new byte[bytes], -1 ); 59 | StatisticsUtil.totalTransactions.incrementAndGet(); 60 | } catch(KeeperException keeperException ){ 61 | //�����ڣ���ôҪ��������һ���ˡ� 62 | keeperException.code().equals( Code.SESSIONEXPIRED ); 63 | try{ 64 | createZk(); 65 | PressDataSet.reConnectSuccessTimes.incrementAndGet(); 66 | }catch( Exception e){ 67 | PressDataSet.reConnectFailTimes.incrementAndGet(); 68 | e.printStackTrace(); 69 | } 70 | }catch ( Exception e ) { 71 | PressDataSet.failTimes.incrementAndGet(); 72 | log.error( "fail set data: " + e.getMessage() ); 73 | e.printStackTrace(); 74 | } 75 | } 76 | } 77 | } ); 78 | 79 | } 80 | 81 | @Override 82 | public void process( WatchedEvent event ) {} 83 | 84 | } 85 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/session/SessionCreator.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.session; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.zookeeper.WatchedEvent; 6 | import org.apache.zookeeper.Watcher; 7 | import org.apache.zookeeper.ZooKeeper; 8 | import org.apache.zookeeper.ZooKeeper.States; 9 | 10 | import common.toolkit.java.util.StatisticsUtil; 11 | import common.toolkit.java.util.ThreadUtil; 12 | 13 | /** 14 | * Session Creator 15 | * 16 | * @author yinshi.nc 17 | * @Date 2011-11-10 18 | */ 19 | public class SessionCreator implements Watcher { 20 | 21 | private String serverList; 22 | private int sessionTimeout; 23 | 24 | public SessionCreator( String serverList, int sessionTimeout ) throws IOException { 25 | this.serverList = serverList; 26 | this.sessionTimeout = sessionTimeout; 27 | } 28 | 29 | private boolean createSessionAndClose() { 30 | ZooKeeper zk = null; 31 | try { 32 | zk = new ZooKeeper( this.serverList, this.sessionTimeout, this ); 33 | while( null != zk && States.CONNECTING == zk.getState() ){ 34 | try { 35 | Thread.sleep( 20 ); 36 | } catch ( InterruptedException e ) {} 37 | } 38 | return true; 39 | } catch ( Throwable e ) { 40 | return false; 41 | }finally{ 42 | closeSession( zk ); 43 | } 44 | } 45 | 46 | 47 | private boolean closeSession( ZooKeeper zk ){ 48 | if ( null != zk ) { 49 | try { 50 | zk.close(); 51 | } catch ( Throwable e ) {} 52 | } 53 | return true; 54 | } 55 | 56 | 57 | public void start() { 58 | ThreadUtil.startThread( new Runnable() { 59 | @Override 60 | public void run() { 61 | while ( true ) { 62 | if( createSessionAndClose() ){ 63 | StatisticsUtil.totalTransactions.incrementAndGet(); 64 | }else{ 65 | SessionPressTest.failTimes.incrementAndGet(); 66 | } 67 | } 68 | } 69 | } ); 70 | 71 | } 72 | 73 | @Override 74 | public void process( WatchedEvent event ) {} 75 | 76 | } 77 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/session/SessionPressTest.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.session; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | import org.apache.zookeeper.KeeperException; 11 | import org.apache.zookeeper.WatchedEvent; 12 | import org.apache.zookeeper.Watcher; 13 | 14 | import common.toolkit.java.constant.EmptyObjectConstant; 15 | import common.toolkit.java.util.StatisticsUtil; 16 | import common.toolkit.java.util.StringUtil; 17 | 18 | /** 19 | * Session established and release 20 | * @author 银时 21 | */ 22 | public class SessionPressTest implements Watcher { 23 | 24 | static Log log = LogFactory.getLog( SessionPressTest.class ); 25 | 26 | static String SERVER_LIST = "10.232.19.92:2181"; 27 | final static int SESSION_TIMEOUT = 5000; 28 | static int SESSIONCREATORS = 10; 29 | 30 | static AtomicLong failTimes = new AtomicLong(); 31 | 32 | static List< SessionCreator > sessionCreatorList = new ArrayList< SessionCreator >(); 33 | 34 | static boolean isWork = true; 35 | 36 | 37 | public static void main( String[] args ) throws IOException, KeeperException, InterruptedException { 38 | 39 | if ( args.length != 2 ) { 40 | throw new IllegalArgumentException( "Argument must contain serverList and sessinoNums" ); 41 | } 42 | SessionPressTest.SERVER_LIST = StringUtil.defaultIfBlank( args[0], SERVER_LIST ); 43 | SessionPressTest.SESSIONCREATORS = Integer.parseInt( StringUtil.defaultIfBlank( args[1], SESSIONCREATORS + EmptyObjectConstant.EMPTY_STRING ) ); 44 | 45 | try { 46 | // Prepare SessionCreator 47 | for ( int i = 0; i < SESSIONCREATORS; i++ ) { 48 | sessionCreatorList.add( new SessionCreator( SERVER_LIST, SESSION_TIMEOUT ) ); 49 | } 50 | StatisticsUtil.start( 20 ); 51 | for ( SessionCreator sessionCreator : sessionCreatorList ) { 52 | sessionCreator.start(); 53 | } 54 | } finally { 55 | while ( isWork ) { 56 | log.error( "Error times: " + SessionPressTest.failTimes ); 57 | Thread.sleep( 10000 ); 58 | } 59 | StatisticsUtil.stop(); 60 | } 61 | } 62 | 63 | @Override 64 | public void process( WatchedEvent event ) { 65 | // TODO Auto-generated method stub 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/setdataandwatcher/PressDataSetAndWatcher.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.setdataandwatcher; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.concurrent.atomic.AtomicLong; 9 | 10 | import org.apache.commons.logging.Log; 11 | import org.apache.commons.logging.LogFactory; 12 | import org.apache.zookeeper.CreateMode; 13 | import org.apache.zookeeper.KeeperException; 14 | import org.apache.zookeeper.WatchedEvent; 15 | import org.apache.zookeeper.Watcher; 16 | import org.apache.zookeeper.ZooDefs.Ids; 17 | import org.apache.zookeeper.ZooKeeper.States; 18 | import org.apache.zookeeper.ZooKeeper; 19 | 20 | import common.toolkit.java.constant.EmptyObjectConstant; 21 | import common.toolkit.java.util.StatisticsUtil; 22 | import common.toolkit.java.util.StringUtil; 23 | import common.toolkit.java.util.system.SystemUtil; 24 | 25 | /** 26 | * ��˵��: ���з������ѹ������ 27 | * 28 | * @author yinshi.nc 29 | */ 30 | public class PressDataSetAndWatcher implements Watcher { 31 | 32 | static Log log = LogFactory.getLog( PressDataSetAndWatcher.class ); 33 | 34 | static String PATH = "/YINSHI.NC-PRESS-TEST"; 35 | static String SERVER_LIST = "10.13.44.47:2181"; 36 | final static int SESSION_TIMEOUT = 5000; 37 | static int TOTAL_PUBS = 6; 38 | static int N_BYTE = 1; 39 | static boolean isFinish = false; 40 | 41 | static ZooKeeper zk = null; 42 | 43 | static AtomicLong failTimes = new AtomicLong(); 44 | 45 | /** 重连成功次数,这个表示这个session过期或断开后,重新建立连接并且成功的次数 */ 46 | static AtomicLong reConnectSuccessTimes = new AtomicLong(); 47 | /** 重连失败次数,这个表示这个session过期或断开后,重新建立连接,但是失败的次数 */ 48 | static AtomicLong reConnectFailTimes = new AtomicLong(); 49 | 50 | static List pubList = new ArrayList(); 51 | static Set pathList = new HashSet(); 52 | 53 | public static void main( String[] args ) throws IOException, KeeperException, InterruptedException { 54 | 55 | log.info( "读写压测程序开始" ); 56 | 57 | if ( args.length != 3 ) { 58 | throw new IllegalArgumentException( "请指定:zk服务器列表,发布者数量, 数据大小(这里填写一个数字,表明是1字节的倍数),如1024,那么表示数据大小是1K" ); 59 | } 60 | PressDataSetAndWatcher.SERVER_LIST = StringUtil.defaultIfBlank( args[0], SERVER_LIST ); 61 | PressDataSetAndWatcher.TOTAL_PUBS = Integer.parseInt( StringUtil.defaultIfBlank( args[1], TOTAL_PUBS + EmptyObjectConstant.EMPTY_STRING ) ); 62 | PressDataSetAndWatcher.PATH += "-" 63 | + StringUtil.defaultIfBlank( SystemUtil.getHostName(), System.currentTimeMillis() + EmptyObjectConstant.EMPTY_STRING ); 64 | PressDataSetAndWatcher.N_BYTE = Integer.parseInt( StringUtil.defaultIfBlank( args[2], N_BYTE + EmptyObjectConstant.EMPTY_STRING ) ); 65 | 66 | try { 67 | // 准备发布者 68 | for ( int i = 0; i < TOTAL_PUBS; i++ ) { 69 | String path = PATH + "-" + i; 70 | pubList.add( new WatchedPublisher( SERVER_LIST, SESSION_TIMEOUT, path, N_BYTE ) ); 71 | pathList.add( path ); 72 | } 73 | PressDataSetAndWatcher press = new PressDataSetAndWatcher(); 74 | if ( press.createAndInitPaths() ) { 75 | // 启动统计程序 76 | StatisticsUtil.start( 20 ); 77 | for ( WatchedPublisher publisher : pubList ) { 78 | publisher.start(); 79 | } 80 | } 81 | } finally { 82 | while ( !isFinish ) { 83 | log.error( "错误次数: " + PressDataSetAndWatcher.failTimes ); 84 | log.warn( "重连成功次数:" + PressDataSetAndWatcher.reConnectSuccessTimes ); 85 | log.warn( "重连失败次数:" + PressDataSetAndWatcher.reConnectFailTimes ); 86 | Thread.sleep( 10000 ); 87 | } 88 | StatisticsUtil.stop(); 89 | closeZk( zk ); 90 | } 91 | } 92 | 93 | boolean createAndInitPaths() { 94 | 95 | try { 96 | zk = new ZooKeeper( SERVER_LIST, SESSION_TIMEOUT, this ); 97 | log.info( "需要创建的PATH数是:" + pathList.size() ); 98 | log.info( "等待path创建" ); 99 | while ( null != zk && States.CONNECTED != zk.getState() ) { 100 | try { 101 | Thread.sleep( 20 ); 102 | } catch ( Throwable t ) { 103 | t.printStackTrace(); 104 | } 105 | } 106 | for ( String path : pathList ) { 107 | if ( null != zk.exists( path, false ) ) { 108 | zk.delete( path, -1 ); 109 | } 110 | zk.create( path, EmptyObjectConstant.EMPTY_STRING.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL ); 111 | log.info( "Create path: " + path ); 112 | Thread.sleep( 20 ); 113 | zk.setData( path, new byte[N_BYTE * 1], -1 ); 114 | } 115 | log.info( "PATH创建完毕" ); 116 | return true; 117 | } catch ( Exception e ) { 118 | e.printStackTrace(); 119 | return false; 120 | } 121 | 122 | } 123 | 124 | static void closeZk( ZooKeeper zk ) { 125 | if ( null != zk ) { 126 | try { 127 | zk.close(); 128 | } catch ( InterruptedException e ) { 129 | }finally{ 130 | zk = null; 131 | } 132 | } 133 | } 134 | 135 | @Override 136 | public void process( WatchedEvent event ) { 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/taokeeper/research/test/performance/setdataandwatcher/WatchedPublisher.java: -------------------------------------------------------------------------------- 1 | package com.taobao.taokeeper.research.test.performance.setdataandwatcher; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.zookeeper.KeeperException; 8 | import org.apache.zookeeper.KeeperException.Code; 9 | import org.apache.zookeeper.WatchedEvent; 10 | import org.apache.zookeeper.Watcher.Event.EventType; 11 | import org.apache.zookeeper.ZooKeeper.States; 12 | 13 | import com.taobao.taokeeper.research.test.performance.onlysetdata.Publisher; 14 | 15 | import common.toolkit.java.util.ObjectUtil; 16 | import common.toolkit.java.util.StatisticsUtil; 17 | import common.toolkit.java.util.ThreadUtil; 18 | 19 | /** 20 | * 21 | * @author yinshi.nc 22 | * @Date 2011-11-10 23 | */ 24 | public class WatchedPublisher extends Publisher { 25 | 26 | protected static Log LOG = LogFactory.getLog( WatchedPublisher.class ); 27 | 28 | public WatchedPublisher( String serverList, int sessionTimeout, String path, int bytes ) throws IOException { 29 | super( serverList, sessionTimeout, path, bytes ); 30 | } 31 | 32 | public void start() { 33 | if ( null == this.zk ) 34 | return; 35 | ThreadUtil.startThread( new Runnable() { 36 | @Override 37 | public void run() { 38 | // ������� 39 | while ( true ) { 40 | try { 41 | while ( zk != null && States.CONNECTING == zk.getState() ) { 42 | Thread.sleep( 20 ); 43 | } 44 | zk.getData( path, true, null ); 45 | zk.setData( path, new byte[bytes], -1 ); 46 | } catch ( KeeperException keeperException ) { 47 | keeperException.code().equals( Code.SESSIONEXPIRED ); 48 | try { 49 | createZk(); 50 | PressDataSetAndWatcher.reConnectSuccessTimes.incrementAndGet(); 51 | } catch ( Exception e ) { 52 | PressDataSetAndWatcher.reConnectFailTimes.incrementAndGet(); 53 | e.printStackTrace(); 54 | } 55 | } catch ( Exception e ) { 56 | PressDataSetAndWatcher.failTimes.incrementAndGet(); 57 | log.error( "fail set data: " + e.getMessage() ); 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | } ); 63 | } 64 | 65 | @Override 66 | public void process( WatchedEvent event ) { 67 | 68 | if ( ObjectUtil.isBlank( event ) ) { 69 | return; 70 | } 71 | // 事件类型 72 | EventType eventType = event.getType(); 73 | // 受影响的path 74 | String path = event.getPath(); 75 | 76 | if ( EventType.NodeDataChanged == eventType ) { 77 | try { 78 | while ( zk != null && States.CONNECTING == zk.getState() ) { 79 | Thread.sleep( 20 ); 80 | } 81 | zk.getData( path, true, null ); 82 | StatisticsUtil.totalTransactions.incrementAndGet(); 83 | } catch ( KeeperException keeperException ) { 84 | keeperException.code().equals( Code.SESSIONEXPIRED ); 85 | try { 86 | createZk(); 87 | PressDataSetAndWatcher.reConnectSuccessTimes.incrementAndGet(); 88 | } catch ( Exception e ) { 89 | PressDataSetAndWatcher.reConnectFailTimes.incrementAndGet(); 90 | e.printStackTrace(); 91 | } 92 | } catch ( Exception e ) { 93 | PressDataSetAndWatcher.failTimes.incrementAndGet(); 94 | log.error( "fail set data: " + e.getMessage() ); 95 | e.printStackTrace(); 96 | } 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/zookeeper/presstest/createnode/SequenceNodeCreator.java: -------------------------------------------------------------------------------- 1 | package com.taobao.zookeeper.presstest.createnode; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.zookeeper.CreateMode; 8 | import org.apache.zookeeper.WatchedEvent; 9 | import org.apache.zookeeper.Watcher; 10 | import org.apache.zookeeper.ZooDefs.Ids; 11 | import org.apache.zookeeper.ZooKeeper; 12 | import org.apache.zookeeper.ZooKeeper.States; 13 | 14 | import common.toolkit.java.constant.EmptyObjectConstant; 15 | import common.toolkit.java.util.StatisticsUtil; 16 | import common.toolkit.java.util.StringUtil; 17 | import common.toolkit.java.util.ThreadUtil; 18 | 19 | /** 20 | * SequenceNode 鍒涘缓鑰� 21 | * 22 | * @author yinshi.nc 23 | * @Date 2011-11-10 24 | */ 25 | public class SequenceNodeCreator implements Watcher { 26 | 27 | 28 | Log log = LogFactory.getLog( getClass() ); 29 | 30 | private String serverList; 31 | private static int SESSION_TOUT = 5000; 32 | private String parentPath; 33 | private ZooKeeper zk; 34 | private static boolean needPrint = false; 35 | 36 | public SequenceNodeCreator( String serverList, String parentPath ) throws IOException { 37 | this.serverList = serverList; 38 | this.parentPath = parentPath; 39 | ThreadUtil.startThread( new Runnable() { 40 | @Override 41 | public void run() { 42 | while( true ){ 43 | needPrint = true; 44 | try { 45 | Thread.sleep( 3000 ); 46 | } catch ( InterruptedException e ) {} 47 | } 48 | } 49 | } ); 50 | } 51 | 52 | private String createSequenceNode() { 53 | try { 54 | if ( null == zk || States.CONNECTED != zk.getState() ) 55 | zk = buildZooKeeperClient(); 56 | return zk.create( parentPath + "/" + "child-", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL ); 57 | } catch ( Exception e ) { 58 | SequenceNodeTest.failTimes.incrementAndGet(); 59 | return null; 60 | } 61 | } 62 | 63 | private ZooKeeper buildZooKeeperClient() throws IOException, InterruptedException { 64 | if ( zk != null ) { 65 | zk.close(); 66 | } 67 | return new ZooKeeper( this.serverList, SESSION_TOUT, this ); 68 | } 69 | 70 | private boolean closeSession( ZooKeeper zk ) { 71 | if ( null != zk ) { 72 | try { 73 | zk.close(); 74 | } catch ( InterruptedException e ) { 75 | } 76 | } 77 | return true; 78 | } 79 | 80 | public void start() { 81 | 82 | ThreadUtil.startThread( new Runnable() { 83 | @Override 84 | public void run() { 85 | try{ 86 | while ( true ) { 87 | String path = EmptyObjectConstant.EMPTY_STRING; 88 | if ( !StringUtil.isBlank( path = createSequenceNode() ) ) { 89 | if( needPrint ){ 90 | needPrint = false; 91 | log.info( "path: " + path ); 92 | } 93 | StatisticsUtil.totalTransactions.incrementAndGet(); 94 | } 95 | } 96 | }catch(Exception e){ 97 | 98 | }finally{ 99 | closeSession( zk ); 100 | } 101 | } 102 | } ); 103 | 104 | } 105 | 106 | @Override 107 | public void process( WatchedEvent event ) { 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/zookeeper/presstest/createnode/SequenceNodeTest.java: -------------------------------------------------------------------------------- 1 | package com.taobao.zookeeper.presstest.createnode; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | import org.apache.zookeeper.CreateMode; 11 | import org.apache.zookeeper.KeeperException; 12 | import org.apache.zookeeper.WatchedEvent; 13 | import org.apache.zookeeper.Watcher; 14 | import org.apache.zookeeper.ZooDefs.Ids; 15 | import org.apache.zookeeper.ZooKeeper; 16 | import org.apache.zookeeper.data.Stat; 17 | 18 | import common.toolkit.java.constant.EmptyObjectConstant; 19 | import common.toolkit.java.util.StatisticsUtil; 20 | import common.toolkit.java.util.StringUtil; 21 | 22 | /** 23 | * 类说明: 进行SequenceNode建立压力测试 24 | * @author yinshi.nc 25 | */ 26 | public class SequenceNodeTest implements Watcher { 27 | 28 | static Log log = LogFactory.getLog( SequenceNodeTest.class ); 29 | 30 | static String SERVER_LIST = "10.13.44.47:2181"; 31 | final static int SESSION_TIMEOUT = 5000; 32 | static int SESSIONCREATORS = 10; 33 | static String PARENT_PATH = "/YINSHI_PRESS_TEST_SEQ_NODE"; 34 | 35 | static AtomicLong failTimes = new AtomicLong(); 36 | 37 | static List< SequenceNodeCreator > nodeCreatorList = new ArrayList< SequenceNodeCreator >(); 38 | 39 | static boolean isWork = true; 40 | 41 | 42 | public static void main( String[] args ) throws IOException, KeeperException, InterruptedException { 43 | 44 | if ( args.length != 2 ) { 45 | throw new IllegalArgumentException( "请指定:zk服务器列表,SessionCreator数量" ); 46 | } 47 | SequenceNodeTest.SERVER_LIST = StringUtil.defaultIfBlank( args[0], SERVER_LIST ); 48 | SequenceNodeTest.SESSIONCREATORS = Integer.parseInt( StringUtil.defaultIfBlank( args[1], SESSIONCREATORS + EmptyObjectConstant.EMPTY_STRING ) ); 49 | 50 | try { 51 | 52 | createParentNode(); 53 | 54 | // 准备SessionCreator 55 | for ( int i = 0; i < SESSIONCREATORS; i++ ) { 56 | nodeCreatorList.add( new SequenceNodeCreator( SERVER_LIST, PARENT_PATH ) ); 57 | } 58 | // 启动统计程序 59 | StatisticsUtil.start( 20 ); 60 | for ( SequenceNodeCreator sessionCreator : nodeCreatorList ) { 61 | sessionCreator.start(); 62 | } 63 | }catch(Exception e){ 64 | e.printStackTrace(); 65 | }finally { 66 | while ( isWork ) { 67 | log.error( "创建SequenceNode错误次数: " + SequenceNodeTest.failTimes ); 68 | Thread.sleep( 10000 ); 69 | } 70 | StatisticsUtil.stop(); 71 | } 72 | } 73 | 74 | 75 | static void createParentNode() throws KeeperException, InterruptedException, IOException{ 76 | ZooKeeper zk = new ZooKeeper( SERVER_LIST, 5000, new SequenceNodeTest() ); 77 | Stat stat = zk.exists( PARENT_PATH, false ); 78 | 79 | if( null == stat ) 80 | zk.create( PARENT_PATH, "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT ); 81 | 82 | zk.close(); 83 | } 84 | 85 | 86 | 87 | public void process( WatchedEvent event ) { 88 | // TODO Auto-generated method stub 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/zookeeper/presstest/watcher/PressWatcher.java: -------------------------------------------------------------------------------- 1 | package com.taobao.zookeeper.presstest.watcher; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | import java.util.concurrent.atomic.AtomicLong; 10 | 11 | import org.apache.commons.logging.Log; 12 | import org.apache.commons.logging.LogFactory; 13 | import org.apache.zookeeper.CreateMode; 14 | import org.apache.zookeeper.KeeperException; 15 | import org.apache.zookeeper.ZooDefs.Ids; 16 | import org.apache.zookeeper.ZooKeeper; 17 | 18 | import common.toolkit.java.constant.EmptyObjectConstant; 19 | import common.toolkit.java.util.StatisticsUtil; 20 | import common.toolkit.java.util.StringUtil; 21 | 22 | 23 | /** 24 | * ��˵��: Watcher ���� 25 | * 26 | * @author yinshi.nc 27 | */ 28 | public class PressWatcher{ 29 | 30 | static Log log = LogFactory.getLog( PressWatcher.class ); 31 | 32 | static String PATH = "/YINSHI.NC-PRESS-TEST"; 33 | static String SERVER_LIST = "10.13.44.47:2181"; 34 | final static int SESSION_TIMEOUT = 5000; 35 | static int TOTAL_PUBS = 6; 36 | static long PUT_TIMES = 10000000; 37 | static int N_256 = 1; // 256�ֽڵı��� 38 | 39 | static AtomicLong failTimes = new AtomicLong(); 40 | 41 | /** �����ɹ����������ʾ���session���ڻ�Ͽ������½������Ӳ��ҳɹ��Ĵ��� */ 42 | static AtomicLong reConnectSuccessTimes = new AtomicLong(); 43 | /** ����ʧ�ܴ��������ʾ���session���ڻ�Ͽ������½������ӣ�����ʧ�ܵĴ��� */ 44 | static AtomicLong reConnectFailTimes = new AtomicLong(); 45 | 46 | static List< Publisher > pubList = new ArrayList< Publisher >(); 47 | static List< Subscriber > subList = new ArrayList< Subscriber >(); 48 | static Set< String > pathList = new HashSet< String >(); 49 | 50 | // ���������ķ��������� 51 | static AtomicInteger finshedPub = new AtomicInteger(); 52 | 53 | public static void main( String[] args ) throws IOException, KeeperException, InterruptedException { 54 | 55 | if ( args.length != 5 ) { 56 | throw new IllegalArgumentException( 57 | "��ָ����zk�������б?����������, ÿ�������߷���, PATH��׺, ��ݴ�С(������дһ�����֣�������256�ֽڵı���)����4����ô��ʾ��ݴ�С��1K" ); 58 | } 59 | PressWatcher.SERVER_LIST = StringUtil.defaultIfBlank( args[0], SERVER_LIST ); 60 | PressWatcher.TOTAL_PUBS = Integer.parseInt( StringUtil.defaultIfBlank( args[1], TOTAL_PUBS + EmptyObjectConstant.EMPTY_STRING ) ); 61 | PressWatcher.PUT_TIMES = Long.parseLong( StringUtil.defaultIfBlank( args[2], PUT_TIMES + EmptyObjectConstant.EMPTY_STRING ) ); 62 | PressWatcher.PATH += StringUtil.defaultIfBlank( args[3], System.currentTimeMillis() + EmptyObjectConstant.EMPTY_STRING ); 63 | PressWatcher.N_256 = Integer.parseInt( StringUtil.defaultIfBlank( args[4], N_256 + EmptyObjectConstant.EMPTY_STRING ) ); 64 | 65 | try { 66 | 67 | 68 | // ׼��Path 69 | if ( !createAndInitPaths() ){ 70 | log.error( "Path����ʧ��" ); 71 | System.exit( 0 ); 72 | } 73 | // ׼�������ߺͶ����� 74 | for ( String path : pathList ) { 75 | pubList.add( new Publisher( SERVER_LIST, SESSION_TIMEOUT, path, PUT_TIMES, N_256 * 256 ) ); 76 | for( int j = 0; j < 3 ;j++){ 77 | subList.add( new Subscriber( SERVER_LIST, SESSION_TIMEOUT, path ) ); 78 | } 79 | } 80 | 81 | // ����ͳ�Ƴ��� 82 | StatisticsUtil.start( 10 ); 83 | for ( Publisher publisher : pubList ) { 84 | publisher.start(); 85 | } 86 | log.info( "�ȴ���������" ); 87 | Thread.sleep( 10000 ); 88 | for ( Subscriber subscriber : subList ) { 89 | subscriber.start(); 90 | } 91 | 92 | } finally { 93 | while ( finshedPub.get() < TOTAL_PUBS ) { 94 | log.warn( "setData/getData�������: " + failTimes + " | Session�����ɹ�����" + PressWatcher.reConnectSuccessTimes + ", ʧ�ܴ���" + PressWatcher.reConnectFailTimes); 95 | Thread.sleep( 10000 ); 96 | } 97 | finalDeleteNode(); 98 | StatisticsUtil.stop(); 99 | } 100 | } 101 | 102 | static boolean createAndInitPaths() { 103 | 104 | ZooKeeper zk = null; 105 | try { 106 | zk = new ZooKeeper( SERVER_LIST, SESSION_TIMEOUT, null ); 107 | log.info( "��Ҫ������PATH���ǣ�" + TOTAL_PUBS ); 108 | log.info( "�ȴ�path����" ); 109 | Thread.sleep( 10000 ); 110 | for ( int i = 0; i < TOTAL_PUBS; i++ ) { 111 | String path = PATH + System.currentTimeMillis(); 112 | zk.create( path, EmptyObjectConstant.EMPTY_STRING.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT ); 113 | Thread.sleep( 20 ); 114 | zk.setData( path, new byte[ N_256 * 256 ], -1 ); 115 | pathList.add( path ); 116 | } 117 | log.info( "PATH�������" ); 118 | return true; 119 | } catch ( Exception e ) { 120 | e.printStackTrace(); 121 | return false; 122 | } finally { 123 | try { 124 | zk.close(); 125 | } catch ( InterruptedException e ) { 126 | } 127 | } 128 | 129 | } 130 | 131 | /** 132 | * ɾ��ڵ� 133 | */ 134 | static void finalDeleteNode() { 135 | try { 136 | ZooKeeper zk = new ZooKeeper( SERVER_LIST, SESSION_TIMEOUT, null ); 137 | for ( String path : pathList ) { 138 | try { 139 | int version = zk.exists( path, null ).getVersion(); 140 | zk.delete( path, version ); 141 | } catch ( Exception e ) { 142 | } 143 | } 144 | } catch ( Exception e ) { 145 | e.printStackTrace(); 146 | } 147 | 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/zookeeper/presstest/watcher/Publisher.java: -------------------------------------------------------------------------------- 1 | package com.taobao.zookeeper.presstest.watcher; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.zookeeper.KeeperException; 8 | import org.apache.zookeeper.KeeperException.Code; 9 | import org.apache.zookeeper.ZooKeeper; 10 | 11 | import common.toolkit.java.util.ThreadUtil; 12 | 13 | /** 14 | * ��ݷ����� 15 | * @author yinshi.nc 16 | * @Date 2011-11-10 17 | */ 18 | public class Publisher{ 19 | 20 | private static Log log = LogFactory.getLog( Publisher.class ); 21 | 22 | ZooKeeper zk = null; 23 | private String path; 24 | private String serverList; 25 | private int sessionTimeout; 26 | private long setTimes = 0; 27 | private int bytes = 256; 28 | 29 | public Publisher(String serverList, int sessionTimeout, String path, long setTimes, int bytes) throws IOException { 30 | this.serverList = serverList; 31 | this.sessionTimeout = sessionTimeout; 32 | this.path = path; 33 | this.setTimes = setTimes; 34 | this.bytes = bytes; 35 | this.createZk(); 36 | } 37 | 38 | private boolean createZk(){ 39 | if( null != this.zk ){ 40 | try { 41 | this.zk.close(); 42 | } catch ( InterruptedException e ) { 43 | //ignore 44 | } 45 | this.zk = null; 46 | } 47 | try { 48 | this.zk = new ZooKeeper( this.serverList, this.sessionTimeout, null ); 49 | return true; 50 | } catch ( IOException e ) { 51 | return false; 52 | } 53 | } 54 | 55 | public void start() { 56 | if( null == this.zk ) 57 | return; 58 | ThreadUtil.startThread( new Runnable() { 59 | @Override 60 | public void run() { 61 | //������� 62 | for ( int i = 0; i < setTimes; i++ ) { 63 | try { 64 | zk.setData( path, new byte[bytes], -1 ); 65 | } catch(KeeperException keeperException ){ 66 | //�����ڣ���ôҪ��������һ���ˡ� 67 | keeperException.code().equals( Code.SESSIONEXPIRED ); 68 | if( createZk() ) { 69 | PressWatcher.reConnectSuccessTimes.incrementAndGet(); 70 | }else{ 71 | PressWatcher.reConnectFailTimes.incrementAndGet(); 72 | } 73 | }catch ( Exception e ) { 74 | PressWatcher.failTimes.incrementAndGet(); 75 | log.error( "fail set data: " + e.getMessage() ); 76 | } 77 | } 78 | PressWatcher.finshedPub.incrementAndGet(); 79 | } 80 | } ); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/java/com/taobao/zookeeper/presstest/watcher/Subscriber.java: -------------------------------------------------------------------------------- 1 | package com.taobao.zookeeper.presstest.watcher; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.zookeeper.KeeperException; 8 | import org.apache.zookeeper.KeeperException.Code; 9 | import org.apache.zookeeper.WatchedEvent; 10 | import org.apache.zookeeper.Watcher; 11 | import org.apache.zookeeper.ZooKeeper; 12 | import org.apache.zookeeper.data.Stat; 13 | 14 | import common.toolkit.java.util.StatisticsUtil; 15 | import common.toolkit.java.util.ThreadUtil; 16 | 17 | /** 18 | * ��ݶ�����,�յ���ݱ��֪ͨ�������ݻ�ȡ 19 | * @author yinshi.nc 20 | * @since 2011-11-22 21 | */ 22 | public class Subscriber implements Watcher { 23 | 24 | private static Log log = LogFactory.getLog( Subscriber.class ); 25 | 26 | ZooKeeper zk = null; 27 | private String path; 28 | private String serverList; 29 | private int sessionTimeout; 30 | 31 | /** 32 | * @param path znode��path 33 | * @throws IOException 34 | * @throws InterruptedException 35 | */ 36 | public Subscriber( String serverList, int sessionTimeout, String path ){ 37 | this.serverList = serverList; 38 | this.sessionTimeout = sessionTimeout; 39 | this.path = path; 40 | this.createZk(); 41 | } 42 | 43 | private boolean createZk(){ 44 | if( null != this.zk ){ 45 | try { 46 | this.zk.close(); 47 | } catch ( InterruptedException e ) { 48 | //ignore 49 | } 50 | this.zk = null; 51 | } 52 | try { 53 | this.zk = new ZooKeeper( this.serverList, this.sessionTimeout, this ); 54 | return true; 55 | } catch ( IOException e ) { 56 | return false; 57 | } 58 | } 59 | 60 | public void start() { 61 | if( null == this.zk ) 62 | return; 63 | ThreadUtil.startThread( new Runnable() { 64 | @Override 65 | public void run() { 66 | // ��ȡ��� 67 | try { 68 | zk.exists( path, true ); 69 | }catch(KeeperException keeperException ){ 70 | //�����ڣ���ôҪ��������һ���ˡ� 71 | keeperException.code().equals( Code.SESSIONEXPIRED ); 72 | if( createZk() ) { 73 | PressWatcher.reConnectSuccessTimes.incrementAndGet(); 74 | }else{ 75 | PressWatcher.reConnectFailTimes.incrementAndGet(); 76 | } 77 | }catch ( Exception e ) { 78 | PressWatcher.failTimes.incrementAndGet(); 79 | log.error( "zk.exists: "); 80 | e.printStackTrace(); 81 | } 82 | } 83 | } ); 84 | } 85 | 86 | @Override 87 | public void process( WatchedEvent event ) { 88 | 89 | // ��ȡ��� 90 | try { 91 | if( null == this.zk ){ 92 | createZk(); 93 | } 94 | zk.getData( path, true, new Stat() ); 95 | StatisticsUtil.totalTransactions.incrementAndGet(); 96 | }catch(KeeperException keeperException ){ 97 | //�����ڣ���ôҪ��������һ���ˡ� 98 | keeperException.code().equals( Code.SESSIONEXPIRED ); 99 | if( createZk() ) { 100 | PressWatcher.reConnectSuccessTimes.incrementAndGet(); 101 | }else{ 102 | PressWatcher.reConnectFailTimes.incrementAndGet(); 103 | } 104 | }catch ( Exception e ) { 105 | PressWatcher.failTimes.incrementAndGet(); 106 | log.error( "Fail get data: " ); 107 | e.printStackTrace(); 108 | } 109 | 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /taokeeper-research/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # DEFAULT 2 | log4j.rootLogger=INFO,CONSOLE 3 | 4 | # 5 | # Log INFO level and above messages to the console 6 | # 7 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 8 | log4j.appender.CONSOLE.Threshold=INFO 9 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %m%n 11 | 12 | # 13 | # Add ROLLINGFILE to rootLogger to get log file output 14 | # Log DEBUG level and above messages to a log file 15 | log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender 16 | log4j.appender.ROLLINGFILE.Threshold=INFO 17 | log4j.appender.ROLLINGFILE.File=/home/admin/taokeeper-monitor/logs/taokeeper-monitor.log 18 | log4j.appender.ROLLINGFILE.DatePattern='.'yyyy-MM-dd 19 | 20 | log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{2}@%L] - %m%n 22 | 23 | 24 | log4j.appender.COMMONSTAT=org.apache.log4j.DailyRollingFileAppender 25 | log4j.appender.COMMONSTAT.Threshold=INFO 26 | log4j.appender.COMMONSTAT.File=/usr/local/taokeeper-test-agent/log/presstest-case4.log 27 | log4j.appender.COMMONSTAT.DatePattern='.'yyyy-MM-dd 28 | 29 | log4j.appender.COMMONSTAT.layout=org.apache.log4j.PatternLayout 30 | log4j.appender.COMMONSTAT.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] - %m%n 31 | 32 | log4j.logger.org.displaytag=WARN 33 | log4j.logger.org.apache.zookeeper=ERROR 34 | log4j.logger.org.springframework=WARN 35 | log4j.logger.org.I0Itec=WARN 36 | log4j.logger.commonStat=INFO,COMMONSTAT --------------------------------------------------------------------------------