CollOracle.java 9.64 KB
package com.sitech.ismp.coll;

import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
import com.sitech.util.JSONUtil;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;

public class CollOracle implements CollOracleMBean {
    private Logger logger = Logger.getLogger(CollOracle.class);

	@Override
	public Vector<TblATO_KPIDETAIL> getCMStandKPI(HashMap<String, String> params) {
		try {
			CollOracleBySql collector = new CollOracleBySql();
			return collector.getCMStandKPI(params);
		} catch (Exception e) {
			logger.error("Exception while getCMStandKPI", e);
			return new Vector<TblATO_KPIDETAIL>();
		}
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getDataFile(HashMap<String, String> params) {
		try {
			CollOracleBySql collector = new CollOracleBySql();
			return collector.getDataFile(params);
		} catch (Exception e) {
			logger.error("Exception while getDataFile", e);
			return new Vector<TblATO_KPIDETAIL>();
		}
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getExtendKPI(HashMap<String, String> params) {
		try {
			return  new CollOracleBySql().getExtendKPI(params);
		} catch (Exception e) {
			throw new RuntimeException("Exception while getExtendKPI,params=" + JSONUtil.toJSON(params), e);
		}
	}

    //全库数据量 CM-00-03-006-02 单位G  1个月一次
    public Vector<TblATO_KPIDETAIL> getTotalData(HashMap<String, String> params) {
        try {
            return  new CollOracleBySql().getTotalData(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getTotalData,params=" + JSONUtil.toJSON(params), e);
        }
    }

//    //数据库Headroom时间 PM-00-03-009-10   ASM归档磁盘组  PM-00-03-001-05
//    public Vector<TblATO_KPIDETAIL> getAsmHeadroom(HashMap<String, String> params) {
//        try {
//            return  new CollOracleBySql().getAsmHeadroom(params);
//        } catch (Exception e) {
//            throw new RuntimeException("Exception while getAsmHeadroom,params=" + JSONUtil.toJSON(params), e);
//        }
//    }

    // 数据库Headroom时间 PM-00-03-009-10
    public Vector<TblATO_KPIDETAIL> getHeadroom(HashMap<String,String> params) {
        try {
            return  new CollOracleBySql().getHeadroom(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getHeadroom,params=" + JSONUtil.toJSON(params), e);
        }
    }

    // ASM归档磁盘组  PM-00-03-001-05
    public Vector<TblATO_KPIDETAIL> getAsmDiskGroup(HashMap<String,String> params) {
        try {
            return  new CollOracleBySql().getAsmDiskGroup(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getAsmDiskGroup,params=" + JSONUtil.toJSON(params), e);
        }
    }

    public Vector<TblATO_KPIDETAIL> getPMExtendKPI(HashMap<String, String> params) {
        try {
            return  new CollOracleBySql().getPMExtendKPI(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getPMExtendKPI,params=" + JSONUtil.toJSON(params), e);
        }
    }

    @Override
    public Vector<TblATO_KPIDETAIL> getSessionWait(HashMap<String, String> params) {
        try {
            return  new CollOracleBySql().getSessionWait(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getSessionWait,params=" + JSONUtil.toJSON(params), e);
        }
    }

    @Override
	public Vector<TblATO_KPIDETAIL> getSpecialTable(
			HashMap<String, String> params) {
		try {
			CollOracleBySql collector = new CollOracleBySql();
			return collector.getSpecialTable(params);
		} catch (Exception e) {
			logger.error("Exception while getSpecialTable", e);
			return new Vector<TblATO_KPIDETAIL>();
		}
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getStatus(HashMap<String, String> params) {
		try {
			CollOracleBySql collector = new CollOracleBySql();
			return collector.getStatus(params);
		} catch (Exception e) {
			logger.error("Exception while getStatus", e);
			return new Vector<TblATO_KPIDETAIL>();
		}
	}

	@Override
	public Vector<TblATO_KPIDETAIL> getSystem(HashMap<String, String> params) {
		try {
			CollOracleBySql collector = new CollOracleBySql();
			return collector.getSystem(params);
		} catch (Exception e) {
			logger.error("Exception while getSystem", e);
			return new Vector<TblATO_KPIDETAIL>();
		}
	}

    @Override
    public Vector<TblATO_KPIDETAIL> getTableSpaces(HashMap<String, String> params) {
        try {
            CollOracleBySql collector = new CollOracleBySql();
            return collector.getTableSpaces(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getTableSpaces, params=" + JSONUtil.toJSON(params), e);
        }
    }

    /**
     * 调整oracle数据库回滚段表空间的监控策略
     * add by mooker 2014-01-22
     * @param params
     * @return
     */
    @Override
    public Vector<TblATO_KPIDETAIL> getTableSpacesSpecial(HashMap<String, String> params) {
        try {
            CollOracleBySql collector = new CollOracleBySql();
            return collector.getTableSpacesSpecial(params);
        } catch (Exception e) {
            throw new RuntimeException("Exception while getTableSpacesSpecial, params=" + JSONUtil.toJSON(params), e);
        }
    }

	@Override
	public Vector<TblATO_KPIDETAIL> getUndoTableSpaces(
			HashMap<String, String> params) {
		try {
			CollOracleBySql collector = new CollOracleBySql();
			return collector.getUndoTableSpaces(params);
		} catch (Exception e) {
			logger.error("Exception while getUndoTableSpaces", e);
			return new Vector<TblATO_KPIDETAIL>();
		}
	}

    private static String read(String prompt) {
        Scanner scanner = new Scanner(System.in);
        System.out.print(prompt);
        return scanner.nextLine();
    }
	
	public static void main(String[] args) {
        System.out.println("***************ORACLE Collect Test Begin*********************");
        /*String ipAddr = "172.21.0.69";
        String username = "ssdbomc";
        String password = "ssdbomc";
        String port = "1525";
        String sid = "e3cloud";
        String deviceId = "bnms";
        String methodStr = "9";
        String methodStr = "6";*/
        String ipAddr = read("IP_ADDR(remote oracle service ip):\n");
        String username = read("USERNAME:\n");
        String password = read("PASSWORD:\n");
        String port = read("PORT:\n");
        String sid = read("SID:\n");
        String deviceId = read("DEVICE_ID\n");
        String methodStr = read("METHOD(0:getAll, 1:getExtendKPI, 2:getStatus, 3:getSystem, 4:getTableSpaces, 5:getTableSpacesSpecial, 6:getTotalData):\n");
//        String methodStr = read("METHOD(0:getAll, 1:getExtendKPI, 2:getStatus, 3:getSystem,
//              4:getTableSpaces, 5:getTableSpacesSpecial, 6:getTotalData, 7:getHeadroom, 8:getAsmDiskGroup):\n");

		HashMap params = new HashMap();
		params.put("IP_ADDR", ipAddr);
		params.put("USERNAME", username);
		params.put("PASSWORD", DES3.encrypt(password));
		params.put("PORT", port);
		params.put("DEVICE_ID", deviceId);
		params.put("SID", sid);
        
		CollOracle coll = new CollOracle();
		Vector lst = new Vector<TblATO_KPIDETAIL>();

        int method = Integer.parseInt(methodStr);
        switch (method) {
            case 0:
                lst.addAll(coll.getExtendKPI(params));
                lst.addAll(coll.getStatus(params));
                lst.addAll(coll.getSystem(params));
                lst.addAll(coll.getTableSpaces(params));
                lst.addAll(coll.getTableSpacesSpecial(params));
                lst.addAll(coll.getTotalData(params));
                lst.addAll(coll.getHeadroom(params));
                lst.addAll(coll.getAsmDiskGroup(params));
                lst.addAll(coll.getSessionWait(params));
                break;
            case 1:
                lst.addAll(coll.getExtendKPI(params));
                break;
            case 2:
                lst.addAll(coll.getStatus(params));
                break;
            case 3:
                lst.addAll(coll.getSystem(params));
                break;
            case 4:
                lst.addAll(coll.getTableSpaces(params));
                break;
            case 5:
                lst.addAll(coll.getTableSpacesSpecial(params));
                break;
            case 6:
                lst.addAll(coll.getTotalData(params));
                break;
            case 7:
                lst.addAll(coll.getHeadroom(params));
                break;
            case 8:
                lst.addAll(coll.getAsmDiskGroup(params));
                break;
            case 9:
                lst.addAll(coll.getSessionWait(params));
                break;
            default:
                break;
        }
        System.out.println("***************ORACLE Collect Test End*********************");

		System.out.println("lst.size() is " + lst.size());
		for (int i = 0; i < lst.size(); i++) {
			TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) lst.get(i);
//			System.out.println(kpidetail.UNIT_ID + "|" + kpidetail.KPI_ID + "|" + kpidetail.CLL_TIME + "|" + kpidetail.KPI_VALUE);
            String insSql = "INSERT INTO TB_ATO_KPIDETAIL (KPI_ID, UNIT_ID, CLL_TIME, KPI_VALUE, EXT_INFO, DB_TIME, EXT_UNIT_ID, INTERVAL) " +
                    "VALUES ('#KPI_ID#', '#UNIT_ID#', sysdate, '#KPI_VALUE#', 'null', sysdate, '10-11-30:bnms', #INTERVAL#);";
            insSql = insSql.replace("#KPI_ID#", record.KPI_ID);
            insSql = insSql.replace("#UNIT_ID#", record.UNIT_ID);
            insSql = insSql.replace("#KPI_VALUE#", record.KPI_VALUE);
            insSql = insSql.replace("#INTERVAL#", record.INTERVAL);
            System.out.println(insSql);
		}
	}
}