@SuppressWarnings({ "rawtypes", "unchecked" }) JmxAttributePollConfig<?> configCopy = new JmxAttributePollConfig(config); if (configCopy.getPeriod() < 0) configCopy.period(builder.period, builder.periodUnits); attributePolls.put(configCopy.getObjectName().getCanonicalName() + configCopy.getAttributeName(), configCopy);
@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); }
.period(60, TimeUnit.SECONDS) .attributeName("StartTime")) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.UP_TIME) .objectName(ManagementFactory.RUNTIME_MXBEAN_NAME) .period(60, TimeUnit.SECONDS) .attributeName("Uptime")) .pollAttribute(new JmxAttributePollConfig<Integer>(UsesJavaMXBeans.AVAILABLE_PROCESSORS) .objectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME) .period(60, TimeUnit.SECONDS) .attributeName("AvailableProcessors")) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.TOTAL_PHYSICAL_MEMORY_SIZE) .objectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME) .period(60, TimeUnit.SECONDS) .attributeName("TotalPhysicalMemorySize")) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.FREE_PHYSICAL_MEMORY_SIZE) .objectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME) .period(60, TimeUnit.SECONDS) .attributeName("FreePhysicalMemorySize"));
@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()); } }