Пример #1
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;
  }
 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();
   }
 }
  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 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;
  }
Пример #7
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;
  }
Пример #8
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();
     }
   }
 }