pocozh commented on code in PR #5301: URL: https://github.com/apache/inlong/pull/5301#discussion_r935086158
########## 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 + } + + @Override + public void init() { + // starting metrics server + int metricsServerPort = AgentConfiguration.getAgentConf() + .getInt(PROMETHEUS_EXPORTER_PORT, DEFAULT_PROMETHEUS_EXPORTER_PORT); Review Comment: > If there are multiple listeners later, it should be a listener object corresponding to a processing class, so even if there are multiple ports, each class initializes itself. Or that the listener will correspond to multiple ports. If this is the case, is it okay to wait until there is such a business and then modify it? Okay, let's improve it later. -- 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]
