Пример #1
0
 private Set<String> enumerateIndexes(ProbeDescSummary summary) {
   MBeanServerConnection mbean = cnx.getConnection().connection;
   Set<String> indexes = new HashSet<String>();
   for (String name : summary.specifics.get("mbeanNames").split(" *; *")) {
     try {
       Set<ObjectName> mbeanNames = mbean.queryNames(new ObjectName(name), null);
       Pattern p = Pattern.compile(summary.specifics.get("mbeanIndex"));
       for (ObjectName oneMbean : mbeanNames) {
         log(Level.DEBUG, "%s", oneMbean.getCanonicalName());
         Matcher m = p.matcher(oneMbean.toString());
         if (m.matches() && !m.group(1).isEmpty()) {
           log(Level.DEBUG, "index found: %s for %s", m.group(1), summary.name);
           indexes.add(m.group(1));
         }
       }
     } catch (MalformedObjectNameException e) {
       log(
           Level.WARN,
           "invalid name for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     } catch (IOException e) {
       log(
           Level.WARN,
           "Connection failed for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     }
   }
   return indexes;
 }
Пример #2
0
 @Override
 public boolean isGoodProbeDesc(ProbeDescSummary summary) {
   MBeanServerConnection mbean = cnx.getConnection().connection;
   boolean valid = true;
   boolean enumerated = false;
   for (String name : summary.specifics.get("mbeanNames").split(" *; *")) {
     enumerated = true;
     try {
       Set<ObjectName> mbeanNames = mbean.queryNames(new ObjectName(name), null);
       log(Level.TRACE, "%s", "found mbeans %s for %s", mbeanNames, summary.name);
       if (mbeanNames.size() > 1 && !summary.isIndexed) {
         log(Level.WARN, "not indexed probe %s return more than one mbean", summary.name);
         valid = false;
       } else if (mbeanNames.size() > 0) {
         valid &= true;
       } else {
         valid = false;
       }
     } catch (MalformedObjectNameException e) {
       log(
           Level.WARN,
           "invalid name for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     } catch (IOException e) {
       log(
           Level.WARN,
           "Connection failed for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     }
   }
   return valid && enumerated;
 }
  @Override
  public void init() throws ServletException {

    LOG.info("enter--init");

    super.init();
    ArrayList<MBeanServer> serverList = MBeanServerFactory.findMBeanServer(null);
    MBeanServer serverHelloWorld = (MBeanServer) serverList.get(0);
    final HelloWorldService helloWorldMBean = new HelloWorldService();
    ObjectName helloWorld = null;
    try {
      helloWorld = new ObjectName("jboss.jmx:name=HelloJMX");
      serverHelloWorld.registerMBean(helloWorldMBean, helloWorld);
    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    } catch (InstanceAlreadyExistsException e) {
      e.printStackTrace();
    } catch (MBeanRegistrationException e) {
      e.printStackTrace();
    } catch (NotCompliantMBeanException e) {
      e.printStackTrace();
    }

    LOG.info("exit--init");
  }
Пример #4
0
 static {
   try {
     service =
         new ObjectName(
             "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
   } catch (MalformedObjectNameException e) {
     throw new AssertionError(e.getMessage());
   }
 }
 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();
   }
 }
  static boolean execScript(String process, String script) {
    int vmid = -1;
    try {
      vmid = Integer.parseInt(process);
    } catch (NumberFormatException e) {
      vmid = findVmid(process);
    }
    if (vmid == -1) {
      System.err.println(process + ": Could not find process");
      return false;
    }

    try {
      JMXConnector jmxc;
      MBeanServerConnection server;

      String address = ConnectorAddressLink.importFrom(vmid);
      JMXServiceURL jmxUrl = new JMXServiceURL(address);
      jmxc = JMXConnectorFactory.connect(jmxUrl);
      server = jmxc.getMBeanServerConnection();
      Object[] parameters = {script};
      String[] signature = {"java.lang.String"};
      Object result;
      result =
          server.invoke(
              new ObjectName("net.multiverse:type=Engine"),
              "runPythonScript",
              parameters,
              signature);
      System.out.println(result.toString());
      jmxc.close();
    } catch (IOException e) {
      System.err.println("Unable to attach to " + vmid + ": " + e.getMessage());
      return false;
    } catch (javax.management.MalformedObjectNameException e) {
      System.err.println("Internal error: " + e.getMessage());
      return false;
    } catch (javax.management.InstanceNotFoundException e) {
      System.err.println("Process " + vmid + " is not a Multiverse engine");
      return false;
    } catch (javax.management.MBeanException e) {
      System.err.println("Error: " + e);
      return false;
    } catch (javax.management.ReflectionException e) {
      System.err.println("Error: " + e);
      return false;
    }
    return true;
  }
Пример #7
0
  public static void putPocessTiming(
      String projectId, String userId, String domainId, ParamType paramType) {
    // get cache
    try {
      Cache cache = CacheUtil.getCache();
      Node rootNode = cache.getRoot();
      String roleTree = domainId + "/" + projectId + "/" + userId + "/" + PM_ENABLE_PROCESS_TIMING;
      rootNode.put(roleTree, paramType.getValue());

    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.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();
    }
  }
Пример #9
0
  public static String clearPocessTiming(String projectId, String userId, String domainId) {
    String processTimingPMFlag = "NONE";
    // get cache
    try {

      Node rootNode = CacheUtil.getCache().getRoot();
      processTimingPMFlag =
          (String)
              rootNode.put(
                  domainId + "/" + projectId + "/" + userId + "/" + PM_ENABLE_PROCESS_TIMING, null);
    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    }
    return processTimingPMFlag;
  }
  public void start() {
    this.mbeanServer = ManagementFactory.getPlatformMBeanServer();

    try {
      platformMonitor = new ObjectName(OBJECT_NAME);
      this.mbeanServer.registerMBean(this, platformMonitor);

    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    } catch (InstanceAlreadyExistsException e) {
      e.printStackTrace();
    } catch (MBeanRegistrationException e) {
      e.printStackTrace();
    } catch (NotCompliantMBeanException e) {
      e.printStackTrace();
    }
  }
 public RemoteBundle(BundleInfo bInfo, RemoteGateway gateway, ManageableEntity parent) {
   this.info = bInfo;
   this.gateway = gateway;
   this.parent = parent;
   if (parent != null) {
     this.connection = parent.getConnection();
   }
   try {
     this.on =
         new ObjectName(
             Constants.OSGI_JMX_PATH
                 + "type=bundles,url="
                 + gateway.getUrl()
                 + ",name="
                 + this.info.getName());
     EntitiesEventManager.getInstance().listenTo(this);
   } catch (MalformedObjectNameException e) {
     e.printStackTrace();
   } catch (NullPointerException e) {
     e.printStackTrace();
   }
 }
Пример #12
0
 /**
  * Registers a logger to the management server.
  *
  * @param logger A logger to be registered for management.
  */
 public static synchronized void register(Logger logger) {
   try {
     ManagementFactory.getPlatformMBeanServer()
         .createMBean(
             "com.hapiware.jmx.log4j.Logging",
             new ObjectName(LOGGING_NAME),
             new Object[] {logger.getLoggerRepository()},
             new String[] {"org.apache.log4j.spi.LoggerRepository"});
   } catch (MBeanException e) {
     e.printStackTrace();
   } catch (InstanceAlreadyExistsException e) {
     e.printStackTrace();
   } catch (NotCompliantMBeanException e) {
     e.printStackTrace();
   } catch (MalformedObjectNameException e) {
     e.printStackTrace();
   } catch (ReflectionException e) {
     e.printStackTrace();
   } catch (NullPointerException 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();
    }
  }
Пример #14
0
  /**
   * Gets the initial file name.
   *
   * @param jvm The active JVM
   * @return The file name, or <tt>null</tt> if file name is specified
   * @throws JvmCoreException
   */
  String getInitialFileName(IActiveJvm jvm) throws JvmCoreException {

    ObjectName objectName;
    try {
      objectName = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
    } catch (MalformedObjectNameException e) {
      throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
    } catch (NullPointerException e) {
      throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
    }

    TabularData initialName =
        (TabularData)
            jvm.getMBeanServer().getAttribute(objectName, "SystemProperties"); // $NON-NLS-1$
    CompositeData compisiteData = initialName.get(new Object[] {"user.home"}); // $NON-NLS-1$
    String home = compisiteData.values().toArray(new String[0])[1];
    StringBuffer initialFileName = new StringBuffer(home);
    initialFileName
        .append(File.separator)
        .append(new Date().getTime())
        .append('.')
        .append(SnapshotType.Hprof.getExtension());
    return initialFileName.toString();
  }
  public CreateResourceReport createResource(CreateResourceReport report) {

    JBossASServerComponent parentResourceComponent =
        getResourceContext().getParentResourceComponent();

    String resourceTypeName = report.getResourceType().getName();

    String objectNamePreString;
    boolean isTopic = false;
    if (resourceTypeName.contains("Topic")) {
      objectNamePreString = TOPIC_MBEAN_NAME;
      isTopic = true;
    } else {
      objectNamePreString = QUEUE_MBEAN_NAME;
    }

    Configuration config = report.getResourceConfiguration();

    String name = config.getSimple("MBeanName").getStringValue();
    PropertySimple nameTemplateProp = report.getPluginConfiguration().getSimple("nameTemplate");
    String rName = nameTemplateProp.getStringValue();
    //noinspection ConstantConditions
    rName = rName.replace("{name}", name);

    EmsConnection connection = parentResourceComponent.getEmsConnection();

    if (DeploymentUtility.isDuplicateJndiName(connection, objectNamePreString, name)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage("Duplicate JNDI Name, a resource with that name already exists");
      return report;
    }
    PropertySimple pluginNameProperty = new PropertySimple("name", rName);
    getResourceContext().getPluginConfiguration().put(pluginNameProperty);

    File deployDir = new File(parentResourceComponent.getConfigurationPath() + "/deploy");
    File deploymentFile =
        new File(deployDir, FileNameUtility.formatFileName(name) + "-destination-service.xml");

    xmlEditor = new JBossMessagingConfigurationEditor(resourceTypeName);
    xmlEditor.updateConfiguration(deploymentFile, name, report);
    try {
      parentResourceComponent.deployFile(deploymentFile);
    } catch (Exception e) {
      JBossASServerComponent.setErrorOnCreateResourceReport(report, e.getLocalizedMessage(), e);
      return report;
    }

    // This key needs to be the same as the object name string used in discovery, defined in the
    // plugin descriptor
    //   jboss.messaging.destination:service=<Queue|Topic>,name=%name%
    String serviceString = (isTopic ? "Topic" : "Queue");

    String objectName = "jboss.messaging.destination:name=" + name + ",service=" + serviceString;
    try {
      // IMPORTANT: The object name must be canonicalized so it matches the resource key that
      //            MBeanResourceDiscoveryComponent uses, which is the canonical object name.
      objectName = getCanonicalName(objectName);
      report.setResourceKey(objectName);
    } catch (MalformedObjectNameException e) {
      log.warn("Invalid key [" + objectName + "]: " + e.getMessage());
      return report;
    }
    report.setResourceName(rName);

    try {
      Thread.sleep(5000L);
    } catch (InterruptedException e) {
      log.info("Sleep after datasource create interrupted", e);
      Thread.currentThread().interrupt();
    }

    return report;
  }
Пример #16
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();
    }
  }