Java Code Examples for org.hyperic.sigar.SigarProxy

The following examples show how to use org.hyperic.sigar.SigarProxy. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: perfmon-agent   Source File: CPUTotalMetric.java    License: Apache License 2.0 6 votes vote down vote up
protected CPUTotalMetric(SigarProxy aSigar, MetricParamsSigar params) {
    super(aSigar, params);

    if (params.type.length() == 0) {
        type = COMBINED;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Invalid total cpu type: " + params.type);
        }
    }

    if (params.coreID >= 0) {
        int avail;
        try {
            avail = aSigar.getCpuList().length;
        } catch (SigarException ex) {
            throw new IllegalArgumentException("Cannot get CPU count at this system: " + ex.getMessage());
        }
        if (params.coreID >= avail) {
            throw new IllegalArgumentException("Invalid core ID on this system: " + params.type);
        }
        coreID = params.coreID;
    }
}
 
Example 2
/**
 * Test method for {@link kg.apc.perfmon.metrics.PerfMonMetricsCreatorImpl#getMetricProvider(java.lang.String, kg.apc.perfmon.metrics.MetricParamsSigar, org.hyperic.sigar.SigarProxy)}.
 */
public final void testGetMetricProviderError() {
    Throwable catched = null;
    PerfMonMetricsCreatorImpl getter = new PerfMonMetricsCreatorImpl();
    System.out.println("createMetric");
    String metricType = "not exist";
    String metricParams = "idle";
    SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar metricParamsSigar = MetricParamsSigar.createFromString(metricParams, sigarProxy);
    try {
        AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy, false);
    } catch (Throwable e) {
        catched = e;
    }
    assertNotNull(catched);
    assertEquals(RuntimeException.class, catched.getClass());
}
 
Example 3
Source Project: perfmon-agent   Source File: CPUProcMetric.java    License: Apache License 2.0 5 votes vote down vote up
protected CPUProcMetric(SigarProxy aSigar, MetricParamsSigar params) {
    super(aSigar, params);
    if (params.type.length() == 0) {
        type = PERCENT;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Invalid process cpu type: " + params.type);
        }
    }
}
 
Example 4
Source Project: perfmon-agent   Source File: NetworkIOMetric.java    License: Apache License 2.0 5 votes vote down vote up
public NetworkIOMetric(SigarProxy aSigar, MetricParams params) {
    super(aSigar);

    if (params.type.length() == 0) {
        type = RX_BYTES;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Unknown net io type: " + params.type);
        }
    }
    log.debug("Net metric type: " + type);

    LinkedList list = new LinkedList();
    if (params.iface.length() != 0) {
        list.add(params.iface);
    } else {
        try {
            list.addAll(Arrays.asList(aSigar.getNetInterfaceList()));
        } catch (SigarException ex) {
            log.warn("Can't get network interfaces list", ex);
        }
    }

    interfaces = (String[]) list.toArray(new String[0]);
    dividingFactor = getUnitDividingFactor(params.getUnit());
}
 
Example 5
Source Project: perfmon-agent   Source File: NetworkIOMetric.java    License: Apache License 2.0 5 votes vote down vote up
static void logAvailableInterfaces(SigarProxy sigar) {
    log.info("*** Logging available network interfaces ***");

    try {
        String[] list = sigar.getNetInterfaceList();
        for (int n = 0; n < list.length; n++) {
            NetInterfaceConfig ifc = sigar.getNetInterfaceConfig(list[n]);
            log.info("Network interface: iface=" + ifc.getName() + " addr=" + ifc.getAddress() + " type=" + ifc.getType());
        }
    } catch (SigarException e) {
        log.debug("Can't get network info", e);
    }
}
 
Example 6
Source Project: perfmon-agent   Source File: AbstractMemMetric.java    License: Apache License 2.0 5 votes vote down vote up
public static AbstractMemMetric getMetric(SigarProxy sigar, MetricParamsSigar params) {
    if (params.PID >= 0) {
        return new MemProcMetric(sigar, params);
    } else {
        return new MemTotalMetric(sigar, params);
    }
}
 
Example 7
Source Project: perfmon-agent   Source File: MemProcMetric.java    License: Apache License 2.0 5 votes vote down vote up
public MemProcMetric(SigarProxy aSigar, MetricParamsSigar params) {
    super(aSigar, params);
    if (params.type.length() == 0) {
        type = RESIDENT;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Invalid proc mem type: " + params.type);
        }
    }
    dividingFactor = getUnitDividingFactor(params.getUnit());
}
 
Example 8
Source Project: perfmon-agent   Source File: SwapMetric.java    License: Apache License 2.0 5 votes vote down vote up
public SwapMetric(SigarProxy aSigar, MetricParamsSigar params) {
    super(aSigar);
    if (params.type.length() == 0) {
        type = USED;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Unknown swap type: " + params.type);
        }
    }
    dividingFactor = getUnitDividingFactor(params.getUnit());
}
 
Example 9
Source Project: perfmon-agent   Source File: MemTotalMetric.java    License: Apache License 2.0 5 votes vote down vote up
public MemTotalMetric(SigarProxy aSigar, MetricParamsSigar params) {
    super(aSigar, params);
    if (params.type.length() == 0) {
        type = USED_PERCENT;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Invalid total mem type: " + params.type);
        }
    }
    dividingFactor = getUnitDividingFactor(params.getUnit());
}
 
Example 10
Source Project: perfmon-agent   Source File: TCPStatMetric.java    License: Apache License 2.0 5 votes vote down vote up
public TCPStatMetric(SigarProxy aSigar, MetricParams params) {
    super(aSigar);

    if (params.type.length() == 0) {
        type = ESTAB;
    } else {
        type = Arrays.asList(types).indexOf(params.type);
        if (type < 0) {
            throw new IllegalArgumentException("Unknown TCP type: " + params.type);
        }
    }
}
 
Example 11
Source Project: perfmon-agent   Source File: PerfMonMetricsCreatorImpl.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractPerfMonMetric getMetricProvider(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy, boolean isNoExec) {
    AbstractPerfMonMetric metric;
    if (isNoExec && (metricType.equalsIgnoreCase("exec") || metricType.equalsIgnoreCase("tail"))) {
        log.warn("Agent started in safe mode, 'exec' and 'tail' metrics are not available");
        metric = new InvalidPerfMonMetric();
    } else if (metricType.equalsIgnoreCase("exec")) {
        metric = new ExecMetric(metricParams);
    } else if (metricType.equalsIgnoreCase("tail")) {
        metric = new TailMetric(metricParams);
    } else if (metricType.equalsIgnoreCase("cpu")) {
        metric = AbstractCPUMetric.getMetric(sigarProxy, metricParams);
    } else if (metricType.equalsIgnoreCase("memory")) {
        metric = AbstractMemMetric.getMetric(sigarProxy, metricParams);
    } else if (metricType.equalsIgnoreCase("swap")) {
        metric = new SwapMetric(sigarProxy, metricParams);
    } else if (metricType.equalsIgnoreCase("disks")) {
        metric = new DiskIOMetric(sigarProxy, metricParams);
    } else if (metricType.equalsIgnoreCase("network")) {
        metric = new NetworkIOMetric(sigarProxy, metricParams);
    } else if (metricType.equalsIgnoreCase("tcp")) {
        metric = new TCPStatMetric(sigarProxy, metricParams);
    } else if (metricType.equalsIgnoreCase("jmx")) {
        metric = new JMXMetric(metricParams, new JMXConnectorHelper());
    } else {
        metric = new InvalidPerfMonMetric();
        throw new RuntimeException("No collector object for metric type " + metricType);
    }
    return metric;
}
 
Example 12
Source Project: perfmon-agent   Source File: AbstractCPUMetric.java    License: Apache License 2.0 5 votes vote down vote up
public static AbstractCPUMetric getMetric(SigarProxy sigar, MetricParamsSigar params) {
    if (params.PID >= 0) {
        return new CPUProcMetric(sigar, params);
    } else {
        return new CPUTotalMetric(sigar, params);
    }
}
 
Example 13
Source Project: perfmon-agent   Source File: PerfMonMetricsService.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractPerfMonMetric getMetric(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy, boolean isNoExec) throws IllegalArgumentException, RuntimeException {
    AbstractPerfMonMetric metric = null;

    Iterator mCreators = loader.iterator();
    while (metric == null && mCreators.hasNext()) {
        PerfMonMetricsCreator mCreator = (PerfMonMetricsCreator) mCreators.next();
        try {
            metric = mCreator.getMetricProvider(metricType, metricParams, sigarProxy, isNoExec);
        } catch (Exception e) {
            log.debug("Error when getting metrics from: " + mCreator.getClass());
            log.debug(e.getMessage());
            triedClasses.add(mCreator.getClass());
            metricExceptions.add(e);
            metric = null;
        }
    }

    if (metric == null) {
        metric = new InvalidPerfMonMetric();
        log.error("Couldn't get metrics from: " + Arrays.toString(triedClasses.toArray()));
        for (int i = 0; i < metricExceptions.size(); i++) {
            log.error(((Exception) metricExceptions.get(i)).getMessage());
        }
        throw new RuntimeException("Couldn't get metrics from: " + Arrays.toString(triedClasses.toArray()));
    }

    return metric;
}
 
Example 14
Source Project: perfmon-agent   Source File: AbstractMemMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getMetric method, of class AbstractMemMetric.
 */
public void testGetMetric() {
    System.out.println("getMetric");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar params = new MetricParamsSigar(sigar);
    AbstractMemMetric result = AbstractMemMetric.getMetric(sigar, params);
    assertEquals(params, result.params);
}
 
Example 15
Source Project: perfmon-agent   Source File: MetricParamsSigarTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of createFromString method, of class MetricParamsSigar.
 */
public void testCreateFromString() {
    System.out.println("createFromString");
    String metricParamsStr = "";
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar result = MetricParamsSigar.createFromString(metricParamsStr, sigar);
    assertEquals(-1, result.PID);
}
 
Example 16
Source Project: perfmon-agent   Source File: MetricParamsSigarTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of populateParams method, of class MetricParamsSigar.
 */
public void testPopulateParams() {
    System.out.println("populateParams");
    String token = "";
    List params = new LinkedList();
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar instance = MetricParamsSigar.createFromString("", sigar);
    instance.populateParams(token, params);
}
 
Example 17
Source Project: perfmon-agent   Source File: SwapMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class SwapMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = new SigarProxyEmul();
    SwapMetric instance = new SwapMetric(sigar, new MetricParamsSigar(sigar));
    instance.getValue(res);
}
 
Example 18
Source Project: perfmon-agent   Source File: NetworkIOMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class NetworkIOMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    for (int n = 0; n < NetworkIOMetric.types.length; n++) {
        NetworkIOMetric instance = new NetworkIOMetric(sigar, MetricParams.createFromString(NetworkIOMetric.types[n]));
        StringBuffer res = new StringBuffer();
        instance.getValue(res);
        System.out.println(NetworkIOMetric.types[n] + "=" + res.toString());
        Thread.sleep(100);
        res = new StringBuffer();
        instance.getValue(res);
        System.out.println(NetworkIOMetric.types[n] + "=" + res.toString());
    }
}
 
Example 19
Source Project: perfmon-agent   Source File: AbstractPerfMonMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of createMetric method, of class AbstractPerfMonMetric.
 */
public void testCreateMetric() {
    System.out.println("createMetric");
    String metricType = "cpu";
    String metricParams = "idle";
    SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
    Class expResult = CPUTotalMetric.class;
    AbstractPerfMonMetric result = AbstractPerfMonMetric.createMetric(metricType, metricParams, sigarProxy, false);
    assertNotNull(result);
    assertEquals(expResult, result.getClass());
}
 
Example 20
Source Project: perfmon-agent   Source File: PerfMonMetricsServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
public final void testGetMetric() {
    String metricType = "cpu";
    SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar metricParams = MetricParamsSigar.createFromString("idle", sigarProxy);

    AbstractPerfMonMetric metric = service.getMetric(metricType, metricParams, sigarProxy, false);

    assertNotNull(metric);
    assertEquals(CPUTotalMetric.class, metric.getClass());
    System.out.println(metric.getClass());
}
 
Example 21
Source Project: perfmon-agent   Source File: AbstractCPUMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getMetric method, of class AbstractCPUMetric.
 */
public void testGetMetric() {
    System.out.println("getMetric");
    SigarProxy sigar = null;
    MetricParamsSigar metricParams = MetricParamsSigar.createFromString("", sigar);
    AbstractCPUMetric result = AbstractCPUMetric.getMetric(sigar, metricParams);
    assertNotNull(result);
}
 
Example 22
Source Project: perfmon-agent   Source File: DiskIOMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class DiskIOMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar metricParams = MetricParamsSigar.createFromString("used", sigar);

    DiskIOMetric instance = new DiskIOMetric(sigar, metricParams);
    instance.getValue(res);
    System.err.println(res.toString());
}
 
Example 23
Source Project: perfmon-agent   Source File: DiskIOMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGetValue_concrete() throws Exception {
    System.out.println("getValue_c");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = new SigarProxyEmul();
    DiskIOMetric instance = new DiskIOMetric(sigar, MetricParamsSigar.createFromString("fs=/", sigar));
    instance.getValue(res);
    assertTrue(res.toString().length() != 0);
    System.err.println(res.toString());
}
 
Example 24
Source Project: perfmon-agent   Source File: DiskIOMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGetValue_reads() throws Exception {
    System.out.println("getValue_r");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    DiskIOMetric instance = new DiskIOMetric(sigar, MetricParamsSigar.createFromString("reads", sigar));
    instance.getValue(res);
    assertTrue(res.toString().length() != 0);
    System.out.println(res.toString());
    res = new StringBuffer();

    instance.getValue(res);
    assertTrue(res.toString().length() != 0);
    System.out.println(res.toString());
}
 
Example 25
Source Project: perfmon-agent   Source File: DiskIOMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGetValue_all() throws Exception {
    System.out.println("getValue");
    SigarProxy sigar = SigarProxyCache.newInstance(new Sigar(), 500);
    for (int n = 0; n < DiskIOMetric.types.length; n++) {
        DiskIOMetric instance = new DiskIOMetric(sigar, MetricParamsSigar.createFromString(DiskIOMetric.types[n], sigar));
        StringBuffer res = new StringBuffer();
        instance.getValue(res);
        System.out.println(DiskIOMetric.types[n] + "=" + res.toString());
        Thread.sleep(100);
        res = new StringBuffer();
        instance.getValue(res);
        System.out.println(DiskIOMetric.types[n] + "=" + res.toString());
    }
}
 
Example 26
Source Project: perfmon-agent   Source File: TCPStatMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class TCPStatMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    SigarProxy sigar = new SigarProxyEmul();
    for (int n = 0; n < TCPStatMetric.types.length; n++) {
        TCPStatMetric instance = new TCPStatMetric(sigar, MetricParams.createFromString(TCPStatMetric.types[n]));
        StringBuffer res = new StringBuffer();
        instance.getValue(res);
        System.out.println(TCPStatMetric.types[n] + '=' + res.toString());
    }
}
 
Example 27
Source Project: perfmon-agent   Source File: MemProcMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class MemProcMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = new SigarProxyEmul();
    MemProcMetric instance = new MemProcMetric(sigar, MetricParamsSigar.createFromString("pid=" + sigar.getPid(), sigar));
    instance.getValue(res);
}
 
Example 28
Source Project: perfmon-agent   Source File: MemProcMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGetValue_all() throws Exception {
    System.out.println("getValue");
    SigarProxy sigar = new SigarProxyEmul();
    for (int n = 0; n < MemProcMetric.types.length; n++) {
        MetricParamsSigar params = MetricParamsSigar.createFromString("pid=" + sigar.getPid() + ":" + MemProcMetric.types[n], sigar);
        MemProcMetric instance = new MemProcMetric(sigar, params);
        StringBuffer res = new StringBuffer();
        instance.getValue(res);
        System.out.println(MemProcMetric.types[n] + "=" + res.toString());
    }
}
 
Example 29
Source Project: perfmon-agent   Source File: MemTotalMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class MemTotalMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer();
    SigarProxy sigar = new SigarProxyEmul();
    MemTotalMetric instance = new MemTotalMetric(sigar, MetricParamsSigar.createFromString("", sigar));
    instance.getValue(res);
}
 
Example 30
Source Project: perfmon-agent   Source File: MemTotalMetricTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGetValue_all() throws Exception {
    System.out.println("getValue");
    SigarProxy sigar = new SigarProxyEmul();
    for (int n = 0; n < MemTotalMetric.types.length; n++) {
        MetricParamsSigar params = MetricParamsSigar.createFromString(MemTotalMetric.types[n], sigar);
        MemTotalMetric instance = new MemTotalMetric(sigar, params);
        StringBuffer res = new StringBuffer();
        instance.getValue(res);
        System.out.println(MemTotalMetric.types[n] + "=" + res.toString());
    }
}