@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");
  }
 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();
   }
 }
예제 #3
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();
    }
  }
예제 #5
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();
   }
 }
예제 #8
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();
    }
  }