public static JmxAttributePollConfig<Void> forMultiple() { return new JmxAttributePollConfig<Void>(PollConfig.NO_SENSOR); }
public static <T> JmxAttributePollConfig<T> forSensor(AttributeSensor<T> sensor) { return new JmxAttributePollConfig<T>(sensor); }
@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(); }
@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(); }
if (!config.isEnabled()) continue; @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);
.entity(this) .period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP) .objectName(serverMbeanName) .attributeName("running") .onSuccess(Functions.forPredicate(Predicates.<Object>equalTo(true))) .setOnFailureOrException(false)) .pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT) .objectName(statsMbeanName) .attributeName("requests") .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_4XX_COUNT) .objectName(statsMbeanName) .attributeName("responses4xx")) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_5XX_COUNT) .objectName(statsMbeanName) .attributeName("responses5xx")) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(statsMbeanName) .attributeName("requestTimeTotal")) .pollAttribute(new JmxAttributePollConfig<Integer>(MAX_PROCESSING_TIME) .objectName(statsMbeanName) .attributeName("requestTimeMax"))
@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(); } }
.pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.USED_HEAP_MEMORY) .objectName(ManagementFactory.MEMORY_MXBEAN_NAME) .attributeName("HeapMemoryUsage") return (input == null) ? null : input.getUsed(); }}))) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.INIT_HEAP_MEMORY) .objectName(ManagementFactory.MEMORY_MXBEAN_NAME) .attributeName("HeapMemoryUsage") return (input == null) ? null : input.getInit(); }}))) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.COMMITTED_HEAP_MEMORY) .objectName(ManagementFactory.MEMORY_MXBEAN_NAME) .attributeName("HeapMemoryUsage") return (input == null) ? null : input.getCommitted(); }}))) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.MAX_HEAP_MEMORY) .objectName(ManagementFactory.MEMORY_MXBEAN_NAME) .attributeName("HeapMemoryUsage") return (input == null) ? null : input.getMax(); }}))) .pollAttribute(new JmxAttributePollConfig<Long>(UsesJavaMXBeans.NON_HEAP_MEMORY_USAGE) .objectName(ManagementFactory.MEMORY_MXBEAN_NAME) .attributeName("NonHeapMemoryUsage") .pollAttribute(new JmxAttributePollConfig<Integer>(UsesJavaMXBeans.CURRENT_THREAD_COUNT)
@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(); }
.entity(this) .period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP) .onException(Functions.constant(false)) .suppressDuplicates(true)) .pollAttribute(new JmxAttributePollConfig<Integer>(ERROR_COUNT) .objectName(requestProcessorMbeanName) .attributeName("errorCount") .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT) .objectName(requestProcessorMbeanName) .attributeName("requestCount") .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(requestProcessorMbeanName) .attributeName("processingTime")
.entity(this) .period(3000, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_PROCESS_IS_RUNNING) .setOnFailureOrException(false) .suppressDuplicates(true)) .pollAttribute(new JmxAttributePollConfig<String>(CONNECTOR_STATUS) .objectName(connectorMbeanName) .attributeName("stateName") .suppressDuplicates(true)) .pollAttribute(new JmxAttributePollConfig<Integer>(ERROR_COUNT) .objectName(requestProcessorMbeanName) .attributeName("errorCount") .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT) .objectName(requestProcessorMbeanName) .attributeName("requestCount") .enabled(retrieveUsageMetrics) .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(requestProcessorMbeanName) .attributeName("processingTime")
@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; } })
.entity(this) .period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Long>(FETCH_REQUEST_COUNT) .objectName(SOCKET_SERVER_STATS_MBEAN) .attributeName("NumFetchRequests") .onException(Functions.constant(-1l)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Long>(TOTAL_FETCH_TIME) .objectName(SOCKET_SERVER_STATS_MBEAN) .attributeName("TotalFetchRequestMs") .onException(Functions.constant(-1l)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Double>(MAX_FETCH_TIME) .objectName(SOCKET_SERVER_STATS_MBEAN) .attributeName("MaxFetchRequestMs") .onException(Functions.constant(-1.0d)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Long>(PRODUCE_REQUEST_COUNT) .objectName(SOCKET_SERVER_STATS_MBEAN) .attributeName("NumProduceRequests") .onException(Functions.constant(-1l)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Long>(TOTAL_PRODUCE_TIME) .objectName(SOCKET_SERVER_STATS_MBEAN) .attributeName("TotalProduceRequestMs") .onException(Functions.constant(-1l)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Double>(MAX_PRODUCE_TIME) .objectName(SOCKET_SERVER_STATS_MBEAN)
@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(); }
.pollAttribute(new JmxAttributePollConfig<Map>(mapAttribute) .objectName(objectName) .attributeName(attributeName)
@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()); } }