org.hyperic.sigar.SigarProxy Java Examples

The following examples show how to use org.hyperic.sigar.SigarProxy. 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 File: PerfMonMetricsCreatorImplTest.java    From perfmon-agent with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #2
Source File: CPUTotalMetric.java    From perfmon-agent with 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 #3
Source File: MemProcMetricTest.java    From perfmon-agent with 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 #4
Source File: AbstractMemMetricTest.java    From perfmon-agent with 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 #5
Source File: MetricParamsSigarTest.java    From perfmon-agent with 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 #6
Source File: SwapMetricTest.java    From perfmon-agent with 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 #7
Source File: NetworkIOMetricTest.java    From perfmon-agent with 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 #8
Source File: AbstractPerfMonMetricTest.java    From perfmon-agent with 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 #9
Source File: PerfMonMetricsServiceTest.java    From perfmon-agent with 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 #10
Source File: AbstractCPUMetricTest.java    From perfmon-agent with 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 #11
Source File: DiskIOMetricTest.java    From perfmon-agent with 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 #12
Source File: DiskIOMetricTest.java    From perfmon-agent with 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 #13
Source File: DiskIOMetricTest.java    From perfmon-agent with 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 #14
Source File: DiskIOMetricTest.java    From perfmon-agent with 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 #15
Source File: TCPStatMetricTest.java    From perfmon-agent with 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 #16
Source File: MetricParamsSigarTest.java    From perfmon-agent with 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 #17
Source File: MemProcMetricTest.java    From perfmon-agent with 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 #18
Source File: MemTotalMetricTest.java    From perfmon-agent with 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 #19
Source File: MemTotalMetricTest.java    From perfmon-agent with 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());
    }
}
 
Example #20
Source File: CPUProcMetricTest.java    From perfmon-agent with Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class CPUPerfMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer();
    final SigarProxy sigar = new SigarProxyEmul();
    MetricParamsSigar params = MetricParamsSigar.createFromString("pid=" + sigar.getPid(), sigar);
    CPUProcMetric instance = new CPUProcMetric(sigar, params);
    instance.getValue(res);
    assertTrue(Double.parseDouble(res.toString()) >= 0);
}
 
Example #21
Source File: CPUProcMetricTest.java    From perfmon-agent with 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 < CPUProcMetric.types.length; n++) {
        MetricParamsSigar params = MetricParamsSigar.createFromString("pid=" + sigar.getPid() + ":" + CPUProcMetric.types[n], sigar);
        CPUProcMetric instance = new CPUProcMetric(sigar, params);
        StringBuffer res = new StringBuffer();
        instance.getValue(res);
        System.out.println(CPUProcMetric.types[n] + "=" + res.toString());
        Thread.sleep(100);
        res = new StringBuffer();
        instance.getValue(res);
        System.out.println(CPUProcMetric.types[n] + "=" + res.toString());
    }
}
 
Example #22
Source File: PerfMonMetricsCreatorImplTest.java    From perfmon-agent with Apache License 2.0 5 votes vote down vote up
/**
 * 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 testGetMetricProvider() {
    PerfMonMetricsCreatorImpl getter = new PerfMonMetricsCreatorImpl();
    System.out.println("createMetric");
    String metricType = "cpu";
    String metricParams = "idle";
    SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar metricParamsSigar = MetricParamsSigar.createFromString(metricParams, sigarProxy);
    Class expResult = CPUTotalMetric.class;
    AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy, false);
    assertEquals(expResult, result.getClass());
}
 
Example #23
Source File: PerfMonMetricsCreatorImplTest.java    From perfmon-agent with Apache License 2.0 5 votes vote down vote up
public final void testNoExec() {
    PerfMonMetricsCreatorImpl getter = new PerfMonMetricsCreatorImpl();
    System.out.println("no-exec");
    String metricType = "exec";
    String metricParams = "";
    SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
    MetricParamsSigar metricParamsSigar = MetricParamsSigar.createFromString(metricParams, sigarProxy);
    AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy, true);
    assertNotNull(result);
    assertEquals(InvalidPerfMonMetric.class, result.getClass());
}
 
Example #24
Source File: CPUTotalMetricTest.java    From perfmon-agent with Apache License 2.0 5 votes vote down vote up
/**
 * Test of getValue method, of class CPUTotalMetric.
 */
public void testGetValue() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer("");
    SigarProxy sigar = new SigarProxyEmul();
    MetricParamsSigar params = MetricParamsSigar.createFromString("idle", sigar);
    CPUTotalMetric instance = new CPUTotalMetric(sigar, params);
    instance.getValue(res);
}
 
Example #25
Source File: CPUTotalMetricTest.java    From perfmon-agent with Apache License 2.0 5 votes vote down vote up
public void testGetValue_core() throws Exception {
    System.out.println("getValue");
    StringBuffer res = new StringBuffer("");
    SigarProxy sigar = new SigarProxyEmul();
    MetricParamsSigar params = MetricParamsSigar.createFromString("core=0:idle", sigar);
    CPUTotalMetric instance = new CPUTotalMetric(sigar, params);
    instance.getValue(res);
}
 
Example #26
Source File: CPUTotalMetricTest.java    From perfmon-agent with 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 < CPUTotalMetric.types.length; n++) {
        MetricParamsSigar params = MetricParamsSigar.createFromString("pid=" + sigar.getPid() + ":" + CPUTotalMetric.types[n], sigar);
        CPUTotalMetric instance = new CPUTotalMetric(sigar, params);
        StringBuffer res = new StringBuffer("");
        instance.getValue(res);
        assertTrue(!res.toString().equals("NaN"));
        System.out.println(CPUTotalMetric.types[n] + "=" + res.toString());
    }
}
 
Example #27
Source File: CPUProcMetric.java    From perfmon-agent with 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 #28
Source File: PerfMonMetricsService.java    From perfmon-agent with 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 #29
Source File: NetworkIOMetric.java    From perfmon-agent with 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 #30
Source File: NetworkIOMetric.java    From perfmon-agent with 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);
    }
}