You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/08/01 09:16:43 UTC

[GitHub] [inlong] dockerzhang commented on a diff in pull request #5301: [INLONG-4958][Agent] Unify the exposed metrics for the Agent

dockerzhang commented on code in PR #5301:
URL: https://github.com/apache/inlong/pull/5301#discussion_r934309376


##########
inlong-agent/conf/agent.properties:
##########
@@ -112,14 +112,13 @@ agent.manager.auth.secretKey=
 
 
 ############################
-# prometheus config
+# metric config
 ############################
-# whether to enable prometheus
-agent.prometheus.enable=true
+metricDomains=Agent

Review Comment:
    it's designed for `agent`, maybe the `metricDomains` param is needless? 



##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/channel/MemoryChannel.java:
##########
@@ -54,12 +54,12 @@ public void push(Message message) {
                 if (message instanceof ProxyMessage) {
                     groupId = ((ProxyMessage) message).getInlongGroupId();
                 }
-                GlobalMetrics.incReadNum(groupId);
+                AgentMetricSingleton.getAgentMetricHandler().globalMetrics.incReadNum(groupId);

Review Comment:
   it's better to add a global variate for `AgentMetricSingleton.getAgentMetricHandler().globalMetrics`.



##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/metrics/AgentMetricSingleton.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.inlong.agent.metrics;
+
+import org.apache.commons.lang3.ClassUtils;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.inlong.agent.constant.AgentConstants.AGENT_METRIC_LISTENER_CLASS;
+import static org.apache.inlong.agent.constant.AgentConstants.AGENT_METRIC_LISTENER_CLASS_DEFAULT;
+
+/**
+ * metric singleton
+ */
+public class AgentMetricSingleton {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(AgentMetricSingleton.class);
+    private static AgentMetricBaseHandler agentMetricBaseHandler;
+
+    private AgentMetricSingleton() {
+    }
+
+    public static AgentMetricBaseHandler getAgentMetricHandler() {
+        if (agentMetricBaseHandler == null) {
+            synchronized (AgentJmxMetricHandler.class) {
+                if (agentMetricBaseHandler == null) {
+                    agentMetricBaseHandler = getAgentMetricByConf();
+                    agentMetricBaseHandler.init();
+                }
+            }
+        }
+        return agentMetricBaseHandler;
+    }
+
+    private static AgentMetricBaseHandler getAgentMetricByConf() {
+        AgentConfiguration conf = AgentConfiguration.getAgentConf();
+        try {
+            Class<?> handlerClass = ClassUtils
+                    .getClass(conf.get(AGENT_METRIC_LISTENER_CLASS, AGENT_METRIC_LISTENER_CLASS_DEFAULT));
+            Object handlerObject = handlerClass.getDeclaredConstructor().newInstance();
+            //
+            // final MetricListener listener = (MetricListener) listenerObject;

Review Comment:
   Remove commented code?



-- 
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: commits-unsubscribe@inlong.apache.org

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