public void stop() {
   try {
     this.mbeanServer.unregisterMBean(platformMonitor);
   } catch (MBeanRegistrationException e) {
     e.printStackTrace();
   } catch (InstanceNotFoundException e) {
     e.printStackTrace();
   }
 }
 public static void unregisterBean(PRTGInterface bean) {
   final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
   try {
     server.unregisterMBean(new ObjectName(bean.getObjectName()));
   } catch (MalformedObjectNameException mone) {
     mone.printStackTrace();
   } catch (MBeanRegistrationException mbre) {
     mbre.printStackTrace();
   } catch (InstanceNotFoundException infe) {
     infe.printStackTrace();
   }
 }
Ejemplo n.º 3
0
  static String getJobGraph(ObjectName jobObjName) {
    Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null);
    Iterator<ObjectInstance> jobIterator = jobInstances.iterator();
    ObjectInstance jobInstance = null;

    if (jobIterator.hasNext()) {
      jobInstance = jobIterator.next();
    }
    String gSnapshot = "";
    if (jobInstance != null) {
      ObjectName jobObjectName = jobInstance.getObjectName();
      MBeanInfo mBeanInfo = null;
      try {
        mBeanInfo = mBeanServer.getMBeanInfo(jobObjectName);
      } catch (IntrospectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InstanceNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ReflectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      /*
       * Now get the graph for the job
       */
      Set<String> operations = new HashSet<String>();
      for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) {
        operations.add(operationInfo.getName());
        if (operationInfo.getName().equals("graphSnapshot")) {
          try {
            gSnapshot = (String) mBeanServer.invoke(jobObjectName, "graphSnapshot", null, null);
            // System.out.println(gSnapshot);
          } catch (InstanceNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }
    return gSnapshot;
  }
  private void poolingSystemProperties() {
    try {
      ObjectName name = new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);

      while (true) {

        try {
          Thread.sleep(interval);
        } catch (InterruptedException e) {
        }

        Object systemLoad = mbeanServer.getAttribute(name, SYSTEM_LOAD);
        Long freePhysicalMemory = (Long) mbeanServer.getAttribute(name, FREE_PHYSICAL_MEM);
        Long freeSwapMemory = (Long) mbeanServer.getAttribute(name, FREE_SWAP_MEM);
        Long sharedMemory = (Long) mbeanServer.getAttribute(name, SHARED_MEM);

        Long totalSwapMemory = (Long) mbeanServer.getAttribute(name, TOTAL_SWAP_MEM);
        Long totalPhysicalMemory = (Long) mbeanServer.getAttribute(name, TOTAL_PHYSICAL_MEM);

        Double percentSwap = (double) ((freeSwapMemory * 100) / totalSwapMemory);
        Double percentPhysical = (double) ((freePhysicalMemory * 100 / totalPhysicalMemory));
        Long sharedMbyteMemory = sharedMemory / 1000000;

        Map<String, Object> status = new HashMap<String, Object>();

        status.put(SYSTEM_LOAD, systemLoad);
        status.put(FREE_PHYSICAL_MEM, percentPhysical);
        status.put(FREE_SWAP_MEM, percentSwap);
        status.put(SHARED_MEM, Double.parseDouble(sharedMbyteMemory.toString()));

        this.sendNotification(RESOURCE_STATUS_TYPE, status);
      }

    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    } catch (AttributeNotFoundException e) {
      e.printStackTrace();
    } catch (InstanceNotFoundException e) {
      e.printStackTrace();
    } catch (MBeanException e) {
      e.printStackTrace();
    } catch (ReflectionException e) {
      e.printStackTrace();
    }
  }
 public void stop() {
   try {
     if (adminMBean != null) {
       try {
         adminMBean.stop();
       } catch (InstanceNotFoundException e) {
         Logger myLogger = LoggerFactory.getLogger(Activator.class);
         myLogger.trace("Error stopping Admin MBean " + e.getMessage());
       }
     }
     if (connector != null) {
       connector.close();
     }
   } catch (Exception e) {
     // Ignore - could be because AMQ stopped.
   }
 }
  public void runJmx() throws IOException {

    propEnv.put(JMXConnector.CREDENTIALS, credentials);

    try {

      serviceURL = new JMXServiceURL(urlString);
      jmxConnector = JMXConnectorFactory.connect(serviceURL, propEnv);
      MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
      ObjectName objectName = new ObjectName("jboss.as:management-root=server");
      String serverState = (String) connection.getAttribute(objectName, "serverState");
      System.out.println("server Status is:= " + serverState);

    } catch (MalformedURLException e) {

      e.printStackTrace();
    } catch (MalformedObjectNameException e) {

      e.printStackTrace();
    } catch (IOException e) {

      e.printStackTrace();
    } catch (AttributeNotFoundException e) {

      e.printStackTrace();
    } catch (InstanceNotFoundException e) {

      e.printStackTrace();
    } catch (MBeanException e) {

      e.printStackTrace();
    } catch (ReflectionException e) {

      e.printStackTrace();
    } finally {
      jmxConnector.close();
    }
  }
  public static PRTGInterface getAndRegisterBean(String beanname) {
    // Find an agent from this JVM. Null argument will return
    // a list of all MBeanServer instances.
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectName name = getJMXObjectName(getObjectName(beanname));
    PRTGInterface retVal = getBean(beanname);
    try {
      if (server.isRegistered(name)) {
        server.unregisterMBean(name);
      }
      // register the MBean
      server.registerMBean(retVal, name);

      // Invoke the printInfo operation on an
      // uninitialized MBean instance.
      Object result =
          server.invoke(
              name, // MBean name
              "printInfo", // operation name
              null, // no parameters
              null // void signature
              );
    } catch (InstanceNotFoundException e) {
      e.printStackTrace();
    } catch (MBeanException e) {
      e.getTargetException().printStackTrace();
    } catch (ReflectionException e) {
      e.printStackTrace();
    } catch (InstanceAlreadyExistsException e) {
      e.printStackTrace();
    } catch (NotCompliantMBeanException e) {
      e.printStackTrace();
    }
    return retVal;
  }
Ejemplo n.º 8
0
  private void tryConnect(boolean requireRemoteSSL) throws IOException {
    if (jmxUrl == null && "localhost".equals(hostName) && port == 0) {
      // Monitor self
      this.jmxc = null;
      this.mbsc = ManagementFactory.getPlatformMBeanServer();
      this.server = Snapshot.newSnapshot(mbsc);
    } else {
      // Monitor another process
      if (lvm != null) {
        if (!lvm.isManageable()) {
          lvm.startManagementAgent();
          if (!lvm.isManageable()) {
            // FIXME: what to throw
            throw new IOException(lvm + "not manageable");
          }
        }
        if (this.jmxUrl == null) {
          this.jmxUrl = new JMXServiceURL(lvm.connectorAddress());
        }
      }
      Map<String, Object> env = new HashMap<String, Object>();
      if (requireRemoteSSL) {
        env.put("jmx.remote.x.check.stub", "true");
      }
      // Need to pass in credentials ?
      if (userName == null && password == null) {
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      } else {
        env.put(JMXConnector.CREDENTIALS, new String[] {userName, password});
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      }
      this.mbsc = jmxc.getMBeanServerConnection();
      this.server = Snapshot.newSnapshot(mbsc);
    }
    this.isDead = false;

    try {
      ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
      this.hasPlatformMXBeans = server.isRegistered(on);
      this.hasHotSpotDiagnosticMXBean =
          server.isRegistered(new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME));
      // check if it has 6.0 new APIs
      if (this.hasPlatformMXBeans) {
        MBeanOperationInfo[] mopis = server.getMBeanInfo(on).getOperations();
        // look for findDeadlockedThreads operations;
        for (MBeanOperationInfo op : mopis) {
          if (op.getName().equals("findDeadlockedThreads")) {
            this.supportsLockUsage = true;
            break;
          }
        }

        on = new ObjectName(COMPILATION_MXBEAN_NAME);
        this.hasCompilationMXBean = server.isRegistered(on);
      }
    } catch (MalformedObjectNameException e) {
      // should not reach here
      throw new InternalError(e.getMessage());
    } catch (IntrospectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (InstanceNotFoundException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (ReflectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    }

    if (hasPlatformMXBeans) {
      // WORKAROUND for bug 5056632
      // Check if the access role is correct by getting a RuntimeMXBean
      getRuntimeMXBean();
    }
  }
Ejemplo n.º 9
0
  static String getJobsInfo(ObjectName jobObjName) {
    Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null);

    Iterator<ObjectInstance> jobIterator = jobInstances.iterator();
    StringBuffer json = new StringBuffer("[");
    int counter = 0;
    while (jobIterator.hasNext()) {
      if (counter > 0) {
        json.append(",");
      }
      ObjectInstance jobInstance = jobIterator.next();
      ObjectName jobObjectName = jobInstance.getObjectName();
      MBeanInfo mBeanInfo = null;
      try {
        mBeanInfo = mBeanServer.getMBeanInfo(jobObjectName);
      } catch (IntrospectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InstanceNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ReflectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      /*
       * Get the names of all the attributes
       */

      Set<String> names = new HashSet<String>();
      for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
        names.add(attributeInfo.getName());
      }
      // now construct the job json and add it to the string buffer
      StringBuffer s = new StringBuffer();
      s.append("{\"");
      Iterator<String> it = names.iterator();
      while (it.hasNext()) {
        String attr = it.next();
        s.append(attr);
        s.append("\":\"");
        try {
          s.append((String) mBeanServer.getAttribute(jobObjectName, attr));
        } catch (AttributeNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InstanceNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MBeanException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ReflectionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        s.append("\",\"");
      }
      // remove the trailing ,\
      s.deleteCharAt(s.length() - 1);
      s.deleteCharAt(s.length() - 1);
      json.append(s.toString() + "}");
      counter++;
    }
    json.append("]");
    String jsonString = json.toString();

    return jsonString;
  }
Ejemplo n.º 10
0
 private void renderEndPoints(
     String appRoot, IApplianceConfiguration config, IEndPoint[] endPoints, PrintWriter pw) {
   for (int i = 0; i < endPoints.length; i++) {
     IEndPoint endPoint = endPoints[i];
     IAppliance appliance = endPoint.getAppliance();
     String appliancePid = appliance.getPid();
     Integer endPointId = new Integer(endPoint.getId());
     boolean isAvailable = appliance.isAvailable();
     if (isAvailable) pw.println("<b>");
     else pw.println("<b><font color=\"gray\">");
     String name = null;
     ICategory category = null;
     ILocation location = null;
     if (config != null) {
       name = config.getName(endPointId);
       category = appliancesProxy.getCategory(config.getCategoryPid(endPointId));
       location = appliancesProxy.getLocation(config.getLocationPid(endPointId));
     }
     pw.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENDPOINT");
     if (!appliance.isSingleton())
       pw.println(
           "&nbsp;(<a href=\""
               + appRoot
               + "/"
               + LABEL
               + "/config/"
               + appliancePid
               + "/"
               + endPointId
               + "\">Configuration</a>)");
     pw.println(
         "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID: "
             + endPoint.getId()
             + "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPE: "
             + endPoint.getType()
             + ((name != null) ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: " + name : "")
             + ((category != null)
                 ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Category: " + category.getName()
                 : "")
             + ((location != null)
                 ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Location: " + location.getName()
                 : ""));
     if (isAvailable)
       pw.println(
           "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
               + (endPointId > 0 ? "Clusters:" : "")
               + "</b><br/>");
     else
       pw.println(
           "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
               + (endPointId > 0 ? "Clusters:" : "")
               + "</b></font><br/>");
     try {
       IServiceCluster[] clusterArray = endPoint.getServiceClusters(IServiceCluster.SERVER_SIDE);
       if (clusterArray != null && clusterArray.length > 0) {
         renderClusterList(appRoot, appliancePid, endPointId, clusterArray, pw);
       }
       clusterArray = endPoint.getServiceClusters(IServiceCluster.CLIENT_SIDE);
       if (clusterArray != null && clusterArray.length > 0) {
         renderClusterList(appRoot, appliancePid, endPointId, clusterArray, pw);
       }
       String[] clusterNames = endPoint.getAdditionalClusterNames();
       if (clusterNames != null && clusterNames.length > 0) {
         renderClusterList(appRoot, appliancePid, endPoint, clusterNames, pw);
       }
       pw.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>");
     } catch (InstanceNotFoundException e) {
       e.printStackTrace();
     } catch (IntrospectionException e) {
       e.printStackTrace();
     } catch (ReflectionException e) {
       e.printStackTrace();
     }
   }
 }