CollLinuxHost.java 5.11 KB
package com.sitech.ismp.coll.host;

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

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

public class CollLinuxHost implements CollLinuxHostMBean {

	public Vector<TblATO_KPIDETAIL> getConfig(HashMap<String, String> params) {
		Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
		
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
		CollLinuxWithCMDByCron collByCron = new CollLinuxWithCMDByCron();
		result.addAll(coll.collBaseInfo(params));
		result.addAll(coll.collCpuInfo(params));
		result.addAll(coll.collMemSize(params));
		result.addAll(coll.collOsVersion(params));
//		result.addAll(coll.collInterface(params));
		result.addAll(coll.collSwap(params));
		result.addAll(collByCron.getConfig(params));

		return result;
	}

	public Vector<TblATO_KPIDETAIL> getCpu(HashMap<String, String> params) {
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();		
		return coll.collCpu(params);
	}

	public Vector<TblATO_KPIDETAIL> getDisk(HashMap<String, String> params) {
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();	
		return coll.collDisk(params);
	}

    public Vector<TblATO_KPIDETAIL> getDiskByCron(HashMap<String, String> params) {
        CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
        return coll.collDisk(params);
    }

	public Vector<TblATO_KPIDETAIL> getFileSystem(HashMap<String, String> params) {
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
		return coll.collFileSystem(params);
	}


	public Vector<TblATO_KPIDETAIL> getMemory(HashMap<String, String> params) {
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();		
		return coll.collMemory(params);
	}
	
	public Vector<TblATO_KPIDETAIL> getUnavailableCpu(HashMap<String, String> params){
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();		
		return coll.getUnavailableCpu(params);
	}
	
	public Vector<TblATO_KPIDETAIL> getUnavailableMem(HashMap<String, String> params){
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();		
		return coll.getUnavailableMem(params);
	}
	
	public Vector<TblATO_KPIDETAIL> collIO(HashMap<String, String> params){
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();		
		return coll.collIO(params);
	}
	
	public void  getHapervisor(HashMap<String, String> params){
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();		
		coll.getHapervisor(params);
	}
	
	public Vector<TblATO_KPIDETAIL> getVMInfo(HashMap<String, String> params){
		CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();	
		return coll.collVMInfo(params);
	}

    public Vector<TblATO_KPIDETAIL> getProcessTop10(HashMap<String, String> params) {
        CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
        return coll.getProcessTop10(params);
    }
    public Vector<TblATO_KPIDETAIL> getProcessByKey(HashMap<String, String> params) {
        CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
        return coll.getProcessByKey(params);
    }

    @Override
    public Vector<TblATO_KPIDETAIL> getNet(HashMap<String, String> params) {
        CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
        Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
        result.addAll(coll.collInterface(params));
        result.addAll(coll.getNet(params));
//        return coll.getNet(params);
        return result;
    }

	/**
	 * 采集文件变更指标
	 */
	@Override
	public Vector<TblATO_KPIDETAIL> getFileChange(HashMap<String, String> params) {
		CollLinuxWithCMDByCron cmd = new CollLinuxWithCMDByCron();
		return cmd.getFileChange(params);
	}

    public static void main(String[] args) {
		System.out
				.println("***************Linux Collect Test Begin*********************");
		String methodStr = read("METHOD(0:getAll, 1:getConfig, 2:getCpu, 3:getMemory, 4:getDisk, 5:getFileSystem):\n");

		HashMap<String, String> params = new HashMap<String, String>();

		int method = Integer.parseInt(methodStr);
		Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();

		CollLinuxHost collector = new CollLinuxHost();

		switch (method) {
		case 0:
			result.addAll(collector.getConfig(params));
			result.addAll(collector.getCpu(params));
			result.addAll(collector.getMemory(params));
			result.addAll(collector.getDisk(params));
			result.addAll(collector.getFileSystem(params));
			break;
		case 1:
			result.addAll(collector.getConfig(params));
			break;
		case 2:
			result.addAll(collector.getCpu(params));
			break;
		case 3:
			result.addAll(collector.getMemory(params));
			break;
		case 4:
			result.addAll(collector.getDisk(params));
			break;
		case 5:
			result.addAll(collector.getFileSystem(params));
			break;
		default:
			break;
		}

		System.out
				.println("***************Linux Collect Test End*********************");
		System.out.println();
		for (int i = 0; i < result.size(); i++) {
			TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) result.get(i);
			System.out.println(record.UNIT_ID + "\t" + record.KPI_ID + "\t"
					+ record.KPI_VALUE);
		}
	}
	
	private static String read(String prompt) {
		Scanner scanner = new Scanner(System.in);
		System.out.print(prompt);
		return scanner.nextLine();
	}

}