GXCollTuxedo.java 15.8 KB
package com.sitech.ismp.coll.tivoli;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.Formater;

/*
 * ibm所提供的以 UA 插件 使用shell脚本方式采集Tuxedo的方式
 * 
 * IBM出来的是原始数据,IBM将原始数据直接入到它库里丢失了部分标识[咨询过tuxedo专家]
 * 
 * 所以,目前该类暂不启用
 * 
 */
public class GXCollTuxedo implements GXCollTuxedoMBean {

	private boolean debug=false;
	private SoapClient soapClient =null;

	private String pre_unitid="10-12-12"; //Tuxedo标识
	
	public GXCollTuxedo()
	{
		String url=SoapParam.getString("SOAP_URL");
		soapClient = new SoapClient(url);
	}	
	
	public Vector getPerformance(java.util.HashMap params) throws Exception
	{
		String host_name=(String)params.get("HOST_NAME"); 
		String ip_addr=(String)params.get("IP_ADDR");
		String neat_host_name = Formater.neatenunitid(host_name);
		//String KBP_ID = this.KBP_ID+"-11"+":"+NEATENSID+"-TABLESPACES";
		Vector collResult = new Vector();
		//返回结果为param_name , param_value 类型, 单实例
		String kpi_node="BBSTATS";
		String value_node="MetricValue";
		String time_node="LocalTimeStamp";				
		
		/**
		 * PM-00-04-001-01	客户端连接的队列个数	交易中间件用于响应客户端请求的进程队列个数
		 * PM-00-04-001-02	服务个数	交易中间件提供的服务的总数
		 * lianlian 2006-09-11
		 * BBSTATS		MetricValue		LocalTimeStamp
		 * @param host_name
		 * @return
		 */
		//得到soap请求
		String soap_performance_TUXEDOBBSTATS00 = GXCollTuxedoSoapHelper.getSoap_performance_TUXEDOBBSTATS00(host_name);  //soap消息
		//发送soap请求,并返回结果
		String soap_performance_TUXEDOBBSTATS00_res = soapClient.getSoapStringResponse(soap_performance_TUXEDOBBSTATS00);
		//分析返回结果,得到list
		//List TUXEDOBBSTATS00_res_results = CollTuxedoXmlHelper.parseParamsSoapResponse(soap_performance_TUXEDOBBSTATS00_res,kpi_node,value_node, time_node);		
		List TUXEDOBBSTATS00_res_results = CollTuxedoXmlHelper.parseCommonSoapResponse(soap_performance_TUXEDOBBSTATS00_res);
		if( TUXEDOBBSTATS00_res_results == null || TUXEDOBBSTATS00_res_results.size()==0){
			System.out.println("@tivoli error, no TUXEDOBBSTATS00_res_results info got by tivoli  "+new Date());
		}else{	
			//tivoli名称与规范kpi名称的映射关系
			Map kpiMap = new java.util.HashMap();
			kpiMap.put("Current number of request queues","PM-00-04-001-01");
			kpiMap.put("Current number of servers","PM-00-04-001-02");
			String unit_id=pre_unitid+"-11:"+ip_addr+"-"+neat_host_name;
			for(int i=0; i<TUXEDOBBSTATS00_res_results.size(); i++)
			{
				Map resultMap = (Map)TUXEDOBBSTATS00_res_results.get(i);
				String bbstats = (String)resultMap.get("BBSTATS");
				String metricvalue = (String)resultMap.get("MetricValue");
				String cll_time = (String)resultMap.get("LocalTimeStamp");
				bbstats = bbstats.replaceAll(" ","");
				if(bbstats.equalsIgnoreCase("Currentnumberofrequestqueues"))
				{
					this.setResult(collResult,  unit_id,  "PM-00-04-001-01" ,  metricvalue, this.parseTime(cll_time));
				}
				else if(bbstats.equalsIgnoreCase("Currentnumberofservices"))
				{
					this.setResult(collResult,  unit_id,  "PM-00-04-001-02" ,  metricvalue, this.parseTime(cll_time));
				}
				
				/*String[] kpidetail = (String[])TUXEDOBBSTATS00_res_results.get(i);
				String tivoli_kpi_name  = kpidetail[0].trim();
				String kpi_value = kpidetail[1];
				String cll_time  = kpidetail[2];
				
				String kpi_id= (String)kpiMap.get(tivoli_kpi_name);
				if(kpi_id!=null)
				{
					//
					String unit_id=pre_unitid+"-11:"+ip_addr+"-"+neat_host_name;
					this.setResult(collResult,  unit_id,  kpi_id ,  kpi_value, this.parseTime(cll_time));
				}
				*/
			}			
		}
		/**
		 * PM-00-04-01-03	队列等待数	交易中间件工作队列排队数		ProgramName		QueueName		WorkQueued		MachineName
		 * PM-00-04-01-04	进程队列中消息个数	应用进程队列中消息个数	ProgramName		QueueName		NumQueued		MachineName
		 * FM-00-04-01-03	客户端连接的队列个数	交易中间件用于响应客户端请求的进程队列个数	ProgramName		QueueName		WorkQueued		MachineName
		 * lianlian 2006-09-11
		 */
		//返回结果为普通类型,多实例
		//得到soap请求
		String soap_performance_TUXEDOQUEUESINFO00 = GXCollTuxedoSoapHelper.getSoap_performance_TUXEDOQUEUESINFO00(host_name);  //soap消息
		//发送soap请求,并返回结果
		String soap_performance_TUXEDOQUEUESINFO00_res = soapClient.getSoapStringResponse(soap_performance_TUXEDOQUEUESINFO00);
		//分析返回结果,得到list
		List TUXEDOQUEUESINFO00_results = CollTuxedoXmlHelper.parseCommonSoapResponse(soap_performance_TUXEDOQUEUESINFO00_res);		
		if( TUXEDOQUEUESINFO00_results == null || TUXEDOQUEUESINFO00_results.size()==0){
			System.out.println("@tivoli error, no TUXEDOQUEUESINFO00_results info got by tivoli in collCpu "+new Date());
		}else{	
			for(int i=0; i<TUXEDOQUEUESINFO00_results.size(); i++){
				Map rowMap = (Map)TUXEDOQUEUESINFO00_results.get(i);
				String WorkQueued = (String)rowMap.get("WorkQueued");
				String NumQueued = (String)rowMap.get("NumQueued");
				String ProgramName = (String)rowMap.get("ProgramName");
				String LocalTimeStamp = (String)rowMap.get("LocalTimeStamp");
				String neatProgramName = Formater.neatenunitid(ProgramName);
				String unit_id=pre_unitid+"-12:"+ip_addr+"-"+neatProgramName;
				//System.out.println(unit_id);
				this.setResult(collResult,unit_id,"PM-00-04-001-03",WorkQueued,this.parseTime(LocalTimeStamp));
				this.setResult(collResult,unit_id,"FM-00-04-001-03",WorkQueued,this.parseTime(LocalTimeStamp));
				this.setResult(collResult,unit_id,"PM-00-04-001-04",NumQueued,this.parseTime(LocalTimeStamp));
			}						
		}
		
		/**
		 * PM-00-04-001-05	应用进程负载	每个应用进程得到数据的服务调用的次数
		 * FM-00-04-001-02	中间件可用性	中间件代理服务是否正常启动并处于可用状态
		 * lianlian 2006-09-11
		 */
		//返回结果为普通类型,多实例
		//得到soap请求
		String soap_performance_TUXEDOSERVERPROCINFO00= GXCollTuxedoSoapHelper.getSoap_performance_TUXEDOSERVERPROCINFO00(host_name);  //soap消息
		//发送soap请求,并返回结果
		String soap_performance_TUXEDOSERVERPROCINFO00_res = soapClient.getSoapStringResponse(soap_performance_TUXEDOSERVERPROCINFO00);
		//分析返回结果,得到list
		List TUXEDOSERVERPROCINFO00_results = CollTuxedoXmlHelper.parseCommonSoapResponse(soap_performance_TUXEDOSERVERPROCINFO00_res);		
		if( TUXEDOSERVERPROCINFO00_results == null || TUXEDOSERVERPROCINFO00_results.size()==0){
			System.out.println("@tivoli error, no TUXEDOSERVERPROCINFO00_results info got by tivoli in collCpu "+new Date());
		}else{	
			for(int i=0; i<TUXEDOSERVERPROCINFO00_results.size(); i++){
				Map rowMap = (Map)TUXEDOSERVERPROCINFO00_results.get(i);
				String CurrentService = (String)rowMap.get("CurrentService");
				String RequestDone = (String)rowMap.get("RequestDone");
				String ProgramName = (String)rowMap.get("ProgramName");
				String LocalTimeStamp = (String)rowMap.get("LocalTimeStamp");
				String neatProgramName = Formater.neatenunitid(ProgramName);
				String unit_id=pre_unitid+"-12:"+ip_addr+"-"+neatProgramName;
				//System.out.println(unit_id);
				this.setResult(collResult,unit_id,"FM-00-04-001-02",CurrentService,this.parseTime(LocalTimeStamp));
				this.setResult(collResult,unit_id,"PM-00-04-001-05",RequestDone,this.parseTime(LocalTimeStamp));	
			}						
		}		
		
		/**
		 * PM-00-04-01-06	客户端活动连接数	正在执行操作的客户端连接个数		ClientName
		 * lianlian 2006-09-11
		 */
		String Soap_performance_TUXEDOCLIENTSPROCINFO00 = GXCollTuxedoSoapHelper.getSoap_performance_TUXEDOCLIENTSPROCINFO00(host_name);
		String Soap_performance_TUXEDOCLIENTSPROCINFO00_res = soapClient.getSoapStringResponse(Soap_performance_TUXEDOCLIENTSPROCINFO00);
		List TUXEDOCLIENTSPROCINFO00_result = CollTuxedoXmlHelper.parseCommonSoapResponse(Soap_performance_TUXEDOCLIENTSPROCINFO00_res);
		
		if( TUXEDOCLIENTSPROCINFO00_result == null || TUXEDOCLIENTSPROCINFO00_result.size()==0)
		{
			System.out.println("@tivoli error, no TUXEDOCLIENTSPROCINFO00_result info got by tivoli in collCpu "+new Date());
		}
		else
		{	
			for(int i=0; i<TUXEDOCLIENTSPROCINFO00_result.size(); i++)
			{
				Map rowMap = (Map)TUXEDOCLIENTSPROCINFO00_result.get(i);
				String ClientName = (String)rowMap.get("ClientName");
				String LocalTimeStamp = (String)rowMap.get("LocalTimeStamp");
				String unit_id=pre_unitid+"-12:"+ip_addr+"-"+neat_host_name;
				this.setResult(collResult,unit_id,"PM-00-04-001-06",ClientName,this.parseTime(LocalTimeStamp));
			}						
		}	
	/**
	 * FM-00-04-001-01	应用服务状态(可选)	服务是否正常启动并处于可用状态
	 * lianlian 2006-09-11
	 */
		String Soap_performance_TUXEDOPRINTSERVICE00 = GXCollTuxedoSoapHelper.getSoap_performance_TUXEDOPRINTSERVICE00(host_name);
		String Soap_performance_TUXEDOPRINTSERVICE00_res = soapClient.getSoapStringResponse(Soap_performance_TUXEDOPRINTSERVICE00);
		List TUXEDOPRINTSERVICE00_result = CollTuxedoXmlHelper.parseCommonSoapResponse(Soap_performance_TUXEDOPRINTSERVICE00_res);
		
		if( TUXEDOPRINTSERVICE00_result == null || TUXEDOPRINTSERVICE00_result.size()==0)
		{
			System.out.println("@tivoli error, no TUXEDOPRINTSERVICE00_result info got by tivoli in collCpu "+new Date());
		}
		else
		{	
			for(int i=0; i<TUXEDOPRINTSERVICE00_result.size(); i++)
			{
				Map rowMap = (Map)TUXEDOPRINTSERVICE00_result.get(i);
				String ProgramName = (String)rowMap.get("ProgramName");
				String Status = (String)rowMap.get("Status");
				String LocalTimeStamp = (String)rowMap.get("LocalTimeStamp");
				String neatProgramName = Formater.neatenunitid(ProgramName);
				String unit_id=pre_unitid+"-12:"+ip_addr+"-"+neatProgramName;
				this.setResult(collResult,unit_id,"FM-00-04-001-01",Status,this.parseTime(LocalTimeStamp));
			}						
		}	
		
		return collResult;
	}
	
	public Vector getConfiguration(java.util.HashMap params) throws Exception{
		
		String host_name	=(String)params.get("HOST_NAME");// AS A PART OF TIVOLI SOAP MSG, AND UNIT_ID 
		String ip_addr		=(String)params.get("IP_ADDR");  // NOUSE , JUST AS A PART OF UNIT_ID
		
		String neat_host_name = Formater.neatenunitid(host_name);
		
		//String KBP_ID = this.KBP_ID+"-11"+":"+NEATENSID+"-TABLESPACES";
		
		Vector collResult = new Vector();
		
		
		/**
		 * CM-00-04-01-03	中间件的系统日志路径	中间件的系统日志路径
		 * CM-00-04-01-04	中间件的用户日志路径	中间件的用户日志路径
		 * lianlian 2006-09-11
		 */
		String Soap_configuration_TSAINFOLOGPATH00 = GXCollTuxedoSoapHelper.getSoap_configuration_TSAINFOLOGPATH00(host_name);
		String Soap_configuration_TSAINFOLOGPATH00_res = soapClient.getSoapStringResponse(Soap_configuration_TSAINFOLOGPATH00);
		List TSAINFOLOGPATH00_result = CollTuxedoXmlHelper.parseCommonSoapResponse(Soap_configuration_TSAINFOLOGPATH00_res);
		
		if( TSAINFOLOGPATH00_result == null || TSAINFOLOGPATH00_result.size()==0)
		{
			System.out.println("@tivoli error, no TSAINFOLOGPATH00_result info got by tivoli  "+new Date());
		}
		else
		{
			for(int i=0; i<TSAINFOLOGPATH00_result.size(); i++)
			{
				Map rowMap = (Map)TSAINFOLOGPATH00_result.get(i);
				String SysLogPath = (String)rowMap.get("SysLogPath");
				String UserLogPath = (String)rowMap.get("UserLogPath");
				String unit_id=pre_unitid+"-12:"+ip_addr+"-"+neat_host_name;
				this.setResult(collResult,unit_id,"CM-00-04-001-03",SysLogPath,new Date());
				this.setResult(collResult,unit_id,"CM-00-04-001-04",UserLogPath,new Date());
			}			
		}
		
		/**
		 * CM-00-04-001-01	中间件最大并发连接数	与数据库连接数
		 * CM-00-04-001-02	中间件最大并发网络客户端数量	与客户端连接数
		 * lianlian 2006-09-11
		 * BBPARMS		MetricValue		LocalTimeStamp
		 */
		String soap_configuration_TUXEDOBBPARAMS00 = GXCollTuxedoSoapHelper.getSoap_configuration_TUXEDOBBPARAMS00(host_name);  //soap消息
		String soap_configuration_TUXEDOBBPARAMS00_res = soapClient.getSoapStringResponse(soap_configuration_TUXEDOBBPARAMS00);
		//分析返回结果,得到list
		String kpi_node="BBPARMS";
		String value_node="MetricValue";
		String time_node="LocalTimeStamp";		
		String unit_id=pre_unitid+"-11:"+ip_addr+"-"+neat_host_name;
		//List configuration_TUXEDOBBPARAMS00_results = CollTuxedoXmlHelper.parseParamsSoapResponse(soap_configuration_TUXEDOBBPARAMS00_res,kpi_node,value_node, time_node);
		List configuration_TUXEDOBBPARAMS00_results = CollTuxedoXmlHelper.parseCommonSoapResponse(soap_configuration_TUXEDOBBPARAMS00_res);
		if( configuration_TUXEDOBBPARAMS00_results == null || configuration_TUXEDOBBPARAMS00_results.size()==0){
			System.out.println("@tivoli error, no configuration_TUXEDOBBPARAMS00_results info got by tivoli in collCpu "+new Date());
		}
		else
		{
			for(int i=0;i<configuration_TUXEDOBBPARAMS00_results.size(); i++)
			{
				Map resultMap = (Map)configuration_TUXEDOBBPARAMS00_results.get(i);
				String bbparms = (String)resultMap.get("BBPARMS");
				String metricvalue = (String)resultMap.get("MetricValue");
				String cll_time = (String)resultMap.get("LocalTimeStamp");
				if(bbparms.equalsIgnoreCase("MAXSERVERS"))
				{
					this.setResult(collResult,  unit_id,  "CM-00-04-001-01" ,  metricvalue, this.parseTime(cll_time));
				}
				else if(bbparms.equalsIgnoreCase("MAXACCESSERS"))
				{
					this.setResult(collResult,  unit_id,  "CM-00-04-001-02" ,  metricvalue, this.parseTime(cll_time));
				}
			}
			//tivoli名称与规范kpi名称的映射关系
			/*
			Map kpiMap = new java.util.HashMap();
			kpiMap.put("MAXSERVERS","CM-00-04-001-01");
			kpiMap.put("MAXACCESSERS","CM-00-04-001-02");
			
			for(int i=0; i<configuration_TUXEDOBBPARAMS00_results.size(); i++){
				String[] kpidetail = (String[])configuration_TUXEDOBBPARAMS00_results.get(i);
				String tivoli_kpi_name  = kpidetail[0].trim();
				String kpi_value = kpidetail[1];
				String cll_time  = kpidetail[2];
				
				String kpi_id= (String)kpiMap.get(tivoli_kpi_name);
				if(kpi_id!=null){
					String unit_id=pre_unitid+"-11:"+ip_addr+"-"+neat_host_name;
					this.setResult(collResult,  unit_id,  kpi_id ,  kpi_value, this.parseTime(cll_time));
				}
			}		*/
		}
		
		return collResult;
	}	
	
	/**
	 * tivoli的时间格式为1060628143502000
	 * 代表 2006-06-28 14-35-50
	 * 替换为思特奇的自己规定的时间格式
	 * @param tivoli_time
	 * @return
	 */
	public Date parseTime(String tivoli_time){
		String tmp = tivoli_time;			//1060628143502000
		tmp = tmp.substring(1,tmp.length());//060628143502000
		tmp = "20"+tmp;//20060628143502000
		tmp = tmp.substring(0,tmp.length()-3);//20060628143502
		String pattern = "yyyyMMddHHmmss";
		SimpleDateFormat dateFormat = new SimpleDateFormat( pattern);
		
		Date cll_time= new Date();
		try{
			cll_time= dateFormat.parse(tmp);
		}catch(Exception e){
			e.printStackTrace();
		}
		

		return cll_time;
	}
	
	private void setResult(Vector result,  String unitID, String kpiID , String value,Date cll_time) {
		try {
			TblATO_KPIDETAIL record;

			record = new TblATO_KPIDETAIL();
			record.setCLL_TIME(new Date());
			record.setKPI_ID(kpiID);
			record.setKPI_VALUE(value);
			record.setUNIT_ID(unitID);
			record.setCLL_TIME(cll_time);
			result.add(record);
		} catch (Exception e) {

			e.printStackTrace();
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		GXCollTuxedo collTuxedo = new GXCollTuxedo();
		java.util.HashMap params = new java.util.HashMap();
		
		//params.put("HOST_NAME","AS1");
		params.put("HOST_NAME","AS1");
		params.put("IP_ADDR","10.110.x.x");
		
		Vector v1 = collTuxedo.getConfiguration(params);
		Vector v2 = collTuxedo.getPerformance(params);
		
		String temp[][] = CheckKPIHelper.Check_Tuxedo_KPI(v1);
		for(int i=0;i<temp.length;i++)
		{
			System.out.println("KPI_ID : " + temp[i][0] + "---" + temp[i][1]);
		}
		

	}

}