Github user steveblackmon commented on a diff in the pull request:
https://github.com/apache/incubator-streams/pull/125#discussion_r20201858
--- Diff:
streams-monitoring/src/main/java/org/apache/streams/monitoring/tasks/BroadcastMonitorThread.java
---
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.streams.monitoring.tasks;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.collect.Lists;
+import org.apache.streams.jackson.*;
+import org.apache.streams.monitoring.persist.MessagePersister;
+import
org.apache.streams.monitoring.persist.impl.BroadcastMessagePersister;
+import org.apache.streams.pojo.json.*;
+import org.slf4j.Logger;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This thread runs inside of a Streams runtime and periodically persists
information
+ * from relevant JMX beans
+ */
+public class BroadcastMonitorThread extends NotificationBroadcasterSupport
implements Runnable {
+ private static final Logger LOGGER =
org.slf4j.LoggerFactory.getLogger(BroadcastMonitorThread.class);
+ private static MBeanServer server;
+
+ private long DEFAULT_WAIT_TIME = 30000;
+ private ObjectMapper objectMapper;
+ private Map<String, Object> streamConfig;
+ private String broadcastURI = null;
+ private MessagePersister messagePersister;
+ private volatile boolean keepRunning;
+
+ public BroadcastMonitorThread(Map<String, Object> streamConfig) {
+ keepRunning = true;
+ this.streamConfig = streamConfig;
+ server = ManagementFactory.getPlatformMBeanServer();
+
+ setBroadcastURI();
+ messagePersister = new BroadcastMessagePersister(broadcastURI);
+
+ initializeObjectMapper();
+ }
+
+ /**
+ * Initialize our object mapper with all of our bean's custom
deserializers
+ * This way we can convert them to and from Strings dictated by our
+ * POJOs which are generated from JSON schemas
+ */
+ private void initializeObjectMapper() {
+ objectMapper = new StreamsJacksonMapper();
+ SimpleModule simpleModule = new SimpleModule();
+
+ simpleModule.addDeserializer(MemoryUsageBroadcast.class, new
MemoryUsageDeserializer());
+ simpleModule.addDeserializer(ThroughputQueueBroadcast.class, new
ThroughputQueueDeserializer());
+ simpleModule.addDeserializer(StreamsTaskCounterBroadcast.class,
new StreamsTaskCounterDeserializer());
+ simpleModule.addDeserializer(DatumStatusCounterBroadcast.class,
new DatumStatusCounterDeserializer());
+
+ objectMapper.registerModule(simpleModule);
+
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
+ }
+
+ /**
+ * Get all relevant JMX beans, convert their values to strings, and
then persist them
+ */
+ @Override
+ public void run() {
+ while(keepRunning) {
+ try {
+ List<String> messages = Lists.newArrayList();
+ Set<ObjectName> beans = server.queryNames(null, null);
+
+ for(ObjectName name : beans) {
+ String item = objectMapper.writeValueAsString(name);
+ Broadcast broadcast = null;
+
+ if(name.getKeyPropertyList().get("type") != null) {
+ if
(name.getKeyPropertyList().get("type").equals("ThroughputQueue")) {
+ broadcast = objectMapper.readValue(item,
ThroughputQueueBroadcast.class);
+ } else if
(name.getKeyPropertyList().get("type").equals("StreamsTaskCounter")) {
+ broadcast = objectMapper.readValue(item,
StreamsTaskCounterBroadcast.class);
+ } else if
(name.getKeyPropertyList().get("type").equals("DatumStatusCounter")) {
+ broadcast = objectMapper.readValue(item,
DatumStatusCounterBroadcast.class);
+ } else if
(name.getKeyPropertyList().get("type").equals("Memory")) {
+ broadcast = objectMapper.readValue(item,
MemoryUsageBroadcast.class);
+ }
+
+ if(broadcast != null) {
+
messages.add(objectMapper.writeValueAsString(broadcast));
+ }
+ }
+ }
+
+ messagePersister.persistMessages(messages);
+ Thread.sleep(DEFAULT_WAIT_TIME);
--- End diff --
And have some convention to disable entirely, perhaps interval set to -1?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---