This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new c5350c1220 [INLONG-9263][Agent] Print the statistics of task and 
instance not detail (#9264)
c5350c1220 is described below

commit c5350c122007985adc4334acbe2be4c1d8e0c5eb
Author: justinwwhuang <hww_jus...@163.com>
AuthorDate: Sat Nov 11 21:46:46 2023 +0800

    [INLONG-9263][Agent] Print the statistics of task and instance not detail 
(#9264)
---
 .../agent/core/instance/InstanceManager.java       | 41 +++++++++++++++--
 .../inlong/agent/core/task/file/TaskManager.java   | 53 +++++++++++++++++++---
 2 files changed, 83 insertions(+), 11 deletions(-)

diff --git 
a/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/instance/InstanceManager.java
 
b/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/instance/InstanceManager.java
index d4a278a974..c7835cd355 100644
--- 
a/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/instance/InstanceManager.java
+++ 
b/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/instance/InstanceManager.java
@@ -69,6 +69,39 @@ public class InstanceManager extends AbstractDaemon {
     private volatile boolean runAtLeastOneTime = false;
     private volatile boolean running = false;
 
+    private class InstancePrintStat {
+
+        public int defaultCount = 0;
+        public int finishedCount = 0;
+        public int deleteCount = 0;
+        public int otherCount = 0;
+
+        private void stat(InstanceStateEnum state) {
+            switch (state) {
+                case DEFAULT: {
+                    defaultCount++;
+                    break;
+                }
+                case FINISHED: {
+                    finishedCount++;
+                    break;
+                }
+                case DELETE: {
+                    deleteCount++;
+                }
+                default: {
+                    otherCount++;
+                }
+            }
+        }
+
+        @Override
+        public String toString() {
+            return String.format("default %d finished %d delete %d other %d", 
defaultCount, finishedCount,
+                    deleteCount, otherCount);
+        }
+    }
+
     /**
      * Init task manager.
      */
@@ -130,13 +163,13 @@ public class InstanceManager extends AbstractDaemon {
             LOGGER.info("instanceManager coreThread running! taskId {} action 
count {}", taskId,
                     actionQueue.size());
             List<InstanceProfile> instances = instanceDb.getInstances(taskId);
+            InstancePrintStat stat = new InstancePrintStat();
             for (int i = 0; i < instances.size(); i++) {
                 InstanceProfile instance = instances.get(i);
-                LOGGER.info(
-                        "instanceManager coreThread instance taskId {} index 
{} total {} instanceId {} state {}",
-                        taskId, i,
-                        instances.size(), instance.getInstanceId(), 
instance.getState());
+                stat.stat(instance.getState());
             }
+            LOGGER.info("instanceManager coreThread running! taskId {} memory 
total {} db total {} db detail {} ",
+                    taskId, instanceMap.size(), instances.size(), stat);
             lastPrintTime = AgentUtils.getCurrentTime();
         }
     }
diff --git 
a/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/task/file/TaskManager.java
 
b/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/task/file/TaskManager.java
index b4cb79a48c..6724247c77 100644
--- 
a/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/task/file/TaskManager.java
+++ 
b/inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/task/file/TaskManager.java
@@ -78,6 +78,45 @@ public class TaskManager extends AbstractDaemon {
     // instance profile queue.
     private final BlockingQueue<TaskAction> actionQueue;
 
+    private class TaskPrintStat {
+
+        public int newCount = 0;
+        public int runningCont = 0;
+        public int frozenCount = 0;
+        public int finishedCount = 0;
+        public int otherCount = 0;
+
+        private void stat(TaskStateEnum state) {
+            switch (state) {
+                case NEW: {
+                    newCount++;
+                    break;
+                }
+                case RUNNING: {
+                    runningCont++;
+                    break;
+                }
+                case FROZEN: {
+                    frozenCount++;
+                    break;
+                }
+                case FINISH: {
+                    finishedCount++;
+                    break;
+                }
+                default: {
+                    otherCount++;
+                }
+            }
+        }
+
+        @Override
+        public String toString() {
+            return String.format("new %d running %d frozen %d finished %d 
other %d", newCount, runningCont, frozenCount,
+                    finishedCount, otherCount);
+        }
+    }
+
     /**
      * Init task manager.
      */
@@ -158,16 +197,16 @@ public class TaskManager extends AbstractDaemon {
 
     private void printTaskDetail() {
         if (AgentUtils.getCurrentTime() - lastPrintTime > 
CORE_THREAD_PRINT_TIME) {
-            LOGGER.info("taskManager coreThread running!");
-            List<TaskProfile> tasks = taskDb.getTasks();
-            for (int i = 0; i < tasks.size(); i++) {
-                TaskProfile task = tasks.get(i);
-                LOGGER.info("taskManager coreThread task index {} total {} 
taskId {} state {}",
-                        i, tasks.size(), task.getTaskId(), task.getState());
+            List<TaskProfile> tasksInDb = taskDb.getTasks();
+            TaskPrintStat stat = new TaskPrintStat();
+            for (int i = 0; i < tasksInDb.size(); i++) {
+                TaskProfile task = tasksInDb.get(i);
+                stat.stat(task.getState());
             }
+            LOGGER.info("taskManager coreThread running! memory total {} db 
total {} db detail {} ", taskMap.size(),
+                    tasksInDb.size(), stat);
             lastPrintTime = AgentUtils.getCurrentTime();
         }
-
     }
 
     private void dealWithConfigQueue(BlockingQueue<List<TaskProfile>> queue) {

Reply via email to