justinwwhuang commented on code in PR #10752: URL: https://github.com/apache/inlong/pull/10752#discussion_r1704868101
########## inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/AgentStatusManager.java: ########## @@ -0,0 +1,279 @@ +/* + * 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.core; + +import org.apache.inlong.agent.conf.AgentConfiguration; +import org.apache.inlong.agent.constant.CommonConstants; +import org.apache.inlong.agent.core.task.MemoryManager; +import org.apache.inlong.agent.core.task.OffsetManager; +import org.apache.inlong.agent.core.task.TaskManager; +import org.apache.inlong.agent.utils.AgentUtils; +import org.apache.inlong.agent.utils.ExcuteLinux; +import org.apache.inlong.common.constant.ProtocolType; +import org.apache.inlong.sdk.dataproxy.DefaultMessageSender; +import org.apache.inlong.sdk.dataproxy.ProxyClientConfig; +import org.apache.inlong.sdk.dataproxy.common.SendResult; + +import com.google.common.collect.Lists; +import io.netty.util.concurrent.DefaultThreadFactory; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; +import java.lang.management.RuntimeMXBean; +import java.lang.management.ThreadMXBean; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import static org.apache.inlong.agent.constant.AgentConstants.AGENT_CLUSTER_NAME; +import static org.apache.inlong.agent.constant.AgentConstants.AGENT_CLUSTER_TAG; +import static org.apache.inlong.agent.constant.AgentConstants.AGENT_INSTALL_PLATFORM; +import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_READER_QUEUE_PERMIT; +import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_READER_SOURCE_PERMIT; +import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_WRITER_PERMIT; +import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_ADDR; +import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_AUTH_SECRET_ID; +import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_AUTH_SECRET_KEY; + +/** + * Collect various indicators of agent processes for backend problem analysis + */ +public class AgentStatusManager { + + private static final Logger LOGGER = LoggerFactory.getLogger(AgentStatusManager.class); + public static final String INLONG_AGENT_SYSTEM = "inlong_agent_system"; + public static final String INLONG_AGENT_STATUS = "inlong_agent_status"; + + private static AgentStatusManager manager = null; + private final AgentConfiguration conf; + private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 设置格式 + private Runtime runtime = Runtime.getRuntime(); + final long GB = 1024 * 1024 * 1024; + private OperatingSystemMXBean osMxBean; + private ThreadMXBean threadBean; + private long INVALID_CPU = -1; + private RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); + private ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + private AgentManager agentManager; + public static AtomicLong sendDataLen = new AtomicLong(); + public static AtomicLong sendPackageCount = new AtomicLong(); + private DefaultMessageSender sender; + private List<String> statusFieldsPre = Lists.newArrayList(); + private String processStartupTime = format.format(runtimeMXBean.getStartTime()); + private String systemStartupTime = ExcuteLinux.exeCmd("who -b|awk '{print $(NF-1), $NF}'").replaceAll("\r|\n", ""); + + private AgentStatusManager(AgentManager agentManager) { + this.agentManager = agentManager; + this.conf = AgentConfiguration.getAgentConf(); + osMxBean = ManagementFactory.getOperatingSystemMXBean(); + threadBean = ManagementFactory.getThreadMXBean(); + initStatusFieldsPre(); + createMessageSender(); + } + + public static AgentStatusManager getInstance(AgentManager agentManager) { + if (manager == null) { + synchronized (AgentStatusManager.class) { + if (manager == null) { + manager = new AgentStatusManager(agentManager); + } + } + } + return manager; + } + + public static AgentStatusManager getInstance() { + if (manager == null) { + throw new RuntimeException("HeartbeatManager has not been initialized by agentManager"); + } + return manager; + } + + public void sendStatusMsg(List<String> fields) { + if (sender == null) { + LOGGER.error("sender is null"); + createMessageSender(); + return; + } + SendResult ret = sender.sendMessage( Review Comment: there is an return -- 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-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org