jojochuang commented on code in PR #3949:
URL: https://github.com/apache/ambari/pull/3949#discussion_r2053285581


##########
ambari-server/conf/unix/metrics.properties:
##########
@@ -19,12 +19,13 @@
 
 #################### Metrics Source Configs #####################
 
-#Metric sources : jvm,database
+#Metric sources : jvm,database, stats

Review Comment:
   I'd suggest to add a section in user doc so users can discover this more 
easily.



##########
ambari-server/src/main/java/org/apache/ambari/server/metrics/system/impl/MetricsConfiguration.java:
##########
@@ -124,4 +124,30 @@ public static MetricsConfiguration 
getSubsetConfiguration(MetricsConfiguration m
 
     return new MetricsConfiguration(subsetProperties);
   }
+
+  /**
+   * For enabling stompStats Metrics, append 'stats' in metric.sources.
+   * @return true if StompStatsMetricsSource is configured, false otherwise.
+   */
+  public static boolean isStompStatMetricsConfigured() {
+    MetricsConfiguration configuration = getMetricsConfiguration();
+    String commaSeparatedSources = configuration.getProperty("metric.sources");

Review Comment:
   no nullity check is a potential problem.



##########
ambari-server/src/main/java/org/apache/ambari/server/metrics/system/impl/StompStatsMetricsSource.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     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.ambari.server.metrics.system.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.ambari.server.metrics.system.SingleMetric;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.socket.config.WebSocketMessageBrokerStats;
+
+/**
+ * Gets the metrics about stomp stats connections and publishes to configured
+ * Metric Sink.
+ */
+public class StompStatsMetricsSource extends AbstractMetricsSource {
+    public static final String[] metricsTypes = { "stomp.api", "stomp.agent" };
+    public static final String[] poolMetrics = { "pool_size", 
"active_threads", "queued_tasks", "completed_tasks" };
+    public static final String[] webSocketMetrics = { 
"current_client_session", "current_web_socket_session",
+            "current_http_stream", "current_http_polling",
+            "total_sessions_established", "abnormally_closed_session", 
"connect_failure_session",
+            "send_time_limit_exceeded", "transport_errors_sessions" };
+    public static final String[] stompSubProtocolMetrics = { "connect", 
"connected", "disconnect" };
+    private WebSocketMessageBrokerStats apiStompStats;
+    private WebSocketMessageBrokerStats agentStompStats;
+    private static final Logger LOG = 
LoggerFactory.getLogger(StompEventsMetricsSource.class);
+    private final ScheduledExecutorService executor = 
Executors.newScheduledThreadPool(1);
+
+    @Override
+    public void start() {
+        int interval = 60;
+        LOG.info("Starting stomp stat source.");
+        try {
+            executor.scheduleWithFixedDelay(new Runnable() {
+                @Override
+                public void run() {
+                    List<SingleMetric> events = getStompStatMetrics();
+                    if (!events.isEmpty()) {
+                        sink.publish(events);
+                        LOG.debug("********* Published stomp stat metrics to 
sink **********");
+                    }
+                }
+            }, interval, interval, TimeUnit.SECONDS);
+        } catch (Exception e) {
+            LOG.info("Throwing exception when starting stomp stat source", e);

Review Comment:
   ```suggestion
               LOG.info("Failed to start stomp stat source", e);
   ```



##########
ambari-server/src/main/java/org/apache/ambari/server/metrics/system/impl/MetricsConfiguration.java:
##########
@@ -124,4 +124,30 @@ public static MetricsConfiguration 
getSubsetConfiguration(MetricsConfiguration m
 
     return new MetricsConfiguration(subsetProperties);
   }
+
+  /**
+   * For enabling stompStats Metrics, append 'stats' in metric.sources.
+   * @return true if StompStatsMetricsSource is configured, false otherwise.
+   */
+  public static boolean isStompStatMetricsConfigured() {
+    MetricsConfiguration configuration = getMetricsConfiguration();
+    String commaSeparatedSources = configuration.getProperty("metric.sources");
+    if (StringUtils.isEmpty(commaSeparatedSources)) {
+      return false;
+    }
+
+    String[] sourceNames = commaSeparatedSources.split(",");
+    for (String sourceName : sourceNames) {
+      if (StringUtils.isEmpty(sourceName)) {
+        continue;
+      }
+      sourceName = sourceName.trim();
+
+      String className = configuration.getProperty("source." + sourceName + 
".class");

Review Comment:
   ditto.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@ambari.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ambari.apache.org
For additional commands, e-mail: dev-h...@ambari.apache.org

Reply via email to