@Override protected void connectSensors() { String queue = String.format("org.apache.activemq:type=Broker,brokerName=%s,destinationType=Queue,destinationName=%s", getBrokerName(), getName()); jmxFeed = JmxFeed.builder() .entity(this) .helper(jmxHelper) .pollAttribute(new JmxAttributePollConfig<Integer>(QUEUE_DEPTH_MESSAGES) .objectName(queue) .attributeName("QueueSize")) .build(); }
@Override protected void connectSensors() { String queue = format("org.apache.qpid:type=VirtualHost.Queue,VirtualHost=\"%s\",name=\"%s\"", virtualHost, getName()); jmxFeed = JmxFeed.builder() .entity(this) .helper(jmxHelper) .pollAttribute(new JmxAttributePollConfig<Integer>(QUEUE_DEPTH_BYTES) .objectName(queue) .attributeName("QueueDepth")) .pollAttribute(new JmxAttributePollConfig<Integer>(QUEUE_DEPTH_MESSAGES) .objectName(queue) .attributeName("MessageCount")) .build(); }
@Test public void testJmxOperationPolledForSensor() throws Exception { // This is awful syntax... final int opReturnVal = 123; final AtomicInteger invocationCount = new AtomicInteger(); MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", new MBeanParameterInfo[0], Integer.class.getName(), MBeanOperationInfo.ACTION); GeneralisedDynamicMBean mbean = jmxService.registerMBean( Collections.emptyMap(), ImmutableMap.of(opInfo, new Function<Object[], Integer>() { @Override public Integer apply(Object[] args) { invocationCount.incrementAndGet(); return opReturnVal; }}), objectName); feed = JmxFeed.builder() .entity(entity) .pollOperation(new JmxOperationPollConfig<Integer>(intAttribute) .objectName(objectName) .operationName(opName)) .build(); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertTrue(invocationCount.get() > 0, "invocationCount="+invocationCount); assertEquals(entity.getAttribute(intAttribute), (Integer)opReturnVal); }}); }
@Test public void testJmxOperationWithArgPolledForSensor() throws Exception { // This is awful syntax... MBeanParameterInfo paramInfo = new MBeanParameterInfo("param1", String.class.getName(), "my param1"); MBeanParameterInfo[] paramInfos = new MBeanParameterInfo[] {paramInfo}; MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", paramInfos, String.class.getName(), MBeanOperationInfo.ACTION); GeneralisedDynamicMBean mbean = jmxService.registerMBean( Collections.emptyMap(), ImmutableMap.of(opInfo, new Function<Object[], String>() { @Override public String apply(Object[] args) { return args[0]+"suffix"; }}), objectName); feed = JmxFeed.builder() .entity(entity) .pollOperation(new JmxOperationPollConfig<String>(stringAttribute) .objectName(objectName) .operationName(opName) .operationParams(ImmutableList.of("myprefix"))) .build(); assertSensorEventually(stringAttribute, "myprefix"+"suffix", TIMEOUT_MS); }
@Override protected void connectSensors() { sensors().set(BROKER_URL, String.format("tcp://%s:%d", getAttribute(HOSTNAME), getAttribute(OPEN_WIRE_PORT))); String brokerMbeanName = "org.apache.activemq:type=Broker,brokerName=" + getBrokerName(); jmxFeed = JmxFeed.builder() .entity(this) .period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP) .objectName(brokerMbeanName) .attributeName("BrokerName") .onSuccess(Functions.forPredicate(Predicates.notNull())) .onFailureOrException(Functions.constant(false)) .suppressDuplicates(true)) .build(); }
@Override public JmxFeed call() throws Exception { JmxHelper helper = new JmxHelper(entity); JmxFeed feed = JmxFeed.builder() .entity(entity) .period(period) .helper(helper) .pollAttribute(new JmxAttributePollConfig<T>(sensor) .objectName(objectName) .attributeName(attribute) .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates)) .onFailureOrException(Functions.<T>constant((T) defaultValue))) .build(); entity.addFeed(feed); return feed; } })
@Test public void testJmxNotificationSubscriptionForSensor() throws Exception { final String one = "notification.one", two = "notification.two"; final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of(one, two), objectName); final AtomicInteger sequence = new AtomicInteger(0); feed = JmxFeed.builder() .entity(entity) .subscribeToNotification(new JmxNotificationSubscriptionConfig<Integer>(intAttribute) .objectName(objectName) .notificationFilter(JmxNotificationFilters.matchesType(one))) .build(); // Notification updates the sensor // Note that subscription is done async, so can't just send notification immediately during test. Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { sendNotification(mbean, one, sequence.getAndIncrement(), 123); assertEquals(entity.getAttribute(intAttribute), (Integer)123); }}); // But other notification types are ignored sendNotification(mbean, two, sequence.getAndIncrement(), -1); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertEquals(entity.getAttribute(intAttribute), (Integer)123); }}); }
@Test public void testJmxNotificationMultipleSubscriptionUsingListener() throws Exception { final String one = "notification.one"; final String two = "notification.two"; final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of(one, two), objectName); final AtomicInteger sequence = new AtomicInteger(0); feed = JmxFeed.builder() .entity(entity) .subscribeToNotification(new JmxNotificationSubscriptionConfig<Integer>(intAttribute) .objectName(objectName) .notificationFilter(JmxNotificationFilters.matchesTypes(one, two))) .build(); // Notification updates the sensor // Note that subscription is done async, so can't just send notification immediately during test. Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { sendNotification(mbean, one, sequence.getAndIncrement(), 123); assertEquals(entity.getAttribute(intAttribute), (Integer)123); }}); // And wildcard means other notifications also received sendNotification(mbean, two, sequence.getAndIncrement(), 456); assertSensorEventually(intAttribute, 456, TIMEOUT_MS); }
@Test public void testJmxNotificationSubscriptionForSensorParsingNotification() throws Exception { final String one = "notification.one", two = "notification.two"; final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of(one, two), objectName); final AtomicInteger sequence = new AtomicInteger(0); feed = JmxFeed.builder() .entity(entity) .subscribeToNotification(new JmxNotificationSubscriptionConfig<Integer>(intAttribute) .objectName(objectName) .notificationFilter(JmxNotificationFilters.matchesType(one)) .onNotification(new Function<Notification, Integer>() { @Override public Integer apply(Notification notif) { return (Integer) notif.getUserData(); } })) .build(); // Notification updates the sensor // Note that subscription is done async, so can't just send notification immediately during test. Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { sendNotification(mbean, one, sequence.getAndIncrement(), 123); assertEquals(entity.getAttribute(intAttribute), (Integer)123); }}); }
@Override protected void connectSensors() { super.connectSensors(); // Add a sensor that we can explicitly set in jmx feed = JmxFeed.builder() .entity(this) .pollAttribute(new JmxAttributePollConfig<String>(stringAttribute) .objectName(jmxObjectName) .attributeName(attributeName)) .build(); }
@Test public void testJmxAttributePollerReturnsMBeanAttribute() throws Exception { GeneralisedDynamicMBean mbean = jmxService.registerMBean(ImmutableMap.of(attributeName, 42), objectName); feed = JmxFeed.builder() .entity(entity) .pollAttribute(new JmxAttributePollConfig<Integer>(intAttribute) .objectName(objectName) .period(50) .attributeName(attributeName)) .build(); // Starts with value defined when registering... assertSensorEventually(intAttribute, 42, TIMEOUT_MS); // Change the value and check it updates mbean.updateAttributeValue(attributeName, 64); assertSensorEventually(intAttribute, 64, TIMEOUT_MS); }
@Override protected void connectSensors() { super.connectSensors(); String serverInfoMBeanName = "org.apache.qpid:type=ServerInformation,name=ServerInformation"; jmxFeed = JmxFeed.builder() .entity(this) .period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP) .objectName(serverInfoMBeanName) .attributeName("ProductVersion") .onSuccess(new Function<Object,Boolean>() { private boolean hasWarnedOfVersionMismatch; @Override public Boolean apply(Object input) { if (input == null) return false; if (!hasWarnedOfVersionMismatch && !getConfig(QpidBroker.SUGGESTED_VERSION).equals(input)) { log.warn("Qpid version mismatch: ProductVersion is {}, requested version is {}", input, getConfig(QpidBroker.SUGGESTED_VERSION)); hasWarnedOfVersionMismatch = true; } return true; }}) .onException(Functions.constant(false)) .suppressDuplicates(true)) .build(); }
feed = JmxFeed.builder() .entity(entity) .pollAttribute(new JmxAttributePollConfig<Map>(mapAttribute)
boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS); jmxWebFeed = JmxFeed.builder() .entity(this) .period(3000, TimeUnit.MILLISECONDS)
@Override protected void connectSensors() { connectServiceUpIsRunning(); if (((JavaSoftwareProcessDriver)getDriver()).isJmxEnabled()) { jmxFeed = JmxFeed.builder() .entity(this) .period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Long>(OUTSTANDING_REQUESTS) .objectName(ZOOKEEPER_MBEAN) .attributeName("OutstandingRequests") .onFailureOrException(Functions.constant(-1l))) .pollAttribute(new JmxAttributePollConfig<Long>(PACKETS_RECEIVED) .objectName(ZOOKEEPER_MBEAN) .attributeName("PacketsReceived") .onFailureOrException(Functions.constant(-1l))) .pollAttribute(new JmxAttributePollConfig<Long>(PACKETS_SENT) .objectName(ZOOKEEPER_MBEAN) .attributeName("PacketsSent") .onFailureOrException(Functions.constant(-1l))) .build(); } }
jmxFeed = JmxFeed.builder() .entity(this) .period(500, TimeUnit.MILLISECONDS)
String statsMbeanName = "org.mortbay.jetty.handler:type=atomicstatisticshandler,id=0"; jmxFeedJetty = JmxFeed.builder() .entity(this) .period(500, TimeUnit.MILLISECONDS)
@Override public void start(Collection<? extends Location> locs) { // TODO Auto-generated method stub super.start(locs); sensors().set(Attributes.HOSTNAME, "localhost"); sensors().set(UsesJmx.JMX_PORT, LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString("40123+"))); // only supports no-agent, at the moment config().set(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.NONE); sensors().set(UsesJmx.RMI_REGISTRY_PORT, -1); // -1 means to use the JMX_PORT only ConfigToAttributes.apply(this, UsesJmx.JMX_CONTEXT); JmxFeed.Builder feedBuilder = JmxFeed.builder() .entity(this) .pollAttribute(new JmxAttributePollConfig<String>(SENSOR_STRING) .objectName(OBJECT_NAME) .period(50) .attributeName(JMX_ATTRIBUTE_NAME)); if (getConfig(PRE_CREATE_JMX_HELPER)) { JmxHelper jmxHelper = new JmxHelper(this); feedBuilder.helper(jmxHelper); } addFeed(feedBuilder.build()); } }
@SuppressWarnings({"unchecked"}) public static JmxFeed.Builder getMxBeanSensorsBuilder(Entity entity, Duration jmxPollPeriod) { JmxFeed.Builder builder = JmxFeed.builder() .entity(entity) .period(jmxPollPeriod);
jmxFeed = JmxFeed.builder() .entity(this) .period(500, TimeUnit.MILLISECONDS)