CollHPWithCMD.java 67.8 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 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
package com.sitech.ismp.coll.host;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.sitech.base.AgentProperties;
import com.sitech.ismp.app.coll.RPCTarget;
import com.sitech.ismp.coll.CollBase;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.Formater;

/**
 * @author zang
 * 
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CollHPWithCMD extends CollBase {

	String PRE_UNITID = "10-10-21"; // hp主机的标识
	private String version = "11.11";

	RPCTarget rpctarget = null;

	private String getHostName(HashMap<String, String> params) {
		String host_name ="";
		if(StringUtils.isNotBlank(params.get("DEVICE_ID"))){
			host_name = params.get("DEVICE_ID");
		}else {
			Vector<String> host = rpctarget.getKPISet("hostname");
			logger.info("hp host vet test "+host.get(0).toString()+" host size is  "+host.size());
			System.out.println("hp_size" + host.size());
			host_name = (String) host.elementAt(0);
			host_name = split(host_name, 0);
		}
		return host_name;
	}

	public boolean getState() {
		String value = rpctarget.getKPIValue("echo OK");
		if (value.equals("OK"))
			return true;
		else {
			// RPCERROR = value;
			return false;
		}

	}

	/**
	 * 内存已使用情况通过vmstat的fre字段 乘以 4k 
	 * PM-00-01-002-01 内存的使用率 vmstat 中的memory - free * 4k 为空闲内存,不通过本方法获取,通过SNMP获取 
	 * PM-00-01-002-02 内存交换请求数 vmstat 中的page - fr
	 * PM-00-01-002-03 内存交换页换进率 vmstat 中的page - pi 
	 * PM-00-01-002-04 内存交换页换出率 vmstat 中的page - po 
	 * PM-00-01-002-05 内存队列数 等待内存的进程或线程数量vmstat 中的 kthr - r
	 * PM-00-01-002-06 系统内存使用率 系统内存占所有物理内存的百分比 无此概念 
	 * PM-00-01-002-07 用户内存使用率 用户内存占所有物理内存的百分比 无此概念 
	 * PM-00-01-002-08 文件系统数据缓冲命中率 文件系统数据缓冲命中率 使用sar 2 2 , 平均读写命中率
	 */
	public Vector<TblATO_KPIDETAIL> getMemory(HashMap<String, String> params) {
		logger.info("begin getMemory");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-12"开头
		String memory_PRE_UNITID = PRE_UNITID + "-12";

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
//		String pattern = "yyyy-MM-dd-HH-mm-ss";
//		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
//		collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "",
//				"CM-00-01-001-22", dateFormat.format(new java.util.Date()));

		Vector<String> vmstat_result = rpctarget.getKPISet("vmstat 2 10");
		String vmstat_string = vmstat_result.elementAt(vmstat_result.size() - 1);	 
		
		try{			
			Vector<String> mem_num = rpctarget.getKPISet("/usr/contrib/bin/machinfo|grep Memory");
			String memTotalSize = split(mem_num.get(0), 1);
			
			double memFreeSize = Double.parseDouble(split(vmstat_string, 4)) * 4 / 1024;
			
			logger.info("-- Memory free size:" + memFreeSize);
			// 内存使用率
			double memUsage = 100.0 - (memFreeSize * 100.0) / Double.parseDouble(memTotalSize); 
			
			collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name
					+ "-memory", "PM-00-01-002-01", Formater.formatDecimalKpivalue(String.valueOf(memUsage)));
				
		}catch(Exception e){
			e.printStackTrace();
		}

		String value = "";
		value = split(vmstat_string, 9);
		collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
				"PM-00-01-002-02", Formater.formatDecimalKpivalue(value));

		value = split(vmstat_string, 7);
		collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
				"PM-00-01-002-03", Formater.formatDecimalKpivalue(value));

		value = split(vmstat_string, 8);
		collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
				"PM-00-01-002-04", Formater.formatDecimalKpivalue(value));

		value = split(vmstat_string, 0);
		collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
				"PM-00-01-002-05", Formater.formatDecimalKpivalue(value));

		try {
			Vector<String> filerate_result = rpctarget.getKPISet("sar -b 2 2 | grep Average");
			// System.out.println(filerate_result.size());
			String filerate_string = (String) filerate_result.elementAt(filerate_result.size() - 1);
			// System.out.println(filerate_string);
			int r_rate = Integer.parseInt(split(filerate_string, 3));
			int w_rate = Integer.parseInt(split(filerate_string, 6));
			collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory", 
					"PM-00-01-002-08", Formater.formatDecimalKpivalue(String.valueOf((r_rate + w_rate) / 2)));
		} catch (Exception e) {
			logger.error(e);
		}
		return collResult.getKPISet();
	}

	/**
	 * PM-00-01-004-01 文件系统使用比率 文件系统已使用的空间与总空间的比值 
	 * PM-00-01-004-02 交换区使用百分比 交换区使用百分比 
	 * PM-00-01-004-03 逻辑卷(裸设备)文件系统使用率 各逻辑卷上文件系统的使用率 
	 * PM-00-01-004-01/03 Object=Disk PM-00-01-004-02 Object=System
	 * 
	 * @param params
	 * @return
	 * @throws Exception
	 */
	public Vector<TblATO_KPIDETAIL> getFileSystem(HashMap<String, String> params) {
		logger.info("begin getFileSystem");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
//		String pattern = "yyyy-MM-dd-HH-mm-ss";
//		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
//		collResult.addKPI(PRE_UNITID + "-14" + ":" + neat_host_name + "",
//				"CM-00-01-001-22", dateFormat.format(new java.util.Date()));

		// 采集各文件系统占用率
		long fs_sum = 0; // 文件系统总空间 兆
		long fs_sum_used = 0; // 文件系统总空余空间

//		天津需求,监控的命令不用df -k,换成bdf		
//		Vector fileSystemV = rpctarget.getKPISet("df -k");
//		/*
//		 * 命令输出格式 /home (/dev/vg00/lvol5 ) : 503824 total allocated Kb 184830
//		 * free allocated Kb 318994 used allocated Kb 63 % allocation used /opt
//		 * (/dev/vg00/lvol6 ) : 3003217 total allocated Kb 1098531 free
//		 * allocated Kb 1904686 used allocated Kb 63 % allocation used
//		 * 
//		 */
//		for (int i = 0; i < fileSystemV.size(); i += 4) {
//			try {
//				String fsname_info = (String) fileSystemV.elementAt(i);
//				String fspercent_info = (String) fileSystemV.elementAt(i + 3);
//				String fsused_info = (String) fileSystemV.elementAt(i + 2);
//				String fsfree_info = (String) fileSystemV.elementAt(i + 1);
//				String fs_name = split(fsname_info, 0);
//				// String fs_size = split(fsname_info,4);
//				String fs_size = fsname_info.substring(
//						fsname_info.indexOf(')') + 4,
//						fsname_info.indexOf("total")).trim();
//				String fs_used_percent = split(fspercent_info, 0);
//				String fs_used = split(fsused_info, 0);
//
//				fsfree_info = split(fsfree_info, 0);
//				float free = Float.parseFloat(fsfree_info) / 1024;
//				String tmp_free = Float.toString(free);
//
//				if (fs_name != null && fs_name.equals("/")) {
//					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
//							+ "-//", "PM-00-01-004-03", Formater.formatDecimalKpivalue(fs_used_percent));
//
//					// 文件系统可用空间
//					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
//							+ "-//", "PM-00-01-004-04", Formater.formatDecimalKpivalue(tmp_free));
//				} else {
//					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
//							+ "-" + Formater.neatenunitid(fs_name),
//							"PM-00-01-004-03", Formater.formatDecimalKpivalue(fs_used_percent));
//
//					// 文件系统可用空间
//					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
//							+ "-" + Formater.neatenunitid(fs_name),
//							"PM-00-01-004-04", Formater.formatDecimalKpivalue(tmp_free));
//				}
//
//				long lfs_size = Long.parseLong(fs_size);
//				fs_sum = fs_sum + lfs_size;
//
//				long lfs_used = Long.parseLong(fs_used);
//				fs_sum_used = fs_sum_used + lfs_used;
//
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}
		
		Vector<String> fileSystemVTmp = rpctarget.getKPISet("bdf");
		//		因为用命令取得的数据,某些行会一行变两行,因此需要将被拆分开的合为一行,原来想法
		//直接合,但是发现会有某些行被删掉,因此造了个临时向量,把哪些有问题的行的行号记下来,
		//先把拼好的放到fileSystemVTmp,然后通过临时向量中记录的序号,将fileSystemVTmp的对应记录删除
		Vector<String> fileSystemV = new Vector();

		String vTmp1,vTmp2;
		for(int m0 = 1;m0<fileSystemVTmp.size(); m0++){
			String tmp = (String)fileSystemVTmp.elementAt(m0);
			
			String Vtmp1 = split(tmp, 1);
			if(!(null == Vtmp1 || Vtmp1.equals(null) || "".equals(Vtmp1) || ""==Vtmp1)){
				String Vtmp2 = split(tmp, 5);
				if(!(null == Vtmp2 || Vtmp2.equals(null) || "".equals(Vtmp2) || ""==Vtmp2)){
					fileSystemV.add(tmp);
				}
			}else{
				int kkk = m0+1;
				vTmp2 = ((String)fileSystemVTmp.elementAt(kkk)).trim();
				vTmp1 = tmp +"    "+ vTmp2;
				fileSystemV.add(vTmp1);
			}
		}

		for (int i = 0; i < fileSystemV.size(); i ++) {
			try{
				String fsname_info = (String) fileSystemV.elementAt(i);
				String fs_size = split(fsname_info, 1);
				String fsused_info = split(fsname_info, 2);
				String fsfree_info = split(fsname_info, 3);
				String fspercent_info = split(fsname_info, 4);

				fspercent_info = fspercent_info.substring(0, fspercent_info.indexOf("%"));
				String fs_name = split(fsname_info, 5);
				
//					logger.info("test oh test "+fs_size +"--"+fsused_info+"--"+fsfree_info+"--"+fspercent_info+"--"+fs_name+"--");
				
				float free = Float.parseFloat(fsfree_info) / 1024;
				String tmp_free = Float.toString(free);
				
				if (fs_name != null && fs_name.equals("/")) {
					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
							+ "-//", "PM-00-01-004-03", fspercent_info);

					// 文件系统可用空间
					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
							+ "-//", "PM-00-01-004-04", Formater.formatDecimalKpivalue(tmp_free));
				} else {
					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
							+ "-" + Formater.neatenunitid(fs_name),
							"PM-00-01-004-03", fspercent_info);

					// 文件系统可用空间
					collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name
							+ "-" + Formater.neatenunitid(fs_name),
							"PM-00-01-004-04", Formater.formatDecimalKpivalue(tmp_free));
				}
				
				long lfs_size = Long.parseLong(fs_size);
				fs_sum = fs_sum + lfs_size;

				long lfs_used = Long.parseLong(fsused_info);
				fs_sum_used = fs_sum_used + lfs_used;
				
			}catch(Exception e){
				e.printStackTrace();
				logger.error("test oh wrong "+e.toString());
			}
		}

		// PM-00-01-004-01 文件系统总占用率需要计算
		if (fs_sum != 0) {
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-01", Formater.formatDecimalKpivalue(String.valueOf(fs_sum_used * 100.0 / fs_sum)));
		}

//		Vector swapV = rpctarget.getKPISet("swapinfo -atm | grep dev ");	天津本地化,使用下面的。
		Vector<String> swapV = rpctarget.getKPISet("/usr/sbin/swapinfo -atm | grep dev ");
		if (swapV != null && swapV.size() > 0) {
			long swap_sum_avl = 0;
			long swap_sum_usd = 0;
			for (int i = 0; i < swapV.size(); i++) {
				String swap_info = (String) swapV.elementAt(i);
				String swap_avl = split(swap_info, 1);
				String swap_usd = split(swap_info, 2);
				swap_sum_avl = swap_sum_avl + Long.parseLong(swap_avl);
				swap_sum_usd = swap_sum_usd + Long.parseLong(swap_usd);
			}

			String swap_usd_percent = getByScale(String.valueOf(swap_sum_usd * 100.0 / swap_sum_avl));

			collResult.addKPI("10-10-21-10"+ ":" + neat_host_name + "-total",
					"PM-00-01-004-02", Formater.formatDecimalKpivalue(swap_usd_percent));
			
		}

		// 实际打开进程数/允许打开进程数 实际使用inod数/允许使用inod数 实际打开文件数/允许打开文件数
		String strUserRate = "sar -v 1 | tail -n 1 | sed 's/\\// /g' | awk '{printf(\"%0.4f\t%0.4f\t%0.4f\t%d\t%d\t%d\t%d\t%d\t%d\n\", $6/$7 *100, $9/$10 *100, $12/$13 *100, $6, $7, $9, $10, $12, $13);}'";
		Vector<String> listUserRate = rpctarget.getKPISet(strUserRate);

		if (listUserRate != null && listUserRate.size() > 0) {
			String strMsg = (String) listUserRate.get(0);

			String strProc = split(strMsg, 0);
			String strInod = split(strMsg, 1);
			String strFile = split(strMsg, 2);

			String strProc_1 = split(strMsg, 3);
			String strProc_2 = split(strMsg, 4);
			String strInod_1 = split(strMsg, 5);
			String strInod_2 = split(strMsg, 6);
			String strFile_1 = split(strMsg, 7);
			String strFile_2 = split(strMsg, 8);

			// 实际打开进程数量与可供打开数比率
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-05", strProc);
			// 实际使用inod比率
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-06", strInod);
			// 实际打开文件数比率
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-07", strFile);
			// 实际打开进程数
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-08", strProc_1);
			// 允许打开进程数
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-09", strProc_2);
			// 实际使用inod数
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-10", strInod_1);
			// 允许使用inod数
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-11", strInod_2);
			// 实际打开文件数
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-12", strFile_1);
			// 允许打开文件数
			collResult.addKPI(PRE_UNITID + "-10:" + neat_host_name + "-total",
					"PM-00-01-004-13", strFile_2);
		}

		return collResult.getKPISet();
	}

	/**
	 * 
	 * 获取所有用户用户进程数
	 * 
	 * @param params
	 * @return
	 */

	public Vector<TblATO_KPIDETAIL> getUserProNum(HashMap<String, String> params) {
		logger.info("begin getUserProNum ");
		logger.info("begin getUserProName ");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 得到所有用户的列表,该用户名出现多少次,就表明ps出来有多少行,即有多少进程
		Vector<String> userV = new Vector();
		Vector<String> processV = rpctarget.getKPISet("ps -ef | grep -v UID");
		// 原来采用以下命令,但在jilin 10.161.1.132 hp主机上有时出现 用户名称为 _3的情况,所以弃用
		// rpctarget.getKPISet("export UNIX95=XPG4;ps -ef -o user | grep -v USER");
		for (int i = 0; i < processV.size(); i++) {
			String processInfo = (String) processV.elementAt(i);
			userV.add(collResult.split(processInfo, 0));
		}
		processV = null;

		if (userV == null || userV.size() == 0) {
			return new Vector<TblATO_KPIDETAIL>();
		}

		// 计算各个用户的进程数,并保存在这个map中
		// user - user process numer
		Map user_pronum = new HashMap();
		
		for (int i = 0; i < userV.size(); i++) {
			String userName = ((String) userV.elementAt(i)).trim();
			int pro_number = 1;
			if (user_pronum.get(userName) == null) {
				user_pronum.put(userName, new Integer(pro_number));
			} else {
				pro_number = Integer.parseInt(user_pronum.get(userName) + "") + 1;
				user_pronum.put(userName, new Integer(pro_number));
			}
		}
		
//		// 将用户排序,然后遍历计算
//		java.util.Collections.sort(userV);
//		String userName = "";
//		for (int i = 0; i < userV.size(); i++) {
//			userName = ((String) userV.elementAt(i)).trim();
//			int pro_number = 1;
//			String nextUer = "";
//			for (int j = i + 1; j < userV.size(); j++) {
//
//				// 到了下一个用户
//				nextUer = ((String) (userV.elementAt(j))).trim();
//				if (!userName.equals(nextUer)) {
//					i = j - 1;
//					break;
//				}
//				pro_number++;
//			}
//			user_pronum.put(userName, new Integer(pro_number));
//		}

		// end for

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-10"开头,代表Total数据
		String pro_PRE_UNITID = PRE_UNITID + "-21"; // total值

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		Set users = user_pronum.keySet();
		// System.out.println("users------------"+users);
		Iterator iter = users.iterator();
		while (iter.hasNext()) {
			String username = (String) iter.next();
			// System.out.println("username------------"+username);
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(username), 
					"PM-00-01-005-06", ((Integer) user_pronum.get(username)).toString());
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(username), 
					"CM-00-01-005-06", Formater.neatenunitid(username));

		}

		return collResult.getKPISet();
	}

	/**
	 * 17个指标中 15个ok 1 hp 
	 * CM-00-01-001-06(cpu频率) 待完成 
	 * 主机物理内存大小通过SNMP获取 其他待测试
	 * 在方法的最后面增加了getAllDisk的指标采集,该方法的采集值比较多,所以放在这里了。
	 * 
	 * @param params
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getConfig(HashMap<String, String> params) {
		logger.info("begin getConfig");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-10"开头,代表Total数据
		String config_PRE_UNITID = PRE_UNITID + "-10"; // total值

		// 获取主机名称
		Vector host = rpctarget.getKPISet("uname -a");
		String host_name = (String) host.elementAt(0);
		String os_version = split((String) host.elementAt(0), 2);
		host_name = collResult.split(host_name, 1);
		host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
//		String pattern = "yyyy-MM-dd-HH-mm-ss";
//		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
//		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
//				"CM-00-01-001-22", dateFormat.format(new java.util.Date()));

		// 常用ip,用于告警标题
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-50", (String) params.get("IP_ADDR"));

		// 主机名称
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-01", host_name);
		// 主机类型
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-03", "HP");
		// ----cpu信息 , CM-00-01-001-04(个数)/05(型号)/06(主频)-----
		Vector cpunumV = rpctarget.getKPISet("ioscan -fnk | grep processor");
		// 1 CM-00-01-001-04 cpu个数
		String cpu_size = String.valueOf(cpunumV.size());
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-04", Formater.formatDecimalKpivalue(cpu_size));

		
		try{
			Vector<String> cputypeV = rpctarget.getKPISet("machinfo");
			for (int j = 0; j < cputypeV.size(); j++) {
				String cpu_info = cputypeV.elementAt(j);
				if (cpu_info.indexOf("processor model:") > -1) {
					String cputype = split(cpu_info, 3) + " " + split(cpu_info, 4) + " " + split(cpu_info, 5) + " " + split(cpu_info, 6) + " " + split(cpu_info, 7);
					// cpu类型
					collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
							"CM-00-01-001-05", cputype);
				}
				if (cpu_info.indexOf("Clock speed") > -1) {
					String cpuHZ = split(cpu_info, 3);
					// cpu频率 MHz
					collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name
							+ "-total", "CM-00-01-001-06", cpuHZ);
				}
				
				// CPU info:
				//   Intel(R) Itanium 2 9100 series processor (1.6 GHz, 24 MB)
				if(cpu_info.trim().startsWith("CPU info:")){
					String nextLine = cputypeV.elementAt(j+1);
					if(nextLine.indexOf("GHz") > 0 && nextLine.indexOf("MB") > 0){
						// cpu类型
						collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
								"CM-00-01-001-05", nextLine.trim().replace("\t", " "));
					}					
				}
				
				if (cpu_info.trim().startsWith("Memory") && cpu_info.indexOf("=")>0) {
					// B.11.23使用
					String phyMemSize = split(cpu_info, 2);
					// 物理内存大小
					collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name
							+ "-total", "CM-00-01-001-07", phyMemSize);
				}
				
				if (cpu_info.trim().startsWith("Memory:")) {
					// HP-UX B.11.31使用
					String phyMemSize = split(cpu_info, 1);
					// 物理内存大小
					collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name
							+ "-total", "CM-00-01-001-07", phyMemSize);
				}
			}
		}catch(Exception e){
			logger.warn("Exception while coll cpu type and cpu clock", e);
		}

		// 1 当前命令是用来查看hp10的, 对于11i,还不知道怎么办
		// http://h50069.www5.hp.com/e-Delivery3/Forum/WebUI/Messages/ShowTopic.aspx?RID=a185f83b-f41d-41ff-8b07-a382e8c93c70
		/*
		 * Vector cpufrequency = rpctarget.getKPISet("echo \"itick_per_usec/D\" |
		 * /usr/bin/adb -k /stand/vmunix /dev/mem"); String cpufrequency1=null;
		 * for(int i=0;i<cpufrequency.size();i++) {
		 * cpufrequency1=cpufrequency1+cpufrequency.elementAt(i); }
		 * 
		 * try{ value = cpufrequency1; record = new TblATO_KPIDETAIL();
		 * record.setCLL_TIME(new java.util.Date());
		 * record.setKPI_ID("CM-00-01-001-06"); record.setKPI_VALUE(value);
		 * record.setUNIT_ID(this.UNIT_ID+":cpufrequency");
		 * config_result.add(record); }catch(Exception e){ e.printStackTrace(); }
		 */
		// ---cpu 信息 , 完成 ---
		
		
		// 主机物理内存大小 CM-00-01-001-07		
//		try{
//			Vector<String> phy_sizeV = rpctarget.getKPISet("dmesg | grep 'Physical:'");
//			if (null == phy_sizeV || phy_sizeV.isEmpty()) {
//				logger.warn("no resultb got with dmesg | grep 'Physical:' ");
//			} else {
//				String phy_sizeInfo = phy_sizeV.elementAt(0);
//				String phy_size = split(phy_sizeInfo, 1);
//				collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total", "CM-00-01-001-07",
//						Formater.formatDecimalKpivalue(phy_size));
//			}
//		}catch(Exception e){
//			logger.warn("Exception while collect memory phyical size", e);
//		}

	

		// 主机操作系统版本 CM-00-01-001-08
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-08", os_version);

		// ----CM-00-01-001-09 内置盘大小--------
		// 这里得到的pe size默认认为是megadata
		// 一下两个命令得到的结果行数一致,分别表示物理设备大小,以及该大小的单位(pe size)
		Vector diskVsize = rpctarget.getKPISet("ioscan -fnkC disk | grep GST");
		float disksize_sum = 0; // 单位PE Size
		for (int i = 0; i < diskVsize.size(); i++) {
			String disksizes = (String) diskVsize.elementAt(i);
			String subds = disksizes.substring(disksizes.indexOf("HP") + 3, disksizes.indexOf("GST"));
			float i_disksize = Float.parseFloat(subds.trim());
			disksize_sum = disksize_sum + i_disksize * 1024;
		}
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-09", Formater.formatDecimalKpivalue(String.valueOf(disksize_sum == 0 ? 139898 : disksize_sum)));
		
//		Vector disksizeV = rpctarget.getKPISet("vgdisplay |grep 'Total PE'");
//		Vector diskpesizeV = rpctarget.getKPISet("vgdisplay |grep 'PE Size'");
//
//		for (int i = 0; i < disksizeV.size(); i++) {
//			String disksizeInfo = (String) disksizeV.elementAt(i);
//			String pesizeInfo = (String) diskpesizeV.elementAt(i);
//
//			String disksize = (String) split(disksizeInfo, 2);
//			int i_disksize = Integer.parseInt(disksize);
//
//			String pesize = (String) split(pesizeInfo, 3);
//			int i_pesize = Integer.parseInt(pesize);
//
//			disksize_sum = disksize_sum + i_disksize * i_pesize;
//		}

		// -----网卡配置,4个kpi CM-00-01-001-02/10/11/12------
		Vector netstatV = rpctarget.getKPISet("netstat -in | grep -v Mtu | grep -v 127.0.0.1 | grep -v none");
		Vector lanscanV = rpctarget.getKPISet("lanscan | grep -v Hardware | grep -v Path");
		// CM-00-01-001-10 系统网络接口数 , lanscan得出的行数
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total", "CM-00-01-001-10", String.valueOf(lanscanV.size()));
		// CM-00-01-001-11 系统网络接口IP地址
		// id 使用 -16 网络
		String net_PRE_UNITID = this.PRE_UNITID + "-16";
		String service_ip = "";
		
		Map ips = new HashMap();
		for (int i = 0; i < netstatV.size(); i++) {
			String netstatInfo = (String) netstatV.elementAt(i);
			String lan_name = split(netstatInfo, 0);
			String ip = split(netstatInfo, 3);
			ips.put(lan_name, ip);
		}
		Map phyaddr = new HashMap();
		Map ipstate = new HashMap();
		for (int j = 0; j < lanscanV.size(); j++) {
			String lancanInfo = (String) lanscanV.elementAt(j);
			String lan_name = split(lancanInfo, 4);
			String phy_address = split(lancanInfo, 1);
			String ip_state = split(lancanInfo, 3);
			phyaddr.put(lan_name, phy_address);
			ipstate.put(lan_name, ip_state);
		}
		Set ipskeys = ips.keySet();
		Object[] arrObj = ipskeys.toArray();
		for (int k = 0; k < arrObj.length; k++) {
			String ipkey = (String) arrObj[k];
			if (phyaddr.get(ipkey) != null) {
				// 系统网络接口IP地址
				collResult.addKPI(net_PRE_UNITID + ":" + neat_host_name + "-" 
						+ Formater.neatenunitid(ipkey), "CM-00-01-001-11", ips.get(ipkey).toString());
				// CM-00-01-001-12 系统网络接口物理地址
				collResult.addKPI(net_PRE_UNITID + ":" + neat_host_name + "-" 
						+ Formater.neatenunitid(ipkey), "CM-00-01-001-12", phyaddr.get(ipkey).toString());
				// 网卡状态
				collResult.addKPI(PRE_UNITID + "-16:" + neat_host_name + "-"
						+ Formater.neatenunitid(ipkey), "FM-00-01-001-03", ipstate.get(ipkey).toString());
				service_ip = service_ip + "," + ips.get(ipkey).toString();
			}
		}
		// 主机(服务)地址 CM-00-01-001-02, 将所有ip地址累加
		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name 
				+ "-total", "CM-00-01-001-02", service_ip.substring(1, service_ip.length()));
		
//		for (int i = 0; i < netstatV.size(); i++) {
//			String netstatInfo = (String) netstatV.elementAt(i);
//			String lan_name = split(netstatInfo, 0);
//			String ip = split(netstatInfo, 3);
//			// 系统网络接口IP地址
//			collResult.addKPI(net_PRE_UNITID + ":" + neat_host_name + "-" 
//					+ Formater.neatenunitid(lan_name), "CM-00-01-001-11", ip);
//			service_ip = service_ip + "," + ip;
//		}
//		// 主机(服务)地址 CM-00-01-001-02, 将所有ip地址累加
//		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name 
//				+ "-total", "CM-00-01-001-02", service_ip.substring(1, service_ip.length()));
//		// CM-00-01-001-12 系统网络接口物理地址
//		for (int i = 0; i < lanscanV.size(); i++) {
//			String lancanInfo = (String) lanscanV.elementAt(i);
//			String lan_name = split(lancanInfo, 4);
//			String phy_address = split(lancanInfo, 1);
//			collResult.addKPI(net_PRE_UNITID + ":" + neat_host_name + "-" 
//					+ Formater.neatenunitid(lan_name), "CM-00-01-001-12", phy_address);
//		}
		
		// 交换分区大小 CM-00-01-001-13
		Vector result_swap = rpctarget.getKPISet("swapinfo -atm ");
		if (result_swap.size() > 0) {
			String value_swap = (String) result_swap.elementAt(result_swap.size() - 1);

			// 交换分区大小
			String swap_size = split(value_swap, 1);
			/*collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name
					+ "-total", "CM-00-01-001-13", Formater.formatDecimalKpivalue(swap_size));*/
			
			collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name
					+ "-total", "CM-00-01-001-13", Formater.formatDecimalKpivalue(swap_size));
			

		}
		/*
		 * // 采集磁盘名称 CM-00-01-001-20 Vector disk = rpctarget .getKPISet("ioscan
		 * -fnkC disk | grep -v 'Description' | grep -v '==' ");
		 */
		// 输出格式
		/*
		 * hpj5000:root:/>ioscan -fnkC disk | grep -v 'Description' | grep -v
		 * '==' disk 0 10/0/14/0.0.0 sdisk CLAIMED DEVICE TEAC CD-532E-B
		 * /dev/dsk/c0t0d0 /dev/rdsk/c0t0d0 disk 2 10/0/15/1.3.0 sdisk CLAIMED
		 * DEVICE FUJITSU MAF3364LCX /dev/dsk/c3t3d0 /dev/rdsk/c3t3d0
		 */
		/*
		 * Vector diskV = this.transMSG(disk);
		 * 
		 * for (int i = 0; i < diskV.size(); i++) { i++; // 只取 2/4/6 偶数行 , , 但
		 * i为奇数
		 * 
		 * String diskInfo = (String) diskV.elementAt(i); // /dev/dsk/c0t0d0 //
		 * /dev/rdsk/c0t0d0 String disk_nameInfo = split(diskInfo, 0); //
		 * /dev/dsk/c0t0d0
		 * 
		 * String disk_name = disk_nameInfo; // 只取 / 后面的名称 if
		 * (disk_nameInfo.indexOf('/') > -1) { disk_name =
		 * disk_nameInfo.substring(disk_nameInfo .lastIndexOf('/') + 1,
		 * disk_nameInfo.length()); } // 磁盘名称 collResult.addKPI(PRE_UNITID +
		 * "-13" + ":" + neat_host_name + "-" +
		 * Formater.neatenunitid(disk_name), "CM-00-01-001-20", disk_name); }
		 */
		// 采集磁盘名称 CM-00-01-001-20 end
		// 逻辑卷名称 与 逻辑卷大小
		// id 使用 -17 逻辑卷与磁盘分开,使用-17
		String lv_PRE_UNITID = this.PRE_UNITID + "-17";
		// modify by wangtaoc 根据集团规范,逻辑卷名称和大小归入total
//		String lv_PRE_UNITID = this.PRE_UNITID + "-10";
		Vector getlvname = rpctarget.getKPISet("vgdisplay -v |grep 'LV Name'");
		Vector getlvsize = rpctarget.getKPISet("vgdisplay -v |grep 'LV Size'");
		if (getlvname != null && getlvsize != null
				&& getlvname.size() == getlvsize.size()) {
			for (int i = 0; i < getlvname.size(); i++) {
				String lvname_info = (String) getlvname.elementAt(i);
				String lv_name = this.split(lvname_info, 2);
				String neat_lv_name = Formater.neatenunitid(lv_name);
				collResult.addKPI(lv_PRE_UNITID + ":" + neat_host_name + "-"
						+ neat_lv_name, "CM-00-01-001-14", lv_name);

				String lvsize_info = (String) getlvsize.elementAt(i);
				String lv_size = this.split(lvsize_info, 3);
				collResult.addKPI(lv_PRE_UNITID + ":" + neat_host_name + "-"
						+ neat_lv_name, "CM-00-01-001-15", Formater
						.formatDecimalKpivalue(lv_size));
			}
		}
		
		// -----文件系统信息-------
		// id 使用 -14
		String fs_PRE_UNITID = this.PRE_UNITID + "-14";
		// 16 CM-00-01-001-16 文件系统名称 文件系统的标识 1天 字符串型
		// 17 CM-00-01-001-17 文件系统的总空间 主机文件系统总的可用量 1天 数值型
		// 文件系统名称 ,并 计算文件系统总空间
//		Vector fileSystemV = rpctarget.getKPISet("df -k ");
		/*
		 * 命令输出格式 /home (/dev/vg00/lvol5 ) : 503824 total allocated Kb 184830
		 * free allocated Kb 318994 used allocated Kb 63 % allocation used /opt
		 * (/dev/vg00/lvol6 ) : 3003217 total allocated Kb 1098531 free
		 * allocated Kb 1904686 used allocated Kb 63 % allocation used
		 * 
		 */
		long fs_sum = 0; // 文件系统总空间,兆
//		for (int i = 0; i < fileSystemV.size(); i += 4) {
//			try {
//				String fsname_info = (String) fileSystemV.elementAt(i);
//				// String fspercent_info = (String)fileSystemV.elementAt(i+3);
//
//				String fs_name = split(fsname_info, 0);
//				// String fs_size = split(fsname_info,4);
//				String fs_size = fsname_info.substring(
//						fsname_info.indexOf(')') + 4,
//						fsname_info.indexOf("total")).trim();
//				// String fs_used_percent = split(fspercent_info,0);
//
//				/**
//				 * * 20090504 New Add huangkai BEGIN
//				 * 解决告警订阅时订阅"/"根导致收到所有此主机文件系统告警 **
//				 */
//				if (fs_name != null && fs_name.trim().equals("/")) {
//					collResult.addKPI(fs_PRE_UNITID + ":" + neat_host_name
//							+ "-" + Formater.neatenunitid("//"), "CM-00-01-001-16", fs_name);
//				} else {
//					collResult.addKPI(fs_PRE_UNITID + ":" + neat_host_name
//							+ "-" + Formater.neatenunitid(fs_name), "CM-00-01-001-16", fs_name);
//				}
//				/** * 20090504 New Add huangkai END ** */
//
//				fs_size = (fs_size == null || fs_size.trim().length() == 0 || fs_size
//						.trim().equals("-")) ? "0" : fs_size.trim();
//				long lfs_size = Long.parseLong(fs_size);
//				fs_sum = fs_sum + lfs_size;
//
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}// end for
		
		Vector fileSystemVTmp = rpctarget.getKPISet("bdf");
		
		Vector fileSystemV = new Vector();

		String vTmp1,vTmp2;
		for(int m0 = 1;m0<fileSystemVTmp.size(); m0++){
			String tmp = (String)fileSystemVTmp.elementAt(m0);
			
			String Vtmp1 = split(tmp, 1);
			if(!(null == Vtmp1 || Vtmp1.equals(null) || "".equals(Vtmp1) || ""==Vtmp1)){
				String Vtmp2 = split(tmp, 5);
				if(!(null == Vtmp2 || Vtmp2.equals(null) || "".equals(Vtmp2) || ""==Vtmp2)){
					fileSystemV.add(tmp);
				}
			}else{
				int kkk = m0+1;
				vTmp2 = ((String)fileSystemVTmp.elementAt(kkk)).trim();
				vTmp1 = tmp +"    "+ vTmp2;
				fileSystemV.add(vTmp1);
			}
		}

		for (int i = 0; i < fileSystemV.size(); i ++) {
			try{
				String fsname_info = (String) fileSystemV.elementAt(i);
				String fs_size = split(fsname_info, 1);
				String fs_name = split(fsname_info, 5);
				
				logger.info("test oh test :"+fs_name+"--"+fs_size+"----"+fsname_info);
				
				if (fs_name != null && fs_name.trim().equals("/")) {
					collResult.addKPI(fs_PRE_UNITID + ":" + neat_host_name
							+ "-" + Formater.neatenunitid("//"), "CM-00-01-001-16", fs_name);
				} else {
					collResult.addKPI(fs_PRE_UNITID + ":" + neat_host_name
							+ "-" + Formater.neatenunitid(fs_name), "CM-00-01-001-16", fs_name);
				}
				
				fs_size = (fs_size == null || fs_size.trim().length() == 0 || fs_size
						.trim().equals("-")) ? "0" : fs_size.trim();
				long lfs_size = Long.parseLong(fs_size);
				fs_sum = fs_sum + lfs_size;
				
			}catch(Exception e){
				e.printStackTrace();
			}
		}

		collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
				"CM-00-01-001-17", Formater.formatDecimalKpivalue(String.valueOf(fs_sum / 1024)));
		// // end -----文件系统信息 ------
		//
		// Vector allDisk = this.getAllDisk(params);
		// collResult.getKPISet().addAll(allDisk);
		
		// cluster状态 cmviewcl -l cluster
		try {
			String cluster_PRE_UNITID = this.PRE_UNITID + "-22";
			Vector clusterInfo = rpctarget.getKPISet("cmviewcl -l cluster");
			if (clusterInfo.size() > 0) {
				for (int i = 0; i < clusterInfo.size(); i++) {
					String lvname_info = (String) clusterInfo.elementAt(i);
					if (lvname_info.trim().length() == 0 || lvname_info.equals("") || lvname_info == null) {
						continue;
					} else if (lvname_info.indexOf("CLUSTER") > -1 || lvname_info.indexOf("STATUS") > -1) {
						continue;
					} else {
						String cluster_name = collResult.split(lvname_info, 0);
						String cluster_state = collResult.split(lvname_info, 1);
						logger.info("lvname_info " + lvname_info);
						// 集群名称
						collResult.addKPI(cluster_PRE_UNITID + ":" + neat_host_name + "-"
								+ Formater.neatenunitid(cluster_name), "CM-00-01-001-18", cluster_name);
						// 集群状态
						collResult.addKPI(cluster_PRE_UNITID + ":" + neat_host_name + "-"
								+ Formater.neatenunitid(cluster_name), "FM-00-01-001-04", cluster_state);
					}
				}
			} else {
				logger.error("user doesn't have access to view the cluster configuration");
			}
			String bin_home = (String) params.get("bin_home");
			String filename = bin_home.replaceAll("bin", "data") + File.separatorChar + "cluster.txt";
			logger.info("filename " + filename);
			File file = new File(filename);
			if (file.exists()) {
				String morecmd = "more " + filename + " | grep -v '^$'";
				Vector fileclusterInfo = rpctarget.getKPISet(morecmd);
				for (int i = 0; i < fileclusterInfo.size(); i++) {
					String cluster_info = (String) fileclusterInfo.elementAt(i);
					if (cluster_info.toUpperCase().indexOf("UP") != -1) {
						String cluster_name = collResult.split(cluster_info, 0);
						String cluster_state = collResult.split(cluster_info, 1);
						// 集群名称
						collResult.addKPI(cluster_PRE_UNITID + ":" + neat_host_name + "-"
								+ Formater.neatenunitid(cluster_name), "CM-00-01-001-18", cluster_name);
						// 集群状态
						collResult.addKPI(cluster_PRE_UNITID + ":" + neat_host_name + "-"
								+ Formater.neatenunitid(cluster_name), "FM-00-01-001-04", cluster_state);
					}
				}
			}
		} catch (Exception e) {
			logger.error(e);
		}

		return collResult.getKPISet();
	}// end getConfig

	/**
	 * 网卡状态放在这个方法里面了
	 * 
	 * @param params
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getCpu(HashMap<String, String> params) {
		logger.info("begin getCpu");
		init(params);

		System.out.println("begin getCPU");
		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-11"开头,代表cpu数据
		String cpu_PRE_UNITID = PRE_UNITID + "-11"; // total值

		System.out.println("coll host name");
		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
//		String pattern = "yyyy-MM-dd-HH-mm-ss";
//		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
//		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
//				"CM-00-01-001-22", dateFormat.format(new java.util.Date()));

		String value = ""; // 临时变量

		Vector cpuout = rpctarget.getKPISet("vmstat 2 10");
		String cpurun = (String) cpuout.elementAt(cpuout.size() - 1);

		// CPU时间:空闲百分比
		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
				"PM-00-01-001-01", Formater.formatDecimalKpivalue(collResult.split(cpurun, 17)));

		// CPU时间:系统百分比
		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
				"PM-00-01-001-02", Formater.formatDecimalKpivalue(collResult.split(cpurun, 16)));

		// CPU时间:用户百分比
		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
				"PM-00-01-001-03", Formater.formatDecimalKpivalue(collResult.split(cpurun, 15)));

		// cpu利用率, 调用后扩的方法
		value = this.getCPU_Rate(3, 30);
		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
				"PM-00-01-001-05", value);

		// CPU运行队列中进程个数
		Vector vmstat_result = rpctarget.getKPISet("vmstat 2 2");
		String vmstat_string = (String) vmstat_result.elementAt(vmstat_result.size() - 1);
		value = collResult.split(vmstat_string, 0);
		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
				"PM-00-01-001-06", Formater.formatDecimalKpivalue(value));

		// // CPU时间:等待百分比
		Vector sar_cpuout = rpctarget.getKPISet("sar -u 2 10");
		String sar_cpurun = (String) sar_cpuout.elementAt(sar_cpuout.size() - 1);
		value = split(sar_cpurun, 3);
		collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
				"PM-00-01-001-04", Formater.formatDecimalKpivalue(value));

		// 网卡状态
//		Vector lan_stateV = rpctarget
//				.getKPISet("lanscan | tail +3 | awk '{print $5,$4}'");
//		if (lan_stateV != null && lan_stateV.size() > 0) {
//			for (int i = 0; i < lan_stateV.size(); i++) {
//				String lan_statInfo = (String) lan_stateV.elementAt(i);
//				String lan_name = split(lan_statInfo, 0);
//				String lan_state = split(lan_statInfo, 1);
//				collResult.addKPI(PRE_UNITID + "-16:" + neat_host_name + "-"
//						+ Formater.neatenunitid(lan_name), "FM-00-01-001-03", lan_state);
//			}
//		}
		 
		return collResult.getKPISet();
	}

	public Vector<TblATO_KPIDETAIL> getDisk(HashMap<String, String> params) {
		return this.getActiveDisk(params);

	}

	/**
	 * 采集当前采集周期内有活动的主机磁盘状态,读写指标 该方法是相对于getAllDisk而言的 每秒磁盘读写请求
	 * PM-00-01-003-04/05现在得到的值为 r+w 在规范磁盘性能指标基础上,增加了FM指标,内置盘状态
	 * 
	 * @param params
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getActiveDisk(HashMap<String, String> params) {
		logger.info("begin getActiveDisk");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-13"开头,代表disk数据
		String disk_PRE_UNITID = PRE_UNITID + "-13";

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
//		String pattern = "yyyy-MM-dd-HH-mm-ss";
//		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
//		collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "",
//				"CM-00-01-001-22", dateFormat.format(new java.util.Date()));

		String value = "";// 临时变量

		// 从出现Average的这行开始,每一行表示一个磁盘的数据
		Vector diskV = rpctarget.getKPISet("sar -d 5 5");
		Set sarDiskSet = new HashSet(); // 保存所有sar命令能取到的io设备名称
		for (int i = 0; i < diskV.size(); i++) {
			String disk_value = (String) diskV.elementAt(i);

			if (disk_value.indexOf("Average") < 0)
				continue;

			String disk_name = split(disk_value, 1);
			sarDiskSet.add(disk_name);

			String neat_disk_name = Formater.neatenunitid(disk_name);

			collResult.addKPI(PRE_UNITID + "-13" + ":" + neat_host_name + "-"
					+ Formater.neatenunitid(disk_name), "CM-00-01-001-20", disk_name);

			// 磁盘物理IO操作速率
			value = split(disk_value, 5);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-01", Formater.formatDecimalKpivalue(value));

			// 等待磁盘系统进程线程数
			value = split(disk_value, 3);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-02", Formater.formatDecimalKpivalue(value));

			// 磁盘忙的百分比
			value = split(disk_value, 2);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-03", Formater.formatDecimalKpivalue(value));

			// 每秒读请求
			value = split(disk_value, 4);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-04", Formater.formatDecimalKpivalue(value));

			// 每秒写请求
			value = split(disk_value, 4);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-05", Formater.formatDecimalKpivalue(value));

		}

		return collResult.getKPISet();
	}

	public Vector<TblATO_KPIDETAIL> getJLSpecProcess(HashMap<String, String> params) {
		logger.info("begin getSpecProcess : " + params.get("PROCESS_NAME"));
		logger.info("begin getSpecProcess : " + params.get("PROCESS_NUM"));

		init(params);
		String process_name = (String) params.get("PROCESS_NAME");
		String process_num = (String) params.get("PROCESS_NUM");

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-10"开头,代表Total数据
		String pro_PRE_UNITID = PRE_UNITID + "-15"; // total值

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		String unit_process = "export UNIX95=XPG4;ps -ef -o pcpu,state,sz,pid,ruser,stime,args | grep '"
				+ process_name + "' | grep -v grep | grep -v '%CPU'";
		Vector proV = rpctarget.getKPISet(unit_process);

		String snum = String.valueOf(proV.size()).trim();
		if (snum.equals(process_num)) {
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
					+ Formater.neatenunitid(process_name), "PM-00-01-005-02",
					"UP");
		} else if (!snum.equals(process_num)) {
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
					+ Formater.neatenunitid(process_name), "PM-00-01-005-03",
					"DOWN");
		}

		return collResult.getKPISet();
	}

	/**
	 * 本类用于获取指定某个进程的各个参数 新建2个kpi PM-00-01-005-07 进程所属用户 PM-00-01-005-02
	 * 如果该进程相关信息不存在,那么直接返回这样一个kpi值DOWN
	 * 
	 * @param params
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getSpecProcess(HashMap<String, String> params) {
		logger.info("begin getSpecProcess : " + params.get("PROCESS_NAME"));

		init(params);
		String process_name = (String) params.get("PROCESS_NAME");

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-10"开头,代表Total数据
		String pro_PRE_UNITID = PRE_UNITID + "-15"; // total值

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		String unit_process = "export UNIX95=XPG4;ps -ef -o pcpu,state,sz,pid,ruser,stime,args | grep \""
				+ process_name + "\" | grep -v grep | grep -v '%CPU'";
	
	/*	String unit_process = "ps -ef -o pcpu,state,sz,pid,ruser,stime,args | grep \""
			+ process_name + "\" | grep -v grep | grep -v '%CPU'";
	
	*/	logger.info("process_name_cmd="+unit_process);
		Vector proV = rpctarget.getKPISet(unit_process);
		if (proV == null || proV.size() == 0) {
			// 不存在该进程
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name), 
					"PM-00-01-005-02", "DOWN");
			return collResult.getKPISet();
		} else {
			for (int i = 0; i < proV.size(); i++) {
				String pro_info = (String) proV.elementAt(i);
				String pcpu = split(pro_info, 0); // 占用cpu时间
				String state = split(pro_info, 1);
				if (state.equals("R")) {
					state = "Running";
				} else if (state.equals("S")) {
					state = "Sleeping";
				} else if (state.equals("0")) {
					state = "Nonexistent";
				} else if (state.equals("W")) {
					state = "Waiting";
				} else if (state.equals("I")) {
					state = "Intermediate";
				} else if (state.equals("Z")) {
					state = "Terminated";
				} else if (state.equals("T")) {
					state = "Stopped";
				} else if (state.equals("X")) {
					state = "Growing";
				}
				String vsz = split(pro_info, 2);
//				String pid = split(pro_info, 3);
//				String puser = split(pro_info, 4);

				String pstime = split(pro_info, 5);
				pstime = pstime.indexOf(":") > -1 ? pstime : pstime + split(pro_info, 6); // 把那种月份+天的时间加上
				int pos_command = pstime.indexOf(":") > 0 ? 6 : 7; // 有冒号就是第6位,没有就是第7位
				String command = split(pro_info, pos_command);
				String full_command = pro_info.substring(pro_info.indexOf(command), pro_info.length());

				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name), 
						"PM-00-01-005-01", Formater.formatDecimalKpivalue(pcpu));
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name),
						"PM-00-01-005-02", state);
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name),
						"PM-00-01-005-03", full_command);
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name),
						"PM-00-01-005-04", pstime);
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name),
						"PM-00-01-005-05", Formater.formatDecimalKpivalue(vsz));
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + Formater.neatenunitid(process_name),
						"PM-00-01-005-07", process_name);
			}
		}

		return collResult.getKPISet();
	}

	/**
	 * 采集占用主机cpu资源的top 15进程,分析cpu占用量趋势
	 */
	public Vector<TblATO_KPIDETAIL> getTopProcess(HashMap<String, String> params) {
		init(params);
		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();
		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);
		String pro_PRE_UNITID = PRE_UNITID + "-16";
		try {
			Vector process = rpctarget.getKPISet("top -h -d 1 -n 15");
			for (int i = 11; i < process.size(); i++) {//去除结果中前10行
				String pro_info = (String) process.elementAt(i);
				if (pro_info.equals(""))
					continue;

				String PID = split(pro_info, 2);
				String USERNAME = split(pro_info, 3);

				String SIZE = split(pro_info, 6);
				String SIZE_VALUE = SIZE.substring(0, SIZE.length() - 1);
				float size = 0f;
				if (SIZE.endsWith("K"))//内存分配量以M为单位
					size = Float.parseFloat(SIZE_VALUE) / 1024;
				else
					size = Float.parseFloat(SIZE_VALUE);

				String RSS = split(pro_info, 7);
				String RSS_VALUE = RSS.substring(0, SIZE.length() - 1);
				float rss = 0f;
				if (RSS.endsWith("K"))//内存占用量以M为单位
					rss = Float.parseFloat(RSS_VALUE) / 1024;
				else
					rss = Float.parseFloat(RSS_VALUE);

				String STATE = split(pro_info, 8);
				String CPU = split(pro_info, 11);
				String PROCESS_NAME = split(pro_info, 12);
                //进程名称
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
						+ PID, "CM-00-01-005-07", PROCESS_NAME);
                //用户名称
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
						+ PID, "CM-00-03-008-016", USERNAME);
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
						+ PID, "PM-00-02-001-17", String.valueOf(size));
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
						+ PID, "PM-00-02-002-14", String.valueOf(rss));
                //进程状态
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
						+ PID, "FM-00-01-002-05", STATE);
				collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
						+ PID, "PM-00-03-009-01", CPU.substring(0, CPU.length() - 1));
			}
		} catch (Exception e) {
			logger.error(e);
		}

		return collResult.getKPISet();
	}

	public void init(HashMap<String, String> params) {
		this.version = (String) params.get("VERSION");

		rpctarget = new RPCTarget();
		rpctarget.setRpcCmd(AgentProperties.AGENT_HOME + "/bin/lexe_hp");
	}

	/**
	 * 
	 * 得到指定精度的double类型数值 精度设定为4
	 * 
	 * @param double_value
	 * @return
	 */
	private String getByScale(String double_value) {
		int scale = 4;
		return Formater.getByScale(double_value, scale);
	}

	/**
	 * 采集所有主机磁盘状态,读写指标 对于当前采集周期非活动的状态为CLAIMED的磁盘,其指标设定默认值 0
	 * 
	 * 每秒磁盘读写请求 PM-00-01-003-04/05现在得到的值为 r+w
	 * 
	 * 在规范磁盘性能指标基础上,增加了FM指标,内置盘状态
	 * 
	 * @param params
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getAllDisk(HashMap<String, String> params) {
		logger.info("begin getAllDisk");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-13"开头,代表disk数据
		String disk_PRE_UNITID = PRE_UNITID + "-13";

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
//		String pattern = "yyyy-MM-dd-HH-mm-ss";
//		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
//		collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "",
//				"CM-00-01-001-22", dateFormat.format(new java.util.Date()));

		String value = "";// 临时变量

		/*
		 * //内置盘状态 Vector otherResult = rpctarget.getKPISet("ioscan -fnkC disk |
		 * tail +3 | grep disk | awk '{print $5}'"); Vector otherResult2 =
		 * rpctarget.getKPISet("ioscan -fnkC disk | tail +3 |grep -v disk | awk
		 * '{print $1}'"); for(int i=0;i<otherResult.size();i++){ String state =
		 * (String)otherResult.elementAt(i); String name =
		 * (String)otherResult2.elementAt(i); collResult.addKPI(disk_PRE_UNITID +
		 * ":" + neat_host_name + "-"+name, "FM-00-01-001-02", state); }
		 */

		// 内置盘状态
		Vector diskState = rpctarget
				.getKPISet("ioscan -fnkC disk | grep -v 'Description' | grep -v '==' ");

		Vector diskStateV = this.transMSG(diskState);
		HashMap disk_stateMap = new HashMap();// 用于存储磁盘名称与磁盘状态。用于后面sar命令中没有得到的磁盘指标附值,hp主机sar命令只采活动io设备
		// 输出格式
		/*
		 * hpj5000:root:/>ioscan -fnkC disk | grep -v 'Description' | grep -v
		 * '==' disk 0 10/0/14/0.0.0 sdisk CLAIMED DEVICE TEAC CD-532E-B
		 * /dev/dsk/c0t0d0 /dev/rdsk/c0t0d0 disk 2 10/0/15/1.3.0 sdisk CLAIMED
		 * DEVICE FUJITSU MAF3364LCX /dev/dsk/c3t3d0 /dev/rdsk/c3t3d0
		 */
		for (int i = 0; i < diskStateV.size(); i = i + 2) {

			String diskInfo1 = (String) diskStateV.elementAt(i); // "disk 0
			// 10/0/14/0.0.0
			// sdisk
			// CLAIMED
			// DEVICE
			// TEAC
			// CD-532E-B"
			String diskInfo2 = (String) diskStateV.elementAt(i + 1); // "/dev/dsk/c0t0d0
			// /dev/rdsk/c0t0d0"

			String disk_state = split(diskInfo1, 4);

			String disk_nameInfo = split(diskInfo2, 0); // /dev/dsk/c0t0d0
			String disk_name = disk_nameInfo;
			// 只取 / 后面的名称
			if (disk_nameInfo.indexOf('/') > -1) {
				disk_name = disk_nameInfo.substring(disk_nameInfo
						.lastIndexOf('/') + 1, disk_nameInfo.length());
			}

			disk_stateMap.put(disk_name, disk_state);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ Formater.neatenunitid(disk_name), "FM-00-01-001-02",
					disk_state);
		}

		// 从出现Average的这行开始,每一行表示一个磁盘的数据
		Vector diskV = rpctarget.getKPISet("sar -d 5 5");
		Set sarDiskSet = new HashSet(); // 保存所有sar命令能取到的io设备名称
		for (int i = 0; i < diskV.size(); i++) {
			String disk_value = (String) diskV.elementAt(i);

			if (disk_value.indexOf("Average") < 0)
				continue;

			String disk_name = split(disk_value, 1);
			sarDiskSet.add(disk_name);

			String neat_disk_name = Formater.neatenunitid(disk_name);

			// 磁盘物理IO操作速率
			value = split(disk_value, 5);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-01", Formater
					.formatDecimalKpivalue(value));

			// 等待磁盘系统进程线程数
			value = split(disk_value, 3);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-02", Formater
					.formatDecimalKpivalue(value));

			// 磁盘忙的百分比
			value = split(disk_value, 2);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-03", Formater
					.formatDecimalKpivalue(value));

			// 每秒读请求
			value = split(disk_value, 4);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-04", Formater
					.formatDecimalKpivalue(value));

			// 每秒写请求
			value = split(disk_value, 4);
			collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
					+ neat_disk_name, "PM-00-01-003-05", Formater
					.formatDecimalKpivalue(value));

		}

		// 给sar命令没有取到的磁盘设备,该设备为CLAIMED状态的情况 附初始值
		Set allDiskSet = disk_stateMap.keySet();
		Iterator iter = allDiskSet.iterator();
		while (iter.hasNext()) {
			String disk_name = (String) iter.next();
			if (sarDiskSet.contains(disk_name)) {
				continue;
			} else {
				if (disk_stateMap.get(disk_name).equals("CLAIMED")) {
					String neat_disk_name = Formater.neatenunitid(disk_name);
					// 磁盘物理IO操作速率
					collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name
							+ "-" + neat_disk_name, "PM-00-01-003-01", "0");
					// 等待磁盘系统进程线程数
					collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name
							+ "-" + neat_disk_name, "PM-00-01-003-02", "0");
					// 磁盘忙的百分比
					collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name
							+ "-" + neat_disk_name, "PM-00-01-003-03", "0");
					// 每秒读请求
					collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name
							+ "-" + neat_disk_name, "PM-00-01-003-04", "0");
					// 每秒写请求
					collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name
							+ "-" + neat_disk_name, "PM-00-01-003-05", "0");
				}

			}
		}

		return collResult.getKPISet();
	}

	private Vector transMSG(Vector vec) {
		Vector vector = new Vector();
		int size = vec.size();
		String tmp = "";

		for (int i = 0; i < size; i++) {
			String msg_1 = (String) vec.elementAt(i);
			if (msg_1.indexOf("/dev/dsk") != -1
					&& tmp.indexOf("/dev/dsk") != -1) {
				continue;
			}
			vector.addElement(msg_1);
			tmp = msg_1;
		}
		return vector;
	}

	// 采集cpu利用率,共采集times次,每次采集间隔interval秒
	private String getCPU_Rate(int times, int interval) {
		CollBase collResult = new CollBase();
		float cpu_value = 0;
		for (int i = 0; i < times; i++) {
			Vector cpuout = rpctarget.getKPISet("vmstat 1 3");
			String cpurun = (String) cpuout.elementAt(cpuout.size() - 1);
			cpu_value = (100 - Integer.parseInt(collResult.split(cpurun, 17))) + cpu_value;
			try {
				Thread.sleep(interval * 1000L);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		cpu_value = cpu_value / times;
		return Formater.formatDecimalKpivalue(Float.toString(cpu_value));
	}
	
//	执行命令开始
	private Vector execute(String shellCommand) {
		logger.info("cmd: " + shellCommand);
		Vector vResult = null;
		try {
			Process process = Runtime.getRuntime().exec(shellCommand);
			vResult = new Vector();
			BufferedReader reader = null;
			reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
			String line = reader.readLine();
			while (line != null) {
				if (shellCommand.indexOf("cqitsm") > 0) {
					logger.info("line: " + line);
				}
				logger.info("cmd:"+shellCommand+":"+line);
				vResult.addElement(line);
				line = reader.readLine();
			}
			
			int err = process.waitFor();
			if (err == 1) { // 有异常
				String lin = "";
				InputStreamReader ir = new InputStreamReader(process.getErrorStream());
				LineNumberReader input = new LineNumberReader(ir);
				String sb = "";
				while ((lin = input.readLine()) != null) {
					sb += lin + "\n";
				}
				 logger.error("Command result is :[" + shellCommand + "] Error<\n" + sb + ">");
				input.close();
			}
			reader.close();
			return vResult;
			
		} catch (Exception e) {
			logger.error("在本机上可能没有 " + shellCommand + " 命令!");
		} finally {
			Runtime.getRuntime().freeMemory();
			Runtime.getRuntime().gc();
		}
		return vResult;
	}
	
	public Vector<TblATO_KPIDETAIL> getAllProcess(HashMap<String, String> params){
		logger.info("begin getAllDisk");
		init(params);
		String pro_PRE_UNITID = PRE_UNITID + "-15"; // total值
		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		String unit_process = "export UNIX95=XPG4;ps -ef -o pcpu,state,sz,pid,ruser,stime,args | grep -v '%CPU'";
	
	/*	String unit_process = "ps -ef -o pcpu,state,sz,pid,ruser,stime,args | grep \""
			+ process_name + "\" | grep -v grep | grep -v '%CPU'";
	
	*/	logger.info("process_name_cmd="+unit_process);
		Vector proV = rpctarget.getKPISet(unit_process);
		for (int i = 0; i < proV.size(); i++) {
			String pro_info = (String) proV.elementAt(i);
			String pcpu = split(pro_info, 0); // 占用cpu时间
			String state = split(pro_info, 1);
			if (state.equals("R")) {
				state = "Running";
			} else if (state.equals("S")) {
				state = "Sleeping";
			} else if (state.equals("0")) {
				state = "Nonexistent";
			} else if (state.equals("W")) {
				state = "Waiting";
			} else if (state.equals("I")) {
				state = "Intermediate";
			} else if (state.equals("Z")) {
				state = "Terminated";
			} else if (state.equals("T")) {
				state = "Stopped";
			} else if (state.equals("X")) {
				state = "Growing";
			}
			String vsz = split(pro_info, 2);
			String pid = split(pro_info, 3);
	 		String puser = split(pro_info, 4);

			String pstime = split(pro_info, 5);
			pstime = pstime.indexOf(":") > -1 ? pstime : pstime + split(pro_info, 6); // 把那种月份+天的时间加上
			int pos_command = pstime.indexOf(":") > 0 ? 6 : 7; // 有冒号就是第6位,没有就是第7位
			String command = split(pro_info, pos_command);
			String full_command = pro_info.substring(pro_info.indexOf(command), pro_info.length());

			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + i, 
					"TM-00-01-005-01", Formater.formatDecimalKpivalue(pcpu));
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" +i,
					"TM-00-01-005-02", state);
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + i,
					"TM-00-01-005-03", full_command);
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + i,
					"TM-00-01-005-04", pstime);
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" +i,
					"TM-00-01-005-05", Formater.formatDecimalKpivalue(vsz));
			/*collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + i,
					"TM-00-01-005-07", ""+i);*/
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + i,
					"TM-00-01-005-08", pid);
			collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-" + i,
					"TM-00-01-005-09", puser);
			
		}
		return collResult.getKPISet();
	}
	
	// 采集Syslog
	public Vector<TblATO_KPIDETAIL> getSyslog(HashMap<String, String> params) {
		logger.info("begin getSyslog ");
		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();
		String host_ip = (String) params.get("IP_ADDR");
		String data_path = (String) params.get("bin_home");
		String now_filename = "now_" + host_ip + ".dat";
		String tmp_filename = "tmp_" + host_ip + ".dat";
		String diff_filename = "diff_" + host_ip + ".dat";
		try {
			init(params);
			String syslogcmd = "grep -E 'EMS|err' /var/adm/syslog/syslog.log | sed -n \"1,1000p\"";
			
			Vector syslogV = rpctarget.getKPISet(syslogcmd);
			String now = this.getVetorString(syslogV);
			
			File now_file = new File(data_path + now_filename);// 最新日志信息
			File tmp_file = new File(data_path + tmp_filename);// 上周期日志信息
			File diff_file = new File(data_path + diff_filename);// 增量日志
			PrintWriter write_now = new PrintWriter(new OutputStreamWriter(
					new FileOutputStream(now_file), "GB2312"));
			PrintWriter write_tmp = new PrintWriter(new OutputStreamWriter(
					new FileOutputStream(tmp_file, true), "GB2312"));
			PrintWriter write_diff = new PrintWriter(new OutputStreamWriter(
					new FileOutputStream(diff_file), "GB2312"));
			String path = now_file.getAbsolutePath();
			logger.info("Current path is " + path);
			// 日志解析
			if (tmp_file.exists() && tmp_file.length() > 0) {// 非第一次采集
				write_now.write(now);
				write_now.flush();
				write_now.close();
				// 读取上周期日志文件(tmp)
				FileReader tmp_reader = new FileReader(tmp_file);
				BufferedReader tmp = new BufferedReader(tmp_reader);
				String line;
				String tmp_file_string = "";
				while ((line = tmp.readLine()) != null) {
					tmp_file_string += line + "\n";
				}
				tmp.close();
				tmp_reader.close();
				// 读取本周期日志文件(now),生成差异文件(diff)
				FileReader now_reader = new FileReader(now_file);
				BufferedReader br = new BufferedReader(now_reader);
				while ((line = br.readLine()) != null) {
					if (tmp_file_string.indexOf(line) == -1)
						write_diff.write(line);
					else
						continue;
				}
				br.close();
				now_reader.close();
				write_diff.flush();
				write_diff.close();
				write_tmp = new PrintWriter(new OutputStreamWriter(
						new FileOutputStream(tmp_file), "GB2312"));
				write_tmp.write(now);
				write_tmp.flush();
				write_tmp.close();
			} else {// 第一次采集
				write_tmp.write(now);
				write_tmp.flush();
				write_tmp.close();
				write_diff.write(now);
				write_diff.flush();
				write_diff.close();
			}
			// 生成指标
			FileReader diff_reader = new FileReader(diff_file);
			BufferedReader diff = new BufferedReader(diff_reader);
			String line1;
			// 获取主机名称
			String host_name = this.getHostName(params);
			// 得到unit_id中使用的主机名称
			String neat_host_name = Formater.neatenunitid(host_name);
			int j=0;
			//限制为10条
			while ((line1 = diff.readLine()) != null&&j<10) {
			/*	String value1 = "err";
				String value2 = (line1.split("Value:"))[1];
				String[] value3_m = ((line1.split(":"))[2]).split(" ");
				String value3 = value3_m[2] + value3_m[3];
				String[] value4_m = line1.split(" ");
				String value4 = value4_m[0] + value4_m[1] + value4_m[2];*/
				String unitid = "10-10-21-20:" + neat_host_name + "-syslog-"
						+ j;
				collResult.addKPI(unitid, "FM-00-01-900-04", line1);
				collResult.addKPI(unitid, "CM-00-01-900-03", "err");
				j++;
			}
			diff.close();
			diff_reader.close();
		} catch (Exception e) {
			e.getMessage();
			e.printStackTrace();
		} finally {
			
		}
		return collResult.getKPISet();
	}
	
	/**
	 * 新增时钟同步信息KPI信息
	 * PM-00-01-006-01	远程服务器名称
	 * PM-00-01-006-03	远程服务器级别
	 * PM-00-01-006-04	请求间隔
	 * PM-00-01-006-05	同步频率
	 * PM-00-01-006-07	循环时间
	 * PM-00-01-006-08	时间偏移量
	 * PM-00-01-006-09	时间精确度
	 * */
	public Vector<TblATO_KPIDETAIL> getClockInfo(HashMap<String, String> params){
		
		logger.info("begin getClockInfo");
		init(params);

		// 保存采集结果,并返回值
		CollBase collResult = new CollBase();

		// 本方法得到的kpi值的unit_id,均以PRE_UNITID + "-24"开头
		String ntpq_PRE_UNITID = PRE_UNITID + "-24";

		// 获取主机名称
		String host_name = this.getHostName(params);
		// 得到unit_id中使用的主机名称
		String neat_host_name = Formater.neatenunitid(host_name);

		// 增加采集时间指标
		String pattern = "yyyy-MM-dd-HH-mm-ss";
		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
		
		Vector ntpqV = rpctarget.getKPISet("/usr/sbin/ntpq -p ");
		String remoteName,remoteST,lastWhen,poll,delay,offset,jitter;
		if (ntpqV != null && ntpqV.size() > 0) {
			for (int i = 2; i < ntpqV.size(); i++){
				logger.info("into getClockInfo"+(String) ntpqV.elementAt(i));
				String strTmp = (String) ntpqV.elementAt(i);
				remoteName = split(strTmp, 0);		//远程服务器名
				remoteST = split(strTmp, 2);		//服务器级别
				lastWhen = split(strTmp, 4);		//请求间隔
				poll = split(strTmp, 5);			//同步频率
				delay = split(strTmp, 7);			//循环时间
				offset = split(strTmp, 8);			//时间偏移量
				jitter = split(strTmp, 9);			//时间精确度
				logger.info("into my getClockInfo"+remoteName + "--"+ remoteST + "--" + lastWhen + "--" + poll + "--" + delay + "--" + offset + "--" + jitter);
				
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-01", remoteName);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-03", remoteST);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-05", lastWhen);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-06", poll);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-08", delay);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-09", offset);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"PM-00-01-006-10", jitter);
				collResult.addKPI(ntpq_PRE_UNITID+ ":" + neat_host_name + "-ntpq"+i,
						"CM-00-01-001-99", dateFormat.format(new java.util.Date()));
			}
		}
		return collResult.getKPISet();
	}
	
	public String getVetorString(Vector v){
		StringBuffer sb = new StringBuffer();
		if(v!=null&&v.size()>0){
			for(int i=0;i<v.size();i++){
				String s = (String)v.get(i);
				if(s!=null&&i<v.size()-1){
					sb.append(s+"\n");
				}
			}
		}
		return sb.toString();
	}

}