sun.jvmstat.monitor.MonitorException Java Examples

The following examples show how to use sun.jvmstat.monitor.MonitorException. 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: JCmd.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #2
Source File: JCmd.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #3
Source File: TestPollingInterval.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException,
        MonitorException, URISyntaxException {
    LingeredApp app = null;
    try {
        List<String> vmArgs = new ArrayList<String>();
        vmArgs.add("-XX:+UsePerfData");
        vmArgs.addAll(Utils.getVmOptions());
        app = LingeredApp.startApp(vmArgs);

        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);
        System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm));

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);

        Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value");
        Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value");
    } finally {
        LingeredApp.stopApp(app);
    }

}
 
Example #4
Source File: JvmstatModelImpl.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public String findByName(String name) {
    String value = valueCache.get(name);
    if (value != null) return value;
    
    try {
        Monitor mon = monitoredVm.findByName(name);
        if (mon != null) {
            value = mon.getValue().toString();
            if (Utils.getVariability(mon).toString().equals(Variability_CONSTANT)) {
                valueCache.put(name,value);
            }
        }
        return value;
    } catch (MonitorException ex) {
        ErrorManager.getDefault().notify(ErrorManager.WARNING,ex);
    }
    return null;
}
 
Example #5
Source File: JCmd.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #6
Source File: JCmd.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #7
Source File: JCmd.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #8
Source File: JCmd.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #9
Source File: JCmd.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #10
Source File: JCmd.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static String getMainClass(VirtualMachineDescriptor vmd)
        throws URISyntaxException, MonitorException {
    try {
        String mainClass = null;
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
        return mainClass;
    } catch(NullPointerException e) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return null;
    }
}
 
Example #11
Source File: ProcessArgumentMatcher.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean check(VirtualMachineDescriptor vmd, String excludeClass, String partialMatch) {
    String mainClass = null;
    try {
        VmIdentifier vmId = new VmIdentifier(vmd.id());
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
        monitoredHost.detach(monitoredVm);
    } catch (NullPointerException npe) {
        // There is a potential race, where a running java app is being
        // queried, unfortunately the java app has shutdown after this
        // method is started but before getMonitoredVM is called.
        // If this is the case, then the /tmp/hsperfdata_xxx/pid file
        // will have disappeared and we will get a NullPointerException.
        // Handle this gracefully....
        return false;
    } catch (MonitorException | URISyntaxException e) {
        return false;
    }

    if (excludeClass != null && mainClass.equals(excludeClass)) {
        return false;
    }

    if (partialMatch != null && mainClass.indexOf(partialMatch) == -1) {
        return false;
    }

    return true;
}
 
Example #12
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void registerJvmstatConnection(Host host, HostIdentifier hostId, int interval) {
    // Monitor the Host for new/finished Applications
    // NOTE: the code relies on the fact that the provider is the first listener registered in MonitoredHost of the Host
    // in which case the first obtained event contains all applications already running on the Host
    JvmstatConnection hostListener = null;
    
    // Get the MonitoredHost for Host
    final MonitoredHost monitoredHost = getMonitoredHost(hostId);
    
    if (monitoredHost == null) { // monitored host not available reschedule
        rescheduleProcessNewHost(host,hostId);
        return;
    }
    hostId = monitoredHost.getHostIdentifier();
    monitoredHost.setInterval(interval);
    if (host == Host.LOCALHOST) checkForBrokenLocalJps(monitoredHost);
    try {
        // Fetch already running applications on the host
        processNewApplicationsByPids(host, hostId, monitoredHost.activeVms());
        hostListener = new JvmstatConnection(host, monitoredHost);
        monitoredHost.addHostListener(hostListener);
        registerHostListener(host, hostId, hostListener);
    } catch (MonitorException e) {
        Throwable t = e.getCause();
        monitoredHost.setLastException(e);
        if (!(t instanceof ConnectException)) {
            DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(
                    NbBundle.getMessage(JvmstatApplicationProvider.class, "MSG_Broken_Jvmstat", // NOI18N
                    DataSourceDescriptorFactory.getDescriptor(host).getName()),
                    NotifyDescriptor.ERROR_MESSAGE));
            LOGGER.log(Level.INFO, "Jvmstat connection to " + host + " failed.", t); // NOI18N
        } else {
            rescheduleProcessNewHost(host,hostId);
        }
    }
}
 
Example #13
Source File: MonitorVmStartTerminate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #14
Source File: MonitorVmStartTerminate.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #15
Source File: SymbolResolutionClosure.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void visit(Object o, boolean hasNext) throws MonitorException {
    if (! (o instanceof ColumnFormat)) {
        return;
    }

    ColumnFormat c = (ColumnFormat)o;
    Expression e = c.getExpression();
    String previous = e.toString();
    e = (Expression)ee.evaluate(e);
    if (debug) {
        System.out.print("Expression: " + previous + " resolved to "
                         + e.toString());
    }
    c.setExpression(e);
}
 
Example #16
Source File: SymbolResolutionClosure.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void visit(Object o, boolean hasNext) throws MonitorException {
    if (! (o instanceof ColumnFormat)) {
        return;
    }

    ColumnFormat c = (ColumnFormat)o;
    Expression e = c.getExpression();
    String previous = e.toString();
    e = (Expression)ee.evaluate(e);
    if (debug) {
        System.out.print("Expression: " + previous + " resolved to "
                         + e.toString());
    }
    c.setExpression(e);
}
 
Example #17
Source File: MonitorVmStartTerminate.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #18
Source File: SymbolResolutionClosure.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void visit(Object o, boolean hasNext) throws MonitorException {
    if (! (o instanceof ColumnFormat)) {
        return;
    }

    ColumnFormat c = (ColumnFormat)o;
    Expression e = c.getExpression();
    String previous = e.toString();
    e = (Expression)ee.evaluate(e);
    if (debug) {
        System.out.print("Expression: " + previous + " resolved to "
                         + e.toString());
    }
    c.setExpression(e);
}
 
Example #19
Source File: PerfCounters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the performance counter with the given name.
 *
 * @param name The name of the performance counter.
 * @throws IllegalArgumentException If no counter with the given name exists.
 * @throws MonitorException If an error occurs while communicating with the VM.
 * @return The performance counter with the given name.
 */
public static PerfCounter findByName(String name)
    throws MonitorException, IllegalArgumentException {
    Monitor m = vm.findByName(name);
    if (m == null) {
        throw new IllegalArgumentException("Did not find a performance counter with name " + name);
    }
    return new PerfCounter(m, name);
}
 
Example #20
Source File: SymbolResolutionClosure.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void visit(Object o, boolean hasNext) throws MonitorException {
    if (! (o instanceof ColumnFormat)) {
        return;
    }

    ColumnFormat c = (ColumnFormat)o;
    Expression e = c.getExpression();
    String previous = e.toString();
    e = (Expression)ee.evaluate(e);
    if (debug) {
        System.out.print("Expression: " + previous + " resolved to "
                         + e.toString());
    }
    c.setExpression(e);
}
 
Example #21
Source File: JvmstatModelImpl.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public List<String> findByPattern(String pattern) {
    try {
        List<Monitor> monitorList = monitoredVm.findByPattern(pattern);
        List<String> monitorStrList = new ArrayList<String>(monitorList.size());
        for (Monitor monitor : monitorList) {
            monitorStrList.add(monitor.getValue().toString());
        }
        return monitorStrList;
    } catch (MonitorException ex) {
        ErrorManager.getDefault().notify(ErrorManager.WARNING,ex);
    }
    return null;
}
 
Example #22
Source File: JvmstatCountersPackages.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private TracerPackage<Application>[] computePackages() {
    List counters;
    Iterator it;
    Map<String,JvmstatCountersPackage> packages = new HashMap();
    
    try {
        counters = monitoredVm.findByPattern(".*");
        Collections.sort(counters,new Comparator<Monitor>() {
            public int compare(Monitor o1, Monitor o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        it = counters.iterator();
        for (int i=0;it.hasNext();i++) {
            Monitor monitor = (Monitor) it.next();
            String unitsName = Utils.getUnits(monitor).toString();
            String var = Utils.getVariability(monitor).toString();
            String name = monitor.getName();
            String baseName = monitor.getBaseName();
            
            if (unitsName.equals(Units_STRING) || unitsName.equals(Units_INVALID) || unitsName.equals(Units_NONE)) {
                continue;
            }
            if (var.equals(Variability_INVALID) || var.equals(Variability_CONSTANT)) {
                continue;
            }
            if (monitor.isVector()) {
                continue;
            }
            getPackage(packages,monitor,i,name);
         }
    } catch (MonitorException ex) {
        LOGGER.log(Level.INFO,"findByPattern failed",ex);  // NOI18N
    }
    return packages.values().toArray(new TracerPackage[0]);
}
 
Example #23
Source File: JCmd.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isJCmdProcess(VirtualMachineDescriptor vmd) {
    try {
        String mainClass = getMainClass(vmd);
        return mainClass != null && mainClass.equals(JCmd.class.getName());
    } catch (URISyntaxException|MonitorException ex) {
        return false;
    }
}
 
Example #24
Source File: SymbolResolutionClosure.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void visit(Object o, boolean hasNext) throws MonitorException {
    if (! (o instanceof ColumnFormat)) {
        return;
    }

    ColumnFormat c = (ColumnFormat)o;
    Expression e = c.getExpression();
    String previous = e.toString();
    e = (Expression)ee.evaluate(e);
    if (debug) {
        System.out.print("Expression: " + previous + " resolved to "
                         + e.toString());
    }
    c.setExpression(e);
}
 
Example #25
Source File: PerfCounters.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the performance counter with the given name.
 *
 * @param name The name of the performance counter.
 * @throws IllegalArgumentException If no counter with the given name exists.
 * @throws MonitorException If an error occurs while communicating with the VM.
 * @return The performance counter with the given name.
 */
public static PerfCounter findByName(String name)
    throws MonitorException, IllegalArgumentException {
    Monitor m = vm.findByName(name);
    if (m == null) {
        throw new IllegalArgumentException("Did not find a performance counter with name " + name);
    }
    return new PerfCounter(m, name);
}
 
Example #26
Source File: MonitorVmStartTerminate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasMainArgs(Integer id, String args) {
    try {
        VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
        MonitoredVm target = host.getMonitoredVm(vmid);
        String monitoredArgs = MonitoredVmUtil.mainArgs(target);
        if (monitoredArgs != null && monitoredArgs.contains(args)) {
            return true;
        }
    } catch (URISyntaxException | MonitorException e) {
        // ok. process probably not running
    }
    return false;
}
 
Example #27
Source File: JCmd.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isJCmdProcess(VirtualMachineDescriptor vmd) {
    try {
        String mainClass = getMainClass(vmd);
        return mainClass != null && mainClass.equals(JCmd.class.getName());
    } catch (URISyntaxException|MonitorException ex) {
        return false;
    }
}
 
Example #28
Source File: JCmd.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isJCmdProcess(VirtualMachineDescriptor vmd) {
    try {
        String mainClass = getMainClass(vmd);
        return mainClass != null && mainClass.equals(JCmd.class.getName());
    } catch (URISyntaxException|MonitorException ex) {
        return false;
    }
}
 
Example #29
Source File: JCmd.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isJCmdProcess(VirtualMachineDescriptor vmd) {
    try {
        String mainClass = getMainClass(vmd);
        return mainClass != null && mainClass.equals(JCmd.class.getName());
    } catch (URISyntaxException|MonitorException ex) {
        return false;
    }
}
 
Example #30
Source File: SymbolResolutionClosure.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void visit(Object o, boolean hasNext) throws MonitorException {
    if (! (o instanceof ColumnFormat)) {
        return;
    }

    ColumnFormat c = (ColumnFormat)o;
    Expression e = c.getExpression();
    String previous = e.toString();
    e = (Expression)ee.evaluate(e);
    if (debug) {
        System.out.print("Expression: " + previous + " resolved to "
                         + e.toString());
    }
    c.setExpression(e);
}