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


##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/metrics/AgentPrometheusMetricHandler.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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 io.prometheus.client.exporter.HTTPServer;
+import io.prometheus.client.hotspot.DefaultExports;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.metrics.global.PrometheusGlobalMetrics;
+import org.apache.inlong.agent.metrics.job.JobPrometheusMetrics;
+import org.apache.inlong.agent.metrics.task.TaskPrometheusMetrics;
+import org.apache.inlong.common.metric.MetricItemValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+
+import static 
org.apache.inlong.agent.constant.AgentConstants.DEFAULT_PROMETHEUS_EXPORTER_PORT;
+import static 
org.apache.inlong.agent.constant.AgentConstants.PROMETHEUS_EXPORTER_PORT;
+
+/**
+ * prometheus metric handler
+ */
+public class AgentPrometheusMetricHandler extends AgentMetricBaseHandler {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AgentPrometheusMetricHandler.class);
+    private static HTTPServer metricsServer;
+
+    static {
+        DefaultExports.initialize();
+    }
+
+    public AgentPrometheusMetricHandler() {
+        jobMetrics = new JobPrometheusMetrics();
+        taskMetrics = new TaskPrometheusMetrics();
+        globalMetrics = new PrometheusGlobalMetrics();
+    }
+
+    @Override
+    public void snapshot(String domain, List<MetricItemValue> itemValues) {
+        // nothing

Review Comment:
   How to snapshot data and report data to metricsServer?



##########
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;
+            // Constructor<?> constructor =
+            //         Class.forName(conf.get(AGENT_METRIC_LISTENER_CLASS, 
AGENT_METRIC_LISTENER_CLASS_DEFAULT))
+            //                 
.getDeclaredConstructor(AgentMetricBaseHandler.class);
+            // constructor.setAccessible(true);
+            return (AgentMetricBaseHandler) handlerObject;
+        } catch (Exception ex) {
+            LOGGER.error("cannot find AgentMetricBaseHandler, {}", 
ex.getMessage());
+        }
+        return null;
+    }
+
+    public static void init() {
+        getAgentMetricHandler();

Review Comment:
   The method "init" invoke the method "getAgentMetricHandler".
   The method "getAgentMetricHandler" invoke the method "init".



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to