public void register() {
    registerMetric(
        registry,
        OPTIMIZER_GROUP_PENDING_TASKS,
        (Gauge<Integer>)
            () ->
                optimizingQueue
                    .collectTasks(
                        task ->
                            task.getStatus().equals(PLANNED) || task.getStatus().equals(SCHEDULED))
                    .size());
    registerMetric(
        registry,
        OPTIMIZER_GROUP_EXECUTING_TASKS,
        (Gauge<Integer>)
            () -> optimizingQueue.collectTasks(task -> task.getStatus().equals(ACKED)).size());

    registerMetric(
        registry,
        OPTIMIZER_GROUP_PLANING_TABLES,
        (Gauge<Long>)
            () ->
                optimizingQueue.getSchedulingPolicy().getTableRuntimeMap().values().stream()
                    .filter(t -> t.getOptimizingState().getOptimizingStatus().equals(PLANNING))
                    .count());
    registerMetric(
        registry,
        OPTIMIZER_GROUP_PENDING_TABLES,
        (Gauge<Long>)
            () ->
                optimizingQueue.getSchedulingPolicy().getTableRuntimeMap().values().stream()
                    .filter(t -> t.getOptimizingState().getOptimizingStatus().equals(PENDING))
                    .count());
    registerMetric(
        registry,
        OPTIMIZER_GROUP_EXECUTING_TABLES,
        (Gauge<Long>)
            () ->
                optimizingQueue.getSchedulingPolicy().getTableRuntimeMap().values().stream()
                    .filter(t -> t.getOptimizingState().getOptimizingStatus().isProcessing())
                    .count());
    registerMetric(
        registry,
        OPTIMIZER_GROUP_IDLE_TABLES,
        (Gauge<Long>)
            () ->
                optimizingQueue.getSchedulingPolicy().getTableRuntimeMap().values().stream()
                    .filter(t -> t.getOptimizingState().getOptimizingStatus().equals(IDLE))
                    .count());
    registerMetric(
        registry,
        OPTIMIZER_GROUP_COMMITTING_TABLES,
        (Gauge<Long>)
            () ->
                optimizingQueue.getSchedulingPolicy().getTableRuntimeMap().values().stream()
                    .filter(t -> t.getOptimizingState().getOptimizingStatus().equals(COMMITTING))
                    .count());

    registerMetric(
        registry, OPTIMIZER_GROUP_OPTIMIZER_INSTANCES, (Gauge<Integer>) optimizerInstances::size);
    registerMetric(
        registry,
        OPTIMIZER_GROUP_MEMORY_BYTES_ALLOCATED,
        (Gauge<Long>)
            () ->
                optimizerInstances.values().stream()
                    .mapToLong(OptimizerInstance::getMemoryMb)
                    .map(mb -> mb * 1024 * 1024)
                    .sum());
    registerMetric(
        registry,
        OPTIMIZER_GROUP_THREADS,
        (Gauge<Long>)
            () ->
                optimizerInstances.values().stream()
                    .mapToLong(OptimizerInstance::getThreadCount)
                    .sum());
  }
Metrics manager for an optimizer group.
amoro-ams/src/main/java/org/apache/amoro/server/optimizing/OptimizerGroupMetrics.java