CollWebLogic10.java 26.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
package com.sitech.ismp.coll.middleware.weblogic.impl;

import java.io.IOException;
import java.net.MalformedURLException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;

import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

import org.apache.log4j.Logger;

import com.sitech.ismp.coll.CollBase;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;

public class CollWebLogic10 implements ICollWebLogic {
	private static Logger logger = Logger.getLogger("COLL");	

	static String user;
	static String pass;
	static String server;
	static String port;
	static String domainname;
	static String cmd;

	private static MBeanServerConnection connection;
	private static JMXConnector connector;
	private static final ObjectName service;

	static {
		try {
			service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
		} catch (MalformedObjectNameException e) {
			throw new AssertionError(e.getMessage());
		}
	}

	@Override
	public void collWeblogic10WithJMX(HashMap<String, String> map) {
		try {
			buildConnection(map);
			getServerNameAndState();
			getJvmRuntime();
			getExecuteQueueRuntime();
			getJdbcRuntime();
			getThreadPoolRuntime();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(map+"Error", e);;
		}finally{
			closeConnection();
		}
	}

    public Vector<TblATO_KPIDETAIL> getStatus(HashMap<String, String> params) {
        return null;
    }

	public static void buildConnection(HashMap<String, String> map) throws IOException, MalformedURLException {
		user = (String) map.get("USERNAME");
		pass = (String) map.get("PASSWORD");
		server = (String) map.get("SERVER");
		port = (String) map.get("PORT");
		domainname = (String) map.get("DOMAIN");
		cmd = (String) map.get("SHELLCMD");
		
		String protocol = "t3";
		Integer portInteger = Integer.valueOf(port);
		int myport = portInteger.intValue();
		String jndiroot = "/jndi/";
		String mserver = "weblogic.management.mbeanservers.domainruntime";
		JMXServiceURL serviceURL = new JMXServiceURL(protocol, server, myport, jndiroot + mserver);
		Hashtable<String, String> h = new Hashtable<String, String>();
		h.put(Context.SECURITY_PRINCIPAL, user);
		h.put(Context.SECURITY_CREDENTIALS, pass);
		h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
		connector = JMXConnectorFactory.connect(serviceURL, h);
		connection = connector.getMBeanServerConnection();
		logger.info("[创建连接成功]");
	}

	public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException {
		String protocol = "t3";
		Integer portInteger = Integer.valueOf(portString);
		int port = portInteger.intValue();
		String jndiroot = "/jndi/";
		String mserver = "weblogic.management.mbeanservers.domainruntime";
		JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);
		Hashtable<String, String> h = new Hashtable<String, String>();
		h.put(Context.SECURITY_PRINCIPAL, username);
		h.put(Context.SECURITY_CREDENTIALS, password);
		h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
		connector = JMXConnectorFactory.connect(serviceURL, h);
		connection = connector.getMBeanServerConnection();
	}

	public static ObjectName[] getServerRuntimes() throws Exception {
		return (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");
	}

	/**
	 * servers 采集服务状态和端口数量 
	 * 服务名 CM-00-04-009-01 
	 * 状态 FM-00-04-009-01 
	 * 端口数量 CM-00-02-002-06
	 * 版本 CM-00-04-009-04
	 */
	public void getServerNameAndState() throws Exception {
		String kbp_class = "10-12-11-10";
		String unit_id = kbp_class + ":" + domainname;
		
		String kpi_servername = "CM-00-04-009-01";
		String kpi_state = "FM-00-04-009-01";
		String kpi_socketcount = "CM-00-02-002-06";
		String kpi_version = "CM-00-04-009-04";

		logger.info("采集服务状态和端口数量");
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;

		for (int i = 0; i < length; i++) {
			String ext_unit_id = unit_id + "-" + connection.getAttribute(serverRT[i], "Name").toString();
			
			String name = connection.getAttribute(serverRT[i], "Name").toString();
			logger.info(ext_unit_id + "\t" + kpi_servername + "\t" + name);
			setResult(name, ext_unit_id, kpi_servername);
			
			String state = connection.getAttribute(serverRT[i], "State").toString();
			logger.info(ext_unit_id + "\t" + kpi_state + "\t" + state);
			setResult(state, ext_unit_id, kpi_state);
			
			String openSocketCount = connection.getAttribute(serverRT[i], "OpenSocketsCurrentCount").toString();
			logger.info(ext_unit_id + "\t" + kpi_socketcount + "\t" + openSocketCount);
			setResult(openSocketCount, ext_unit_id, kpi_socketcount);
			
			setResult("WebLogic10", ext_unit_id, kpi_version);
		}
	}

	/**
	 * JVM内存堆 采集JVM内存堆相关参数 
	 * 服务名 CM-00-04-009-01
	 * jvm厂商 CM-00-04-009-10
	 * java版本 CM-00-04-009-09
	 * JVM堆中内存数 PM-00-04-009-05
	 * 空闲内存数 PM-00-04-009-04
	 * 当前内存堆使用比率 PM-00-04-003-01
	 */
	public void getJvmRuntime() throws Exception {
		String kbp_class = "10-12-11-12";
		String unit_id = kbp_class + ":" + domainname;
		String kpi_servername = "CM-00-04-009-01";
		String kpi_javavendor = "CM-00-04-009-10";
		String kpi_javaversion = "CM-00-04-009-09";
		String kpi_heapsizemax = "PM-00-04-009-05";
		String kpi_heapfreecurrent = "PM-00-04-009-04";
		String kpi_heapusepercent = "PM-00-04-003-01";
		String kpi_heapFreePercent = "PM-00-05-009-04";

		logger.info("采集JVM内存堆相关参数");
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;

		for (int i = 0; i < length; i++) {
			String ext_unit_id = unit_id + "-" + connection.getAttribute(serverRT[i], "Name").toString();

			String name = (String) connection.getAttribute(serverRT[i], "Name");
			logger.info(ext_unit_id + "\t" + kpi_servername + "\t" + name);
			setResult(name, ext_unit_id, kpi_servername);
			
			ObjectName jvmRT = (ObjectName) connection.getAttribute(serverRT[i], "JVMRuntime");
			String JavaVendor = (String) connection.getAttribute(jvmRT, "JavaVendor");
			logger.info(ext_unit_id + "\t" + kpi_javavendor + "\t" + JavaVendor);
			setResult(JavaVendor, ext_unit_id, kpi_javavendor);
			
			String JavaVersion = (String) connection.getAttribute(jvmRT, "JavaVersion");
			logger.info(ext_unit_id + "\t" + kpi_javaversion + "\t" + JavaVersion);
			setResult(JavaVersion, ext_unit_id, kpi_javaversion);
			
			Long LFreeCurrent = (Long) connection.getAttribute(jvmRT, "HeapFreeCurrent");
			String HeapFreeCurrent = LFreeCurrent.toString();
			logger.info(ext_unit_id + "\t" + kpi_heapfreecurrent + "\t" + HeapFreeCurrent);
			setResult(HeapFreeCurrent, ext_unit_id, kpi_heapfreecurrent);
			
			Long LSizeMax = (Long) connection.getAttribute(jvmRT, "HeapSizeMax");
			String HeapSizeMax = LSizeMax.toString();
			logger.info(ext_unit_id + "\t" + kpi_heapsizemax + "\t" + HeapSizeMax);
			setResult(HeapSizeMax, ext_unit_id, kpi_heapsizemax);
			
			Double freePercent = (LFreeCurrent * 1.0) / (LSizeMax * 1.0);
			DecimalFormat df = new DecimalFormat("##0.00");
			String HeapFreePercent = df.format(freePercent * 100);
			logger.info(ext_unit_id + "\t" + kpi_heapFreePercent + "\t" + HeapFreePercent);
			setResult(HeapFreePercent, ext_unit_id, kpi_heapFreePercent);

			Double usePercent = 1 - freePercent;
			String HeapUsePercent = df.format(usePercent * 100);
			logger.info(ext_unit_id + "\t" + kpi_heapusepercent + "\t" + HeapUsePercent);
			setResult(HeapUsePercent, ext_unit_id, kpi_heapusepercent);
		}
	}

	/**
	 * 消息队列 采集消息队列相关参数 
	 * 服务名 CM-00-04-009-01 
	 * 队列名 CM-00-04-009-17 
	 * 队列中的空闲执行线程总数 PM-00-04-009-15 
	 * 队列中的执行线程总数 PM-00-04-009-16 
	 * 队列中被处理的请求数量 PM-00-04-009-17
	 * 队列中的等待请求数 PM-00-04-009-18
	 */
	public void getExecuteQueueRuntime() throws Exception {
		String kbp_class = "10-12-11-16";
		String unit_id = kbp_class + ":" + domainname;
		String kpi_servername = "CM-00-04-009-01";
		String kpi_queuename = "CM-00-04-009-17";
		String kpi_ExecuteThreadCurrentIdleCount = "PM-00-04-009-15";
		String kpi_ExecuteThreadTotalCount = "PM-00-04-009-16";
		String kpi_ServicedRequestTotalCount = "PM-00-04-009-17";
		String kpi_PendingRequestCurrentCount = "PM-00-04-009-18";

		logger.info("采集消息队列相关参数");
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;

		for (int i = 0; i < length; i++) {
			String servername = (String) connection.getAttribute(serverRT[i], "Name");

			ObjectName[] threadRT = (ObjectName[]) connection.getAttribute(serverRT[i], "ExecuteQueueRuntimes");
			String queuename = "";// 队列名称
			String ExecuteThreadCurrentIdleCount = "";// 队列中的空闲执行线程总数
			String ExecuteThreadTotalCount = "";// 队列中的执行线程总数
			String ServicedRequestTotalCount = "";// 队列中被处理的请求数量
			String PendingRequestCurrentCount = "";// 队列中的等待请求数

			for (int x = 0; x < threadRT.length; x++) {
				queuename = (String) connection.getAttribute(threadRT[x], "Name");
				String ext_unit_id = unit_id + "-" + servername + "_" + queuename;
				logger.info(ext_unit_id + "\t" + kpi_servername + "\t" + servername);
				logger.info(ext_unit_id + "\t" + kpi_queuename + "\t" + queuename);
				setResult(servername, ext_unit_id, kpi_servername);
				setResult(queuename, ext_unit_id, kpi_queuename);
				
				ExecuteThreadCurrentIdleCount = connection.getAttribute(threadRT[x], "ExecuteThreadCurrentIdleCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ExecuteThreadCurrentIdleCount + "\t" + ExecuteThreadCurrentIdleCount);
				setResult(ExecuteThreadCurrentIdleCount, ext_unit_id, kpi_ExecuteThreadCurrentIdleCount);
				
				ExecuteThreadTotalCount = connection.getAttribute(threadRT[x], "ExecuteThreadTotalCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ExecuteThreadTotalCount + "\t" + ExecuteThreadTotalCount);
				setResult(ExecuteThreadTotalCount, ext_unit_id, kpi_ExecuteThreadTotalCount);
				
				ServicedRequestTotalCount = connection.getAttribute(threadRT[x], "ServicedRequestTotalCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ServicedRequestTotalCount + "\t" + ServicedRequestTotalCount);
				setResult(ServicedRequestTotalCount, ext_unit_id, kpi_ServicedRequestTotalCount);
				
				PendingRequestCurrentCount = connection.getAttribute(threadRT[x], "PendingRequestCurrentCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_PendingRequestCurrentCount + "\t" + PendingRequestCurrentCount);
				setResult(PendingRequestCurrentCount, ext_unit_id, kpi_PendingRequestCurrentCount);
			}
		}
	}

	/**
	 * JDBC连接池
	 * jdbc名称 CM-00-04-009-13
	 * 状态 PM-00-04-009-04
	 * 活动连接平均计数 PM-00-04-009-06 
	 * 当前活动连接计数 PM-00-04-009-07
	 * 最大活动连接计数 PM-00-04-009-08
	 * 连接总数 PM-00-04-009-09
	 * 重新连接失败计数 PM-00-04-009-10
	 * 泄漏连接计数 PM-00-04-009-11
	 * Prep Stmt缓存命中计数 PM-00-04-009-13
	 * 等待连接当前计数 PM-00-04-009-14
	 */
	public void getJdbcRuntime() throws Exception {
		String kbp_class = "10-12-11-13";
		String unit_id = kbp_class + ":" + domainname;
		String kpi_servername = "CM-00-04-009-01";
		String kpi_jdbcname = "CM-00-04-009-13";
		String kpi_state = "FM-00-04-009-04";
		String kpi_ActiveConnectionsAverageCount = "PM-00-04-009-06";
		String kpi_ActiveConnectionsCurrentCount = "PM-00-04-009-07";
		String kpi_ActiveConnectionsHighCount = "PM-00-04-009-08";
		String kpi_ConnectionsTotalCount = "PM-00-04-009-09";
		String kpi_FailuresToReconnectCount = "PM-00-04-009-10";
		String kpi_LeakedConnectionCount = "PM-00-04-009-11";
		String kpi_PrepStmtCacheHitCount = "PM-00-04-009-13";
		String kpi_WaitingForConnectionCurrentCount = "PM-00-04-009-14";

		String servername = "";
		String jdbcname = "";
		String state = "";
		String ActiveConnectionsAverageCount = "";
		String ActiveConnectionsCurrentCount = "";
		String ActiveConnectionsHighCount = "";
		String ConnectionsTotalCount = "";
		String FailuresToReconnectCount = "";
		String LeakedConnectionCount = "";
		String PrepStmtCacheHitCount = "";
		String WaitingForConnectionCurrentCount = "";

		logger.info("采集JDBC连接池相关参数");
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;
		
		for (int i = 0; i < length; i++) {
			servername = (String) connection.getAttribute(serverRT[i], "Name");
			ObjectName[] appRT = (ObjectName[]) connection.getAttribute(new ObjectName("com.bea:Name=" + servername + ",ServerRuntime=" + servername + ",Location=" + servername + ",Type=JDBCServiceRuntime"), "JDBCDataSourceRuntimeMBeans");
			int appLength = (int) appRT.length;
			
			for (int x = 0; x < appLength; x++) {
				jdbcname = (String) connection.getAttribute(appRT[x], "Name");
				String ext_unit_id = unit_id + "-" + servername + "_" + jdbcname;
				logger.info(ext_unit_id + "\t" + kpi_servername + "\t" + servername);
				setResult(servername, ext_unit_id, kpi_servername);
				logger.info(ext_unit_id + "\t" + kpi_jdbcname + "\t" + jdbcname);
				setResult(jdbcname, ext_unit_id, kpi_jdbcname);
				
				state = connection.getAttribute(appRT[x], "State").toString();
				logger.info(ext_unit_id + "\t" + kpi_state + "\t" + state);
				setResult(state, ext_unit_id, kpi_state);
				
				ActiveConnectionsCurrentCount = connection.getAttribute(appRT[x], "ActiveConnectionsCurrentCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ActiveConnectionsCurrentCount + "\t" + ActiveConnectionsCurrentCount);
				setResult(ActiveConnectionsCurrentCount, ext_unit_id, kpi_ActiveConnectionsCurrentCount);
				
				ActiveConnectionsAverageCount = connection.getAttribute(appRT[x], "ActiveConnectionsAverageCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ActiveConnectionsAverageCount + "\t" + ActiveConnectionsAverageCount);
				setResult(ActiveConnectionsAverageCount, ext_unit_id, kpi_ActiveConnectionsAverageCount);
				
				ActiveConnectionsHighCount = connection.getAttribute(appRT[x], "ActiveConnectionsHighCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ActiveConnectionsHighCount + "\t" + ActiveConnectionsHighCount);
				setResult(ActiveConnectionsHighCount, ext_unit_id, kpi_ActiveConnectionsHighCount);
				
				ConnectionsTotalCount = connection.getAttribute(appRT[x], "ConnectionsTotalCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_ConnectionsTotalCount + "\t" + ConnectionsTotalCount);
				setResult(ConnectionsTotalCount, ext_unit_id, kpi_ConnectionsTotalCount);
				
				FailuresToReconnectCount = connection.getAttribute(appRT[x], "FailuresToReconnectCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_FailuresToReconnectCount + "\t" + FailuresToReconnectCount);
				setResult(FailuresToReconnectCount, ext_unit_id, kpi_FailuresToReconnectCount);
				
				LeakedConnectionCount = connection.getAttribute(appRT[x], "LeakedConnectionCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_LeakedConnectionCount + "\t" + LeakedConnectionCount);
				setResult(LeakedConnectionCount, ext_unit_id, kpi_LeakedConnectionCount);
				
				PrepStmtCacheHitCount = connection.getAttribute(appRT[x], "PrepStmtCacheHitCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_PrepStmtCacheHitCount + "\t" + PrepStmtCacheHitCount);
				setResult(PrepStmtCacheHitCount, ext_unit_id, kpi_PrepStmtCacheHitCount);
				
				WaitingForConnectionCurrentCount = connection.getAttribute(appRT[x], "WaitingForConnectionCurrentCount").toString();
				logger.info(ext_unit_id + "\t" + kpi_WaitingForConnectionCurrentCount + "\t" + WaitingForConnectionCurrentCount);
				setResult(WaitingForConnectionCurrentCount, ext_unit_id, kpi_WaitingForConnectionCurrentCount);
			}
		}
	}

	/**
	 * 线程池 
	 * CM-00-05-009-25 线程池名 
	 * PM-00-05-009-26 请求完毕数 
	 * PM-00-05-009-28 线程总数
	 * PM-00-05-009-27 空闲线程数 
	 * FM-00-05-009-02 线程池健康状况 
	 * PM-00-05-009-29 等待用户请求数
	 * PM-00-05-009-32 队列长度 
	 * PM-00-05-009-33 备用线程数 
	 * PM-00-05-009-31 吞吐率(每秒钟处理的请求平均数)
	 */
	public void getThreadPoolRuntime() throws Exception {
		String kbp_class = "10-12-11-17";
		String unit_id = kbp_class + ":" + domainname;
		String kpi_servername = "CM-00-04-009-01";
		String kpi_ThreadPoolName = "CM-00-05-009-25";
		String kpi_CompletedRequestCount = "PM-00-05-009-26";
		String kpi_ExecuteThreadTotalCount = "PM-00-05-009-28";
		String kpi_ExecuteThreadIdleCount = "PM-00-05-009-27";
		String kpi_HealthState = "FM-00-05-009-02";
		String kpi_PendingUserRequestCount = "PM-00-05-009-29";
		String kpi_QueueLength = "PM-00-05-009-32";
		String kpi_StandbyThreadCount = "PM-00-05-009-33";
		String kpi_Throughput = "PM-00-05-009-31";

		String servername = "";
		String ThreadPoolName = "";
		String CompletedRequestCount = "";
		String ExecuteThreadTotalCount = "";
		String ExecuteThreadIdleCount = "";
		String HealthState = "";
		String PendingUserRequestCount = "";
		String QueueLength = "";
		String StandbyThreadCount = "";
		String Throughput = "";

		logger.info("采集线程池相关参数");
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;

		for (int i = 0; i < length; i++) {
			servername = (String) connection.getAttribute(serverRT[i], "Name");
			ObjectName threadRT = (ObjectName) connection.getAttribute(serverRT[i], "ThreadPoolRuntime");
			ThreadPoolName = connection.getAttribute(threadRT, "Name").toString();
			String ext_unit_id = unit_id + "-" + servername + "_" + ThreadPoolName;
			logger.info(ext_unit_id + "\t" + kpi_servername + "\t" + servername);
			setResult(servername, ext_unit_id, kpi_servername);
			logger.info(ext_unit_id + "\t" + kpi_ThreadPoolName + "\t" + ThreadPoolName);
			setResult(ThreadPoolName, ext_unit_id, kpi_ThreadPoolName);
			
			CompletedRequestCount = connection.getAttribute(threadRT, "CompletedRequestCount").toString();
			logger.info(ext_unit_id + "\t" + kpi_CompletedRequestCount + "\t" + CompletedRequestCount);
			setResult(CompletedRequestCount, ext_unit_id, kpi_CompletedRequestCount);
			
			ExecuteThreadTotalCount = connection.getAttribute(threadRT, "ExecuteThreadTotalCount").toString();
			logger.info(ext_unit_id + "\t" + kpi_ExecuteThreadTotalCount + "\t" + ExecuteThreadTotalCount);
			setResult(ExecuteThreadTotalCount, ext_unit_id, kpi_ExecuteThreadTotalCount);
			
			ExecuteThreadIdleCount = connection.getAttribute(threadRT, "ExecuteThreadIdleCount").toString();
			logger.info(ext_unit_id + "\t" + kpi_ExecuteThreadIdleCount + "\t" + ExecuteThreadIdleCount);
			setResult(ExecuteThreadIdleCount, ext_unit_id, kpi_ExecuteThreadIdleCount);
			
			weblogic.health.HealthState Healthstate = (weblogic.health.HealthState) connection.getAttribute(threadRT, "HealthState");
			if (0 == Healthstate.getState()) {
				HealthState = "OK";
			} else {
				HealthState = "ERROR";
			}
			logger.info(ext_unit_id + "\t" + kpi_HealthState + "\t" + HealthState);
			setResult(HealthState, ext_unit_id, kpi_HealthState);

			PendingUserRequestCount = connection.getAttribute(threadRT, "PendingUserRequestCount").toString();
			logger.info(ext_unit_id + "\t" + kpi_PendingUserRequestCount + "\t" + PendingUserRequestCount);
			setResult(PendingUserRequestCount, ext_unit_id, kpi_PendingUserRequestCount);
			
			QueueLength = connection.getAttribute(threadRT, "QueueLength").toString();
			logger.info(ext_unit_id + "\t" + kpi_QueueLength + "\t" + QueueLength);
			setResult(QueueLength, ext_unit_id, kpi_QueueLength);
			
			StandbyThreadCount = connection.getAttribute(threadRT, "StandbyThreadCount").toString();
			logger.info(ext_unit_id + "\t" + kpi_StandbyThreadCount + "\t" + StandbyThreadCount);
			setResult(StandbyThreadCount, ext_unit_id, kpi_StandbyThreadCount);
			
			Double tmp = (Double) connection.getAttribute(threadRT, "Throughput");
			DecimalFormat df = new DecimalFormat("##0.00");
			Throughput = df.format(tmp);
			logger.info(ext_unit_id + "\t" + kpi_Throughput + "\t" + Throughput);
			setResult(Throughput, ext_unit_id, kpi_Throughput);
		}
	}

	public void getJmsRuntime() throws Exception {
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;
		for (int i = 0; i < length; i++) {
			String name = (String) connection.getAttribute(serverRT[i], "Name");
			logger.info("\n\t ——– name = " + name);
			ObjectName jmsRuntime = (ObjectName) connection.getAttribute(serverRT[i], "JMSRuntime");
			ObjectName jmsServers[] = (ObjectName[]) connection.getAttribute(jmsRuntime, "JMSServers");
			logger.info("\n\t ——–CTotal Targeted JmsServers = " + jmsServers.length);
			for (int y = 0; y < jmsServers.length; y++)
			{
				logger.info("\n\t JMSServer Name: " + connection.getAttribute(jmsServers[y], "Name"));
				ObjectName[] destRT = (ObjectName[]) connection.getAttribute(jmsServers[y], "Destinations");
				int appLength = (int) destRT.length;
				for (int x = 0; x < appLength; x++) {
					logger.info("\n.............<" + name + ": JMSServerRuntime>" + (String) connection.getAttribute(destRT[x], "Name") + ".......");
					logger.info("MessagesCurrentCount     .  : " + connection.getAttribute(destRT[x], "MessagesCurrentCount"));
					logger.info("MessagesPendingCount        : " + connection.getAttribute(destRT[x], "MessagesPendingCount"));
					logger.info("MessagesHighCount           : " + connection.getAttribute(destRT[x], "MessagesHighCount"));
					logger.info("MessagesReceivedCount        : " + connection.getAttribute(destRT[x], "MessagesReceivedCount"));
					logger.info("....................................................\n");
				}
			}
		}
	}

	public void getServletData() throws Exception {
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;
		String ApplicationName = "";
		String ComponentName = "";
		String ServletName = "";
		String ServletContextPath = "";
		String InvocationTotalCount = "";
		for (int i = 0; i < length; i++) {
			ObjectName[] appRT = (ObjectName[]) connection.getAttribute(
					serverRT[i], "ApplicationRuntimes");
			int appLength = (int) appRT.length;
			for (int x = 0; x < appLength; x++) {
				// logger.info("Application name: " +(String)
				// connection.getAttribute(appRT[x], "Name"));
				ApplicationName = (String) connection.getAttribute(appRT[x],
						"Name");
				ObjectName[] compRT = (ObjectName[]) connection.getAttribute(
						appRT[x], "ComponentRuntimes");
				int compLength = (int) compRT.length;
				for (int y = 0; y < compLength; y++) {
					// logger.info(" Component name: " +(String)
					// connection.getAttribute(compRT[y], "Name"));
					ComponentName = (String) connection.getAttribute(compRT[y],
							"Name");
					String componentType = (String) connection.getAttribute(
							compRT[y], "Type");
					// logger.info(componentType.toString());
					if (componentType.toString().equals(
							"WebAppComponentRuntime")) {
//						ObjectName[] servletRTs = (ObjectName[]) connection
//								.getAttribute(compRT[y], "Servlets");
						// int servletLength = (int) servletRTs.length;
						// for (int z = 0; z < servletLength; z++) {
						// ServletName=(String)
						// connection.getAttribute(compRT[y], "Name");
						// ServletContextPath=(String)
						// connection.getAttribute(servletRTs[z],
						// "ContextPath");
						// InvocationTotalCount =
						// connection.getAttribute(servletRTs[z],"InvocationTotalCount").toString();
						// logger.info("Application
						// name:"+ApplicationName+" Component
						// name:"+ComponentName+" Servlet name:"+ServletName+"
						// Servlet context path:"+ServletContextPath+"
						// Invocation Total Count:"+InvocationTotalCount);
						// }
						ServletName = (String) connection.getAttribute(
								compRT[y], "Name");
						// ServletContextPath=(String)
						// connection.getAttribute(compRT[y], "ContextPath");
						// InvocationTotalCount=
						// connection.getAttribute(compRT[y],
						// "InvocationTotalCount").toString();
						logger.info("Application name:"
								+ ApplicationName + " Component name:"
								+ ComponentName + " Servlet name:"
								+ ServletName + " Servlet context path:"
								+ ServletContextPath
								+ " Invocation Total Count:"
								+ InvocationTotalCount);
					}
				}
			}
		}
	}

	/**
	 * 调用脚本生成swap文件入库
	 * 
	 * @param value
	 * @param unitID
	 * @param kpiID
	 */
	private void setResult(String value, String unitID, String kpiID) {
		try {
			CollBase result = new CollBase();
			result.addKPI(unitID, kpiID, value);
			
			result.saveKPI2File();
			
//			ShellExecutor.executeCmd(cmd + " " + unitID + " " + kpiID + " " + value);
		} catch (Exception e) {
			logger.error("Error", e);;
		}
	}

	private void closeConnection() {
		if (connector != null) {
			try {
				connector.close();
				connector = null;
				user = null;
				pass = null;
				port = null;
				server = null;
				domainname = null;
				logger.info("[释放连接成功]");
			} catch (Exception e) {
				logger.error("Error", e);;
			}
		}
	}

	public static void main(String[] args) throws Exception {
		if (args.length < 4) {
			System.out
					.println("<Usage>: java CompleteWebLogicMonitoring  adm-host  adm-port adm-username adm-password");
			System.exit(0);
		}
		String hostname = args[0];
		String portString = args[1];
		String username = args[2];
		String password = args[3];
		CollWebLogic10 s = new CollWebLogic10();
		initConnection(hostname, portString, username, password);
		s.getServerNameAndState();
		connector.close();

	}

	@Override
	public Vector<TblATO_KPIDETAIL> getChannel(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getCluster(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getExecuteQueue(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getJDBC(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getJMS(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getJVM(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getServers(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getThreads(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getWebApps(HashMap<String, String> map) {
		return null;
	}

	@Override
	public Vector<TblATO_KPIDETAIL> collWeblogic10ForSX(HashMap<String, String> params) {
		return null;
	}

}