Package org.hyperic.sigar

Examples of org.hyperic.sigar.Sigar


            traceln("pid " + pid + ": " + e.getMessage());
        }
    }

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

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

        ProcState procState = sigar.getProcState(sigar.getPid());
        traceState(sigar, sigar.getPid());

        char state = procState.getState();
        assertTrue((state == 'R') || (state == 'S'));
        assertTrue(procState.getName().indexOf("java") != -1);

        long[] pids = sigar.getProcList();
        for (int i=0; i<pids.length; i++) {
            traceState(sigar, pids[i]);
        }
    }
View Full Code Here


    }

    public static void main(String[] args) throws Exception {
        int expire = 30 * 1000;

        Sigar sigar = new Sigar();

        SigarProxy proxy = SigarProxyCache.newInstance(sigar, expire);

        new Proxy(sigar, proxy).run(args);
    }
View Full Code Here

                startSize = currentSize = getSize();
                long startTime = System.currentTimeMillis();

                for (int i=0; i<num; i++) {
                    //test many iterations of open/close
                    Sigar s = new Sigar();

                    try {
                        runall(i);
                    } catch (IllegalAccessException e) {
                        throw new SigarException(e.getMessage());
                    } catch (InvocationTargetException e) {
                        throw new SigarException(e.getMessage());
                    } finally {
                        s.close();
                    }
                }

                long totalTime = System.currentTimeMillis() - startTime;
               
View Full Code Here

    private Sigar sigarImpl;
    private SigarProxy sigar;

    public SigarProcess() {
        this(new Sigar());
    }
View Full Code Here

     * @deprecated
     */
    public static List getServiceConfigs(String exe)
        throws Win32Exception {

        Sigar sigar = new Sigar();
        try {
            return getServiceConfigs(sigar, exe);
        } finally {
            sigar.close();
        }
    }
View Full Code Here

            }
            System.out.println(service.getStatusString());
            return;
        }
        else if ((args.length == 1) && (args[0].startsWith("Service."))) {
            Sigar sigar = new Sigar();
            try {
                services = Service.getServiceNames(sigar, args[0]);
            } finally {
                sigar.close();
            }
        }
        else if ((args.length == 1) && (args[0].endsWith(EXE_EXT))) {
            Sigar sigar = new Sigar();
            try {
                services = getServiceConfigs(args[0]);
            } finally {
                sigar.close();
            }
            for (int i=0; i<services.size(); i++) {
                ServiceConfig config = (ServiceConfig)services.get(i);
                config.list(System.out);
                System.out.println("");
View Full Code Here

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

     *
     * @throws IllegalArgumentException
     *      If an unexpected Sigar error occurs.
     */
    public SigarLoadAverage() throws IllegalArgumentException {
        this(new Sigar());
    }
View Full Code Here

        sigar.getLinkInfo(file);
    }

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

        String file;
        File dir = new File(System.getProperty("user.dir"));
        String[] entries = dir.list();
       
        for (int i=0; i<entries.length; i++) {
            file = entries[i];
            File testFile = new File(dir, file);
            if (!(testFile.exists() && testFile.canRead())) {
                continue;
            }
            if (testFile.isHidden()) {
                continue;
            }
            traceln(file + ":");
            getFileInfo(sigar,
                        testFile.getAbsolutePath());
        }

        file = "NO SUCH FILE";

        try {
            getFileInfo(sigar, file);
            assertTrue(false);
        } catch (SigarNotImplementedException e) {
            //XXX win32
        } catch (SigarException e) {
            traceln(file + ": " + e.getMessage());
            assertTrue(true);
        }

        File tmp = File.createTempFile("sigar-", "");
        file = tmp.getAbsolutePath();
        tmp.deleteOnExit();
        traceln("TMP=" + file);

        try {
            //stat() mtime is in seconds, this happens to quick to detect change.
            Thread.sleep(1000 * 1);
        } catch (InterruptedException e) {
        }

        try {
            FileInfo info = sigar.getFileInfo(file);

            FileOutputStream os = null;
            try {
                os = new FileOutputStream(file);
                os.write(1);
View Full Code Here

        return found;
    }

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

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

        try {
            String[] args = sigar.getProcArgs(sigar.getPid());

            if (getVerbose()) {
                findArg(args, TestProcArgs.class.getName());
            }

            if (args.length > 0) {
                assertTrue(args[0].indexOf("java") != -1);
            }

            //hpux has a limit less than what these args will be
            if (!System.getProperty("os.name").equals("HP-UX")) {
                //and this test only works when run under ant
                //assertTrue(findArg(args, TestProcArgs.class.getName()));
            }
        } catch (SigarNotImplementedException e) {
            //ok; might not happen on win32
        }

  long[] pids = sigar.getProcList();

  for (int i=0; i<pids.length; i++) {
            String pidTrace = "pid=" + pids[i];
            try {
                String[] args = sigar.getProcArgs(pids[i]);
                traceln(pidTrace);
                for (int j=0; j<args.length; j++) {
                    traceln("   " + j + "=>" + args[j] + "<==");
                }
            } catch (SigarException e) {
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.