Package org.hyperic.sigar

Examples of org.hyperic.sigar.Sigar


        }
        return false;
    }

    public void testServicePtql() throws Exception {
        Sigar sigar = new Sigar();
        try {
            long pid = sigar.getServicePid(EVENTLOG_NAME);
            String ptql = "Service.Pid.eq=" + pid;
            List names = Service.getServiceNames(sigar, ptql);
            traceln(ptql + "==" + names);
            //different case between XP (Eventlog) and 2008 (EventLog)
            assertTrue(contains(names, EVENTLOG_NAME));
        } finally {
            sigar.close();
        }
    }
View Full Code Here


    public TestThreadCpu(String name) {
        super(name);
    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        ThreadCpu cpu;
        try {
            cpu = sigar.getThreadCpu();
        } catch (SigarNotImplementedException e) {
            return;
        }

        assertGtEqZeroTrace("User", cpu.getUser());
View Full Code Here

    public TestProcEnv(String name) {
        super(name);
    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        try {
            sigar.getProcEnv(getInvalidPid());
        } catch (SigarException e) {
        }

        long pid = sigar.getPid();

        try {
            Map env = sigar.getProcEnv(pid);
            traceln(env.toString());

            String key = "JAVA_HOME";
            String val = (String)env.get(key);

            String single = sigar.getProcEnv(pid, key);

            if (val != null) {
                assertTrue(new File(val, "bin").exists());
                assertTrue(val.equals(single));
                traceln(key + "==>" + single);
            }

            key = "dOeSnOtExIsT";
            val = (String)env.get(key);
            assertTrue(val == null);

            val = sigar.getProcEnv(pid, key);
            assertTrue(val == null);
        } catch (SigarNotImplementedException e) {
            //ok
        } catch (SigarPermissionDeniedException e) {
            //ok
        }

  long[] pids = sigar.getProcList();

  for (int i=0; i<pids.length; i++) {
            //traceln("pid=" + pids[i]);
            try {
                sigar.getProcEnv(pids[i]);
            } catch (SigarException e) {
            }
        }
    }
View Full Code Here

    public TestInvoker(String name) {
        super(name);
    }

    public void testCreate() throws Exception {
        Sigar sigar = new Sigar();

        SigarProxy proxy =
            SigarProxyCache.newInstance(sigar);

        testOK(proxy);

        sigar.close();
    }
View Full Code Here

    public TestCpuInfo(String name) {
        super(name);
    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        CpuInfo[] infos = sigar.getCpuInfoList();

        for (int i=0; i<infos.length; i++) {
            CpuInfo info = infos[i];

            traceln("num=" + i);
            traceln("vendor=" + info.getVendor());
            traceln("model=" + info.getModel());
            traceln("mhz=" + info.getMhz());
            traceln("cache size=" + info.getCacheSize());
            assertGtZeroTrace("totalSockets", info.getTotalSockets());
            assertGtZeroTrace("totalCores", info.getTotalCores());
            assertTrue(info.getTotalSockets() <= info.getTotalCores());
        }

        int mhz = infos[0].getMhz();
        int current = sigar.getCpuInfoList()[0].getMhz();
        assertEquals("Mhz=" + current + "/" + mhz, current, mhz);
    }
View Full Code Here

    public TestNfsServerV3(String name) {
        super(name);
    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();
        NfsServerV3 nfs;
       
        try {
            nfs = sigar.getNfsServerV3();
        } catch (SigarException e) {
            return;
        }

        traceMethods(nfs);
View Full Code Here

    public TestFileSystem(String name) {
        super(name);
    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        FileSystem[] fslist = sigar.getFileSystemList();
        FileSystemMap mounts = sigar.getFileSystemMap();

        String dir = System.getProperty("user.home");
        assertTrueTrace("\nMountPoint for " + dir,
                        mounts.getMountPoint(dir).getDirName());

        for (int i=0; i<fslist.length; i++) {
            FileSystem fs = fslist[i];

            assertTrue(mounts.getFileSystem(fs.getDirName()) != null);
            assertLengthTrace("DevName", fs.getDevName());
            assertLengthTrace("DirName", fs.getDirName());
            assertLengthTrace("TypeName", fs.getTypeName());
            assertLengthTrace("SysTypeName", fs.getSysTypeName());
            traceln("Options=" + fs.getOptions());

            FileSystemUsage usage;

            try {
                usage = sigar.getFileSystemUsage(fs.getDirName());
            } catch (SigarException e) {
                if (fs.getType() == FileSystem.TYPE_LOCAL_DISK) {
                    throw e;
                }
                //else ok, e.g. floppy drive on windows
                continue;
            }

            switch (fs.getType()) {
              case FileSystem.TYPE_LOCAL_DISK:
                assertGtZeroTrace("  Total", usage.getTotal());
                //possible machines have full filesystems
                assertGtEqZeroTrace("  Free", usage.getFree());
                assertGtEqZeroTrace("  Avail", usage.getAvail());
                assertGtEqZeroTrace("   Used", usage.getUsed());
                double usePercent = usage.getUsePercent() * 100;
                traceln("  Usage=" + usePercent + "%");
                assertTrue(usePercent <= 100.0);
              default:
                traceln("  DiskReads=" + usage.getDiskReads());
                traceln("  DiskWrites=" + usage.getDiskWrites());
            }
        }

        try {
            sigar.getFileSystemUsage("T O T A L L Y B O G U S");
            assertTrue(false);
        } catch (SigarException e) {
            assertTrue(true);
        }
    }
View Full Code Here

    /**
     * Creates a new instance of this class. Will create the Sigar instance this
     * class uses when constructing other MBeans.
     */
    public SigarRegistry() {
        super(new Sigar(), CACHELESS);
        this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
                + "=" + MBEAN_TYPE;
        this.managedBeans = new ArrayList();
    }
View Full Code Here

     *
     * @throws IllegalArgumentException If the CPU index is out of range or
     *         an unexpected Sigar error occurs
     */
    public SigarCpuInfo(int index) throws IllegalArgumentException {
        this(new Sigar(), index);
    }
View Full Code Here

     *
     * @throws IllegalArgumentException If the CPU index is out of range or
     *         an unexpected Sigar error occurs
     */
    public SigarCpuPerc(int index) {
        this(new Sigar(), index);
    }
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.Sigar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.