CollTeradata.java 22.9 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 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
/** ******************************************************************* */
//
// Copyright (c) 2006 by SI-TECH Corporation
// All Rights Reserved
//
// NCR CONFIDENTIAL AND TRADE SECRET
//
// *********************************************************************
//
// File: CollTeradata.java
// Purpose: 采集NCR数据库Teradata指标
//              
//              
//
// 编译:javac -d F:\工作资料\网管程序\src -deprecation CollTeradata.java
// 运行: java com.sitech.ismp.coll.CollTeradata
// java com.sitech.ismp.coll.CollNCRWithCMD
// *********************************************************************
package com.sitech.ismp.coll;

import java.util.Date;
import java.util.HashMap;
import java.util.Vector;

import com.sitech.util.DES3;

public class CollTeradata implements CollTeradataMBean {

	String KBP_ID = "10-11-33";

	String hostip = null;

	String user = null;

	String passwd = null;

	String kbp_id = "10-11-33";

	String sid = null;

	String SID = null;

	String NEATENSID = "DBC";

	// SQLTargetNCR collectiondbbase = null;

	public CollTeradata() {
		// collectiondbbase = new SQLTargetNCR();
	}

	/**
	 * * CollNCR(String IP_ADDR,String USERNAME,String PASSWORD,String
	 * KBP_ID,String SID) **
	 */
	/* 为测试 main 函数所增加 */
	/*
	 * public CollTeradata(String IP_ADDR,String USERNAME,String PASSWORD,String
	 * KBP_ID,String SID,int cycle) { try { collectiondbbase = new
	 * SQLTargetNCR();
	 * 
	 * //故障报警 10分钟一次getDeadLockInfo 15分钟一次getStateInfo
	 * 
	 * 
	 * 
	 * getStateInfo(IP_ADDR,USERNAME,PASSWORD,KBP_ID,SID);
	 * getDeadLockInfo(IP_ADDR,USERNAME,PASSWORD,KBP_ID,SID);
	 * 
	 *  // 一个小时运行一次 性能指标 getSessionInfo(IP_ADDR,USERNAME,PASSWORD,KBP_ID,SID);
	 *  // 一个小时运行一次 包括性能指标和配置指标
	 * getDiskSpace(IP_ADDR,USERNAME,PASSWORD,KBP_ID,SID);
	 *  // NCR数据库性能 一个小时一次 getMemCPU(IP_ADDR,USERNAME,PASSWORD,KBP_ID,SID);
	 *  // 数据库配置信息 一个月一次 getDbInfo(IP_ADDR,USERNAME,PASSWORD,KBP_ID,SID);
	 *  } catch (Throwable ex) { System.out.println(" Error1 : " +
	 * ex.getMessage()); ex.printStackTrace(); }
	 *  }
	 */

	/* 数据库配置信息 采集周期一个月 30*24*60*60 = 2592000 秒 */
	/*
	 * CM-00-03-001-01 数据库名 数据库标识 CM-00-03-001-02 版本信息 数据库版本信息 CM-00-03-001-03
	 * 数据库的位数 32/64位
	 */

	public java.util.Vector getDbInfo(java.util.HashMap params)
			throws Exception {
		getParams(params);
		return getDbInfo(hostip, user, passwd, kbp_id, sid);
	}

	public java.util.Vector getDbInfo(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS"; // 标识NCR 数据库
																	// Teradata
																	// 指标

		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			getDbInfo(collectiondbbase);
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "down");
		}
		collectiondbbase.release();
		// collectiondbbase.displayKPI();
		// collectiondbbase.saveKPI2File();
		return collectiondbbase.getKPISet();
	}

	private void getDbInfo(SQLTargetNCR collectiondbbase) {
		String KBP_ID = "10-11-33" + "-10" + ":" + NEATENSID + "-SYS";
		String sSelDiskSpace;

		try {
			/** *** 标识NCR 数据库 Teradata 版本信息 **** */
			sSelDiskSpace = "SELECT InfoData	FROM dbc.dbcinfo where	InfoKey='VERSION'		";
			Vector CM = collectiondbbase.getSQLKPIResult(sSelDiskSpace);
			for (int i = 0; i < CM.size(); i++) {
				Vector row = (Vector) CM.get(i);
				collectiondbbase.addKPI(KBP_ID, "CM-00-03-001-02", (String) row
						.get(0));
				collectiondbbase.addKPI(KBP_ID, "CM-00-03-001-03", "32");
			}
			// collectiondbbase.displayKPI();
			collectiondbbase.addKPI(KBP_ID, "CM-00-03-001-01", "DBC");
		} catch (Throwable ex) {
			System.out.println(" Error  : " + ex.getMessage());
			ex.printStackTrace();
		}
		// saveKPI2File();
	}

	/*
	 * 一天一次 CM-00-03-003-01 表空间名 数据库内各表空间名 dbc.diskspace中的databasename
	 * CM-00-03-003-02 表空间大小 数据库内各表空间大小(MB) dbc.diskspace中的SUM(MaxPerm) String
	 * KBP_ID = this.KBP_ID+"-11"+":"+NEATENSID+"-TABLESPACES";
	 * 
	 * CM-00-03-005-01 回滚段名 数据库日志空间或回滚段名 固定,dbc.TransientJournal CM-00-03-005-02
	 * 回滚段大小 数据库的回滚段的大小(MB) dbc.diskspace中的sum(maxperm-currentperm) String
	 * KBP_ID = "10-11-33"+"-10"+":"+NEATENSID+"-SYS";
	 * 
	 * PM-00-03-004-01 表空间使用率 该表可用空间的百分比
	 * dbc.diskspace中的SUM(CurrentPerm)/NULLIFZERO(SUM(MaxPerm)) String KBP_ID =
	 * this.KBP_ID+"-11"+":"+NEATENSID+"-TABLESPACES";
	 * 
	 * 
	 * 数据库日志空间或回滚段使用情况 PM-00-03-007-01 利用情况 其对应空间利用的百分比 dbc.diskspace中 DBC 数据库的
	 * SUM(CurrentPerm)/NULLIFZERO(SUM(MaxPerm)) String KBP_ID =
	 * this.KBP_ID+"-12"+":"+NEATENSID+"-DATAFILE";
	 * 
	 * PM-00-03-007-02 竞争情况 数据库日志空间或回滚段数据块等待操作 dbc.diskspace中 DBC 数据库的
	 * SUM(CurrentPerm)/NULLIFZERO(SUM(MaxPerm)) 占总操作的百分比情况可以其显示竞争情况 String
	 * KBP_ID = this.KBP_ID+"-15"+":"+NEATENSID+"-OTH";
	 * 
	 */

	public java.util.Vector getDiskSpace(java.util.HashMap params)
			throws Exception {
		getParams(params);
		return getDiskSpace(hostip, user, passwd, kbp_id, sid);
	}

	public java.util.Vector getDiskSpace(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS";
		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			getDiskSpace(collectiondbbase);
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "down");
		}
		collectiondbbase.release();
		collectiondbbase.displayKPI();
		return collectiondbbase.getKPISet();
	}

	private void getDiskSpace(SQLTargetNCR collectiondbbase) {
		String KBP_ID = "10-11-33" + "-10" + ":" + NEATENSID + "-SYS"; /* 表空间情况 */
		String sSelDiskSpace;
		String sTemp;
		String sTemp1;
		String sTemp2;
		String sTemp3;
		String sTemp4;

		int i;

		sTemp = "";
		sTemp1 = "";
		sTemp2 = "";
		sTemp3 = "";
		sTemp4 = "";

		try {
			/** *** 标识NCR 数据库 Teradata 指标 **** */
			sSelDiskSpace = "SELECT DatabaseName,SUM(CurrentPerm),SUM(MaxPerm)/(1024*1024),"
					+ " SUM(CurrentPerm)/NULLIFZERO(SUM(MaxPerm)),"
					+ " sum(maxperm-currentperm)/(1024*1024)"
					+ "	FROM DBC.DiskSpace GROUP BY DatabaseName HAVING SUM(MaxPerm) >0 "
					+ "  ORDER BY SUM(CurrentPerm) DESC";

			Vector CM = collectiondbbase.getSQLKPIResult(sSelDiskSpace);
			for (i = 0; i < CM.size(); i++) {
				Vector row = (Vector) CM.get(i);

				KBP_ID = "10-11-33" + "-11" + ":" + NEATENSID + "-TABLESPACES"; /* 表空间情况 */

				sTemp1 = (String) row.get(2);
				if ((sTemp1.length() - sTemp1.indexOf(".")) >= 3) {
					sTemp1 = sTemp1.substring(0, sTemp1.indexOf("."));
				}
				collectiondbbase.addKPI(KBP_ID + "-" + (String) row.get(0),
						"CM-00-03-003-01", (String) row.get(0));
				collectiondbbase.addKPI(KBP_ID + "-" + (String) row.get(0),
						"CM-00-03-003-02", sTemp1);

				sTemp1 = (String) row.get(3);
				if ((sTemp1.length() - sTemp1.indexOf(".")) >= 3) {
					sTemp1 = sTemp1.substring(0, sTemp1.indexOf(".") + 3);
				}

				collectiondbbase.addKPI(KBP_ID + "-" + (String) row.get(0),
						"PM-00-03-004-01", sTemp1);
				sTemp = (String) row.get(0);
				if (sTemp.compareTo("DBC") == 0) {
					// System.out.println("DBC ok");
					sTemp3 = (String) row.get(4);
					sTemp4 = (String) row.get(3);
				}

			}

			if ((sTemp3.length() - sTemp3.indexOf(".")) >= 3) {
				sTemp3 = sTemp3.substring(0, sTemp3.indexOf(".") + 3);
			}

			KBP_ID = "10-11-33" + "-10" + ":" + NEATENSID + "-SYS";
			collectiondbbase.addKPI(KBP_ID, "CM-00-03-005-01",
					"dbc.TransientJournal");
			collectiondbbase.addKPI(KBP_ID, "CM-00-03-005-02", sTemp3);

			if ((sTemp4.length() - sTemp4.indexOf(".")) >= 3) {
				sTemp4 = sTemp4.substring(0, sTemp4.indexOf(".") + 3);
			}
			KBP_ID = "10-11-33" + "-12" + ":" + NEATENSID + "-DATAFILE";
			collectiondbbase.addKPI(KBP_ID + "-DBC", "PM-00-03-007-01", sTemp4);

			KBP_ID = "10-11-33" + "-15" + ":" + NEATENSID + "-OTH";
			collectiondbbase.addKPI(KBP_ID, "PM-00-03-007-02", sTemp4);

			// collectiondbbase.displayKPI();
		} catch (Throwable ex) {
			System.out.println(" Error  : " + ex.getMessage());
			ex.printStackTrace();
		}
		// saveKPI2File();
	}

	/*
	 * PM-00-03-001-01 共享内存使用百分比 共享内存已经利用的部分占总体的百分比 PM-00-03-005-01 读操作次数
	 * 该数据设备的读操作次数 PM-00-03-005-02 写操作次数 该数据设备的写操作次数
	 * 
	 * PM-00-03-009-01 CPU占用率 其对应操作一天内平均占用CPU时间 String KBP_ID =
	 * this.KBP_ID+"-14"+":"+NEATENSID+"-TABLES";
	 * 
	 * PM-00-03-009-02 内存的占用率 一天内平均占用内存的资源情况
	 */

	public java.util.Vector getMemCPU(java.util.HashMap params)
			throws Exception {
		getParams(params);
		return getMemCPU(hostip, user, passwd, kbp_id, sid);
	}

	public java.util.Vector getMemCPU(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS";
		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			getMemCPU(collectiondbbase);
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "down");
		}
		collectiondbbase.release();
		// collectiondbbase.displayKPI();
		return collectiondbbase.getKPISet();
	}

	private void getMemCPU(SQLTargetNCR collectiondbbase) {
		String KBP_ID = "10-11-33" + "-15" + ":" + NEATENSID + "-OTH";
		String sSelNetwork;
		String sTemp;
		String sYear;
		String sFrom;
		String sTo;
		String sTemp1;

		sTemp = getSysDate(60, hostip, user, passwd, sid);
		sTo = sTemp.substring(18, 26);
		sFrom = sTemp.substring(10, 18);
		sYear = sTemp.substring(0, 10);

		try {
			/** *** Node Network Traffic **** */
			sSelNetwork = "	SELECT    TheDate (FORMAT'yy/mm/dd', TITLE '// //    Date'), "
					+ "	TheTime (FORMAT'99:99:99', TITLE '// //    Time'), "
					+ "	SUM((MemSize(FLOAT))*1024-MemFreeKB)*100/NULLIFZERO(SUM(MemSize(FLOAT))*1024) "
					+ "	(FORMAT 'ZZ9', TITLE 'Use//Mem//  %') ,"
					+ "	SUM(LogicalDeviceReads),             "
					+ "	SUM(LogicalDeviceWrites),						 "
					+ "	SUM(CPUBusy) / SUM(Secs) (FORMAT 'ZZ9', TITLE 'CPU//Bsy//  %')  "
					+ "	FROM DBC.ResGeneralInfoView "
					+ " WHERE		(( TheDate = '"
					+ sYear
					+ "' AND TheTime >= '"
					+ sFrom
					+ "' ) OR (TheDate > '"
					+ sYear
					+ "' )) "
					+ " AND			(( TheDate = '"
					+ sYear
					+ "' AND TheTime <= '"
					+ sTo
					+ "' ) OR (TheDate < '"
					+ sYear
					+ "' )) "
					+ " GROUP BY TheDate, TheTime "
					+ " ORDER BY TheDate, TheTime ";

			Vector CM = collectiondbbase.getSQLKPIResult(sSelNetwork);
			for (int i = 0; i < CM.size(); i++) {
				Vector row = (Vector) CM.get(i);
				collectiondbbase.addKPI(KBP_ID, "PM-00-03-001-01", (String) row
						.get(2));
				collectiondbbase.addKPI(KBP_ID, "PM-00-03-005-01", (String) row
						.get(3));
				collectiondbbase.addKPI(KBP_ID, "PM-00-03-005-02", (String) row
						.get(4));
				sTemp1 = (String) row.get(5);
				if ((sTemp1.length() - sTemp1.indexOf(".")) >= 3) {
					sTemp1 = sTemp1.substring(0, sTemp1.indexOf(".") + 3);
				}
				collectiondbbase.addKPI(KBP_ID, "PM-00-03-009-01", sTemp1);

				sTemp1 = (String) row.get(2);
				if ((sTemp1.length() - sTemp1.indexOf(".")) >= 3) {
					sTemp1 = sTemp1.substring(0, sTemp1.indexOf(".") + 3);
				}
				collectiondbbase.addKPI(KBP_ID, "PM-00-03-009-02", sTemp1);
				// System.out.print("Node id:("+(String)row.get(2)+") value1
				// :("+(String)row.get(3)+")
				// value2:("+(String)row.get(4)+")\n");
			}

		} catch (Throwable ex) {
			System.out.println(" Error  : " + ex.getMessage());
			ex.printStackTrace();
		}
	}

	/*
	 * PM-00-03-009-03 会话数量 数据库的当前会话数
	 */

	public java.util.Vector getSessionInfo(java.util.HashMap params)
			throws Exception {
		getParams(params);
		return getSessionInfo(hostip, user, passwd, kbp_id, sid);
	}

	public java.util.Vector getSessionInfo(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS";
		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			getSessionInfo(collectiondbbase);
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "down");
		}
		collectiondbbase.release();
		// collectiondbbase.displayKPI();
		// collectiondbbase.saveKPI2File();
		return collectiondbbase.getKPISet();
	}

	private void getSessionInfo(SQLTargetNCR collectiondbbase) {
		String KBP_ID = "10-11-33" + "-10" + ":" + NEATENSID + "-SYS";
		String sSelDiskSpace;
		String sTemp;
		String sYear;
		String sFrom;
		String sTo;

		sTemp = "";
		sTemp = getSysDate(60, hostip, user, passwd, sid);
		sTo = sTemp.substring(18, 26);
		sFrom = sTemp.substring(10, 18);
		sYear = sTemp.substring(0, 10);

		try {
			/** *** 标识NCR 数据库 Teradata 指标 **** */
			sSelDiskSpace = "SELECT count(*) FROM dbc.sessioninfo "
					+ "WHERE		(( LogonDate = '" + sYear
					+ "' AND LogonTime >= '" + sFrom + "' ) OR (LogonDate > '"
					+ sYear + "' )) " + "AND			(( LogonDate = '" + sYear
					+ "' AND LogonTime <= '" + sTo + "' ) OR (LogonDate < '"
					+ sYear + "' )) ";

			Vector CM = collectiondbbase.getSQLKPIResult(sSelDiskSpace);
			for (int i = 0; i < CM.size(); i++) {
				Vector row = (Vector) CM.get(i);
				collectiondbbase.addKPI(KBP_ID + "-20-18-12",
						"PM-00-03-009-03", (String) row.get(0));
			}

		} catch (Throwable ex) {
			System.out.println(" Error  : " + ex.getMessage());
			ex.printStackTrace();
		}
	}

	/*
	 * FM-00-03-001-03 有无死锁产生 有无死锁产生
	 */

	public java.util.Vector getDeadLockInfo(java.util.HashMap params)
			throws Exception {
		getParams(params);
		return getDeadLockInfo(hostip, user, passwd, kbp_id, sid);
	}

	public java.util.Vector getDeadLockInfo(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS";
		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			// collectiondbbase.saveKPI2File();
			getDeadLockInfo(collectiondbbase);
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "down");
			// collectiondbbase.saveKPI2File();
		}
		collectiondbbase.release();
		// collectiondbbase.displayKPI();

		return collectiondbbase.getKPISet();
	}

	private void getDeadLockInfo(SQLTargetNCR collectiondbbase) {
		String KBP_ID = "10-11-33" + "-15" + ":" + NEATENSID + "-OTH";
		String sSelDiskSpace;
		String sTemp;
		String sYear;
		String sFrom;
		String sTo;

		sTemp = "";
		sTemp = getSysDate(10, hostip, user, passwd, sid);
		// System.out.println("sTemp="+sTemp);
		sTo = sTemp.substring(18, 26);
		sFrom = sTemp.substring(10, 18);
		sYear = sTemp.substring(0, 10);

		try {
			/** *** 标识NCR 数据库 Teradata 指标 **** */
			sSelDiskSpace = "select count(*) from dbc.sw_event_log where	event_tag=2631	and"
					+ "	(( TheDate = '"
					+ sYear
					+ "' AND TheTime >= '"
					+ sFrom
					+ "' ) OR (TheDate > '"
					+ sYear
					+ "' )) "
					+ "	AND	(( TheDate = '"
					+ sYear
					+ "' AND theTime <= '"
					+ sTo + "' ) OR (TheDate < '" + sYear + "' )) ";

			// System.out.print(sSelDiskSpace);
			Vector CM = collectiondbbase.getSQLKPIResult(sSelDiskSpace);
			// System.out.println("ok!!");
			for (int i = 0; i < CM.size(); i++) {
				Vector row = (Vector) CM.get(i);
				collectiondbbase.addKPI(KBP_ID, "FM-00-03-001-03", (String) row
						.get(0));
				// collectiondbbase.saveKPI2File();
			}
			// collectiondbbase.displayKPI();
		} catch (Throwable ex) {
			System.out.println(" Error  : " + ex.getMessage());
			ex.printStackTrace();
		}
		// saveKPI2File();
	}

	/*
	 * FM-00-03-001-01 数据库状态 数据库是否可用 FM-00-03-001-02 表空间状态 表空间所处状态
	 */
	public java.util.Vector getStateInfo(java.util.HashMap params)
			throws Exception {
		getParams(params);
		return getStateInfo(hostip, user, passwd, kbp_id, sid);
	}

	public java.util.Vector getStateInfo(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS";
		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-02", "up");
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "down");
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-02", "down");
		}
		collectiondbbase.release();
		// collectiondbbase.displayKPI();
		return collectiondbbase.getKPISet();
	}

	/*
	 * CM-00-03-004-01 表名 数据库特定表名称 CM-00-03-004-05 是否有分区 指该表是分区表还是变通表 NCR中全是分区表
	 */
	public java.util.Vector getSpecialTable(java.util.HashMap params)
			throws Exception {
		String TABLEOWNER = (String) params.get("TABLEOWNER");
		String TABLENAME = (String) params.get("TABLENAME");
		getParams(params);
		return getSpecialTable(hostip, user, passwd, kbp_id, sid, TABLEOWNER,
				TABLENAME);
	}

	public java.util.Vector getSpecialTable(String IP_ADDR, String USERNAME,
			String PASSWORD, String KBP_ID, String SID, String tableOwner,
			String tableName) throws Exception {
		this.KBP_ID = KBP_ID + "-10" + ":" + NEATENSID + "-SYS";
		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		if (collectiondbbase.getState()) {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "up");
			getSpecialTable(collectiondbbase, tableOwner, tableName);
		} else {
			collectiondbbase.addKPI(this.KBP_ID, "FM-00-03-001-01", "Down");
		}
		Vector aa = collectiondbbase.getKPISet();

		collectiondbbase.release();
		// collectiondbbase.displayKPI();
		return aa;
	}

	private void getSpecialTable(SQLTargetNCR collectiondbbase,
			String tableOwner, String tableName) {
		String KBP_ID = "10-11-33" + "-14" + ":" + NEATENSID + "-TABLES";
		collectiondbbase.addKPI(KBP_ID, "CM-00-03-004-01", tableName);
		collectiondbbase.addKPI(KBP_ID, "CM-00-03-004-05", "partition table");
	}

	private boolean getParams(java.util.HashMap params) {
		DES3 d;

		d = new DES3();
		hostip = (String) params.get("IP_ADDR");
		user = (String) params.get("USERNAME");
		passwd = d.decrypt((String) params.get("PASSWORD"));
		kbp_id = (String) params.get("KBP_ID");
		sid = (String) params.get("SID");
		/*
		 * System.out.println("USERNAME=\n"+user);
		 * System.out.println("PASSWORD=\n"+passwd);
		 */
		return true;
	}

	/*
	 * 返回值 格式 yyyy-mm-ddhh24:mi:sshh24:mi:ss 第一个hh24:mi:ss为开始的时间
	 * 第二个hh24:mi:ss为结束的时间 间隔10分钟
	 */
	/*
	 * public static String getSysDate() { Date dSysDate; String sYear; String
	 * sMonth; String sDay; String sMinFrom; String sMinTo; int i;
	 * 
	 * dSysDate =new Date(); if(dSysDate.getMonth()<10) sMonth
	 * ="0"+(dSysDate.getMonth()+1); else sMonth
	 * =Integer.toString(dSysDate.getMonth()+1);
	 * 
	 * if(dSysDate.getDate()<10) sDay ="0"+dSysDate.getDate(); else sDay
	 * =Integer.toString(dSysDate.getDate());
	 * 
	 * i =dSysDate.getMinutes(); i =i/10*10; if(i<10) { sMinFrom
	 * =Integer.toString(dSysDate.getHours())+":00:00"; sMinTo
	 * =Integer.toString(dSysDate.getHours())+":05:00"; } else { sMinFrom
	 * =Integer.toString(dSysDate.getHours())+":"+Integer.toString(i)+":00";
	 * sMinTo
	 * =Integer.toString(dSysDate.getHours())+":"+Integer.toString(i+5)+":00"; }
	 * 
	 * 
	 * System.out.println("sMonth= "+sMonth+" "+" sDay= "+sDay);
	 * 
	 * sYear =Integer.toString((dSysDate.getYear()+1900))+"-"+sMonth+"-"+sDay;
	 * System.out.println("system= "+sYear+" From= "+sMinFrom+" sMinTo=
	 * "+sMinTo); sYear =sYear+sMinFrom+sMinTo; System.out.println("system
	 * :"+sYear+"\n"); System.out.println("to :"+sYear.substring(18,26)+"\n");
	 * System.out.println("From :"+sYear.substring(10,18)+"\n");
	 * System.out.println("year :"+sYear.substring(0,10)+"\n"); return sYear; }
	 */

	/*
	 * 修改:20060525 增加:时间间隔分钟数,最少时间间隔是5分钟
	 * 
	 * 
	 * 返回值 格式 yyyy-mm-ddhh24:mi:sshh24:mi:ss 第一个hh24:mi:ss为开始的时间
	 * 第二个hh24:mi:ss为结束的时间
	 * 
	 */
	public String getSysDate(int Minutes, String IP_ADDR, String USERNAME,
			String PASSWORD, String SID) {
		Date dSysDate;
		String sYear;
		String sMonth;
		String sDay;
		String sMinFrom;
		String sMinTo;
		String sSelDateTime;
		int i;

		SQLTargetNCR collectiondbbase = new SQLTargetNCR();
		collectiondbbase.init(IP_ADDR, SID, USERNAME, PASSWORD);

		sSelDateTime = "select CURRENT_DATE,CURRENT_TIME-INTERVAL '"
				+ Integer.toString(Minutes) + "' MINUTE,CURRENT_TIME";
		// System.out.println("sSelDateTime="+sSelDateTime);
		sYear = "";
		sMinFrom = "";
		sMinTo = "";

		Vector CM = collectiondbbase.getSQLKPIResult(sSelDateTime);
		// System.out.print("pe row number :"+CM.size()+"\n");
		for (i = 0; i < CM.size(); i++) {
			Vector row = (Vector) CM.get(i);
			sYear = (String) row.get(0);
			sMinFrom = (String) row.get(1);
			sMinTo = (String) row.get(2);
			sYear = sYear + sMinFrom + sMinTo;
			// System.out.print("SYear="+sYear);
		}
		return sYear;
	}

	public static void main(String[] args) // throws Exception
	{
		String IP_ADDR = "10.182.91.14";
		// String USERNAME ="bnms_ismp";
		// String PASSWORD ="i5s2$sp4";
		String USERNAME = "jiankong";
		String PASSWORD = "837d15f2021bc7fee4ae4ba30270a4169d3e8d2895fb3843";
		String KBP_ID = "10-86";
		String SID = "DBC";
		String pass = "837d15f2021bc7fee4ae4ba30270a4169d3e8d2895fb3843";
		String pass1 = "0.028815832816767698";

		try {
			CollTeradata a = new CollTeradata();
			HashMap param = new HashMap();
			param.put("IP_ADDR", IP_ADDR);
			param.put("USERNAME", USERNAME);
			param.put("PASSWORD", PASSWORD);
			param.put("KBP_ID", KBP_ID);
			param.put("SID", SID);
			// System.out.println("CM-00-03-003-01="+pass1.substring(0,pass1.lastIndexOf(".")+3));
			a.getDiskSpace(param);
		} catch (Throwable ex) {
			System.out.println(" Error  : " + ex.getMessage());
			ex.printStackTrace();
		}
	}

}