Examples of GaugeMonitor


Examples of javax.management.monitor.GaugeMonitor

      return new GaugeMonitor();
   }

   public void testCorrectInitialization() throws Exception
   {
      GaugeMonitor monitor = (GaugeMonitor)createMonitor();
      assertEquals(new Integer(0), monitor.getHighThreshold());
      assertEquals(new Integer(0), monitor.getLowThreshold());
      assertFalse(monitor.getDifferenceMode());
      assertFalse(monitor.getNotifyHigh());
      assertFalse(monitor.getNotifyLow());
   }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

      assertFalse(monitor.getNotifyLow());
   }

   public void testSetThresholds() throws Exception
   {
      GaugeMonitor monitor = (GaugeMonitor)createMonitor();
      try
      {
         monitor.setThresholds(null, null);
         fail();
      }
      catch (IllegalArgumentException ignored)
      {
      }
      try
      {
         monitor.setThresholds(new Integer(0), null);
         fail();
      }
      catch (IllegalArgumentException ignored)
      {
      }
      try
      {
         monitor.setThresholds(null, new Integer(0));
         fail();
      }
      catch (IllegalArgumentException ignored)
      {
      }
      try
      {
         // Different types
         monitor.setThresholds(new Integer(1), new Long(0));
         fail();
      }
      catch (IllegalArgumentException ignored)
      {
      }
      try
      {
         // High less than low
         monitor.setThresholds(new Integer(0), new Integer(1));
         fail();
      }
      catch (IllegalArgumentException ignored)
      {
      }

      monitor.setThresholds(new Float(5.7), new Float(5.0));
   }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

   {
      ObjectName name = new ObjectName(":mbean=target");
      ObjectName monitorName = new ObjectName(":monitor=gauge");

      MBeanServer server = newMBeanServer();
      GaugeMonitor monitor = (GaugeMonitor)createMonitor();
      monitor.setDifferenceMode(true);
      monitor.addObservedObject(name);
      monitor.setObservedAttribute("Integer");
      int period = 1000;
      monitor.setGranularityPeriod(period);
      Integer high = new Integer(10);
      Integer low = new Integer(5);
      monitor.setThresholds(high, low);
      monitor.setNotifyHigh(true);
      monitor.setNotifyLow(false);
      server.registerMBean(monitor, monitorName);

      // Initial value < lowThreshold
      MonitorTarget target = new MonitorTarget();
      int value = low.intValue() - 1;
      target.setInteger(value);
      server.registerMBean(target, name);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      };
      server.addNotificationListener(monitorName, listener, null, null);
      monitor.start();

      try
      {
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Set gauge above high threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Set gauge inside threshold
         value = value + low.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Set gauge above threshold again
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
      }
      finally
      {
         monitor.stop();
      }
   }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

   {
      ObjectName name = new ObjectName(":mbean=target");
      ObjectName monitorName = new ObjectName(":monitor=gauge");

      MBeanServer server = newMBeanServer();
      GaugeMonitor monitor = (GaugeMonitor)createMonitor();
      monitor.setDifferenceMode(true);
      monitor.addObservedObject(name);
      monitor.setObservedAttribute("Integer");
      int period = 1000;
      monitor.setGranularityPeriod(period);
      Integer high = new Integer(5);
      Integer low = new Integer(0);
      monitor.setThresholds(high, low);
      monitor.setNotifyHigh(true);
      monitor.setNotifyLow(true);
      server.registerMBean(monitor, monitorName);

      // Initial gauge inside thresholds
      MonitorTarget target = new MonitorTarget();
      int value = low.intValue() + 1;
      target.setInteger(value);
      server.registerMBean(target, name);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      };
      server.addNotificationListener(monitorName, listener, null, null);
      monitor.start();

      try
      {
         // Inside the thresholds, be sure low notification
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Monitoring takes time, so I disable low notification to be sure to get only the high one
         // The monitor is in difference mode, so the first time will get the high notification, but
         // the second time will get zero, since the gauge did not change, which will triggers a low notification
         monitor.setNotifyLow(false);
         // Set gauge above high threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         monitor.setNotifyHigh(false);
         monitor.setNotifyLow(true);
         // Set gauge above high threshold, so just after goes below low threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Set gauge inside threshold
         value = value + low.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());
      }
      finally
      {
         monitor.stop();
      }
   }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

   {
      ObjectName name = new ObjectName(":mbean=target");
      ObjectName monitorName = new ObjectName(":monitor=gauge");

      MBeanServer server = newMBeanServer();
      GaugeMonitor monitor = (GaugeMonitor)createMonitor();
      monitor.setDifferenceMode(false);
      monitor.addObservedObject(name);
      monitor.setObservedAttribute("Integer");
      int period = 1000;
      monitor.setGranularityPeriod(period);
      server.registerMBean(monitor, monitorName);

      // Set initial gauge
      MonitorTarget target = new MonitorTarget();
      int gauge = 4;
      target.setInteger(gauge);
      server.registerMBean(target, name);

      monitor.start();

      try
      {
         sleep(period * 3);

         Number observed = monitor.getDerivedGauge(name);
         assertEquals(observed.intValue(), gauge);
      }
      finally
      {
         monitor.stop();
      }
   }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

    public void xtestNotificationsJmx() throws Exception {

        // Now let's register a Monitor
        // We would like to know if we have peaks in activity, so we can use JMX's
        // GaugeMonitor
        GaugeMonitor monitorMBean = new GaugeMonitor();
        ObjectName monitorName = new ObjectName("examples", "monitor", "gauge");
        server.registerMBean(monitorMBean, monitorName);
        // Setup the monitor: we want to be notified if we have too many clients or too less
        monitorMBean.setThresholds(new Integer(8), new Integer(4));
        // Setup the monitor: we want to know if a threshold is exceeded
        monitorMBean.setNotifyHigh(true);
        monitorMBean.setNotifyLow(true);

        monitorMBean.setDifferenceMode(false);
        // Setup the monitor: link to the service MBean
        monitorMBean.addObservedObject(serviceName);
        monitorMBean.setObservedAttribute("SimpleCounter");
        // Setup the monitor: a short granularity period
        monitorMBean.setGranularityPeriod(50L);
        // Setup the monitor: register a listener
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        final AtomicBoolean notificationSet = new AtomicBoolean(false);
        //Add a notification listener to the connection - to
        //test for notifications across camel
        connection.addNotificationListener(monitorName, new NotificationListener() {
            public void handleNotification(Notification notification, Object handback) {
                System.out.println("Notification = " + notification);
                synchronized (notificationSet) {
                    notificationSet.set(true);
                    notificationSet.notify();
                }
            }
        }, null, null);
        service.start();
        monitorMBean.start();
        synchronized (notificationSet) {
            if (!notificationSet.get()) {
                notificationSet.wait(5000);
            }
        }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

            counter.setModulus(ep.getModulus());
            counter.setDifferenceMode(ep.isDifferenceMode());
            counter.setNotify(true);
            bean = counter;
        } else if (ep.getMonitorType().equals("gauge")) {
            GaugeMonitor gm = new GaugeMonitor();
            gm.setNotifyHigh(ep.isNotifyHigh());
            gm.setNotifyLow(ep.isNotifyLow());
            gm.setDifferenceMode(ep.isDifferenceMode());
            Object attr = ManagementFactory.getPlatformMBeanServer().getAttribute(ep.getJMXObjectName(), ep.getObservedAttribute());
            Double highValue = ep.getThresholdHigh();
            Double lowValue = ep.getThresholdLow();
            if (attr instanceof Byte) {
                gm.setThresholds(highValue.byteValue(), lowValue.byteValue());
            } else if  (attr instanceof Integer) {
                gm.setThresholds(highValue.intValue(), lowValue.intValue());
            } else if (attr instanceof Short) {
                gm.setThresholds(highValue.shortValue(), lowValue.shortValue());
            } else if (attr instanceof Long) {
                gm.setThresholds(highValue.longValue(), lowValue.longValue());
            } else if (attr instanceof Float) {
                gm.setThresholds(highValue.floatValue(), lowValue.floatValue());
            } else {
                gm.setThresholds(highValue, lowValue);
            }
            bean = gm;
        } else if (ep.getMonitorType().equals("string")) {
            StringMonitor sm = new StringMonitor();
            sm.setNotifyDiffer(ep.isNotifyDiffer());
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

            counter.setModulus(modulus);
            counter.setDifferenceMode(ep.isDifferenceMode());
            counter.setNotify(true);
            bean = counter;
        } else if (ep.getMonitorType().equals("gauge")) {
            GaugeMonitor gm = new GaugeMonitor();
            gm.setNotifyHigh(ep.isNotifyHigh());
            gm.setNotifyLow(ep.isNotifyLow());
            gm.setDifferenceMode(ep.isDifferenceMode());
            Number highValue = convertNumberToAttributeType(ep.getThresholdHigh(), ep.getJMXObjectName(), ep.getObservedAttribute());
            Number lowValue = convertNumberToAttributeType(ep.getThresholdLow(), ep.getJMXObjectName(), ep.getObservedAttribute());
            gm.setThresholds(highValue, lowValue);
            bean = gm;
        } else if (ep.getMonitorType().equals("string")) {
            StringMonitor sm = new StringMonitor();
            sm.setNotifyDiffer(ep.isNotifyDiffer());
            sm.setNotifyMatch(ep.isNotifyMatch());
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

  public void setLowerThreshold(int lowerThreshold) {
    this.lowerThreshold = lowerThreshold;
  }

  public GaugeMonitor getObject() throws Exception {
    GaugeMonitor monitor = new GaugeMonitor();
    monitor.setNotifyHigh(true);
    monitor.addObservedObject(new ObjectName(String.format("%s:type=JobExecution,name=%s,step=%s", defaultDomain,
        jobName, stepName)));
    monitor.setObservedAttribute(observedAttribute);
    if (observedAttribute.endsWith("Duration")) {
      monitor.setThresholds(new Double(upperThreshold), new Double(lowerThreshold));
    }
    else {
      monitor.setThresholds(new Integer(upperThreshold), new Integer(lowerThreshold));
    }
    if (autoStart) {
      monitor.start();
    }
    return monitor;
  }
View Full Code Here

Examples of javax.management.monitor.GaugeMonitor

                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.