Skip to content

Commit

Permalink
complete EsCollector,format
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFatRatre committed Nov 13, 2024
1 parent ebc5e0e commit e29ebd4
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,75 @@
**/
@Data
public class Metrics {

/**
* 正在执行任务的活跃线程大致总数
*/
private int activeCount;

/**
* 大致任务总数
*/
private long taskCount;

/**
* 执行超时任务数量
*/
private long runTimeoutCount;

/**
* 是否为DtpExecutor
*/
private boolean dynamic;

/**
* tps
*/
private double tps;

/**
* 最大任务耗时
*/
private long maxRt;

/**
* 最小任务耗时
*/
private long minRt;

/**
* 任务平均耗时(单位:ms)
*/
private double avg;

/**
* 满足50%的任务执行所需的最低耗时
*/
private double tp50;

/**
* 满足75%的任务执行所需的最低耗时
*/
private double tp75;

/**
* 满足90%的任务执行所需的最低耗时
*/
private double tp90;

/**
* 满足95%的任务执行所需的最低耗时
*/
private double tp95;

/**
* 满足99%的任务执行所需的最低耗时
*/
private double tp99;

/**
* 满足99.9%的任务执行所需的最低耗时
*/
private double tp999;

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ public class ThreadPoolStats extends Metrics {
*/
private int queueRemainingCapacity;

/**
* 正在执行任务的活跃线程大致总数
*/
private int activeCount;

/**
* 大致任务总数
*/
private long taskCount;

/**
* 已执行完成的大致任务总数
*/
Expand Down Expand Up @@ -121,68 +111,9 @@ public class ThreadPoolStats extends Metrics {
*/
private String rejectHandlerName;

/**
* 是否DtpExecutor线程池
*/
private boolean dynamic;

/**
* 执行超时任务数量
*/
private long runTimeoutCount;

/**
* 在队列等待超时任务数量
*/
private long queueTimeoutCount;

/**
* tps
*/
private double tps;

/**
* 最大任务耗时
*/
private long maxRt;

/**
* 最小任务耗时
*/
private long minRt;

/**
* 任务平均耗时(单位:ms)
*/
private double avg;

/**
* 满足50%的任务执行所需的最低耗时
*/
private double tp50;

/**
* 满足75%的任务执行所需的最低耗时
*/
private double tp75;

/**
* 满足90%的任务执行所需的最低耗时
*/
private double tp90;

/**
* 满足95%的任务执行所需的最低耗时
*/
private double tp95;

/**
* 满足99%的任务执行所需的最低耗时
*/
private double tp99;

/**
* 满足99.9%的任务执行所需的最低耗时
*/
private double tp999;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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.dromara.dynamictp.common.entity;

import lombok.Data;
Expand Down Expand Up @@ -25,74 +42,4 @@ public class VTExecutorStats extends Metrics {
*/
private String executorAliasName;

/**
* 正在执行任务的活跃线程大致总数
*/
private int activeCount;

/**
* 大致任务总数
*/
private long taskCount;

/**
* 执行超时任务数量
*/
private long runTimeoutCount;

/**
* 是否为DtpExecutor
*/
private boolean dynamic;

/**
* tps
*/
private double tps;

/**
* 最大任务耗时
*/
private long maxRt;

/**
* 最小任务耗时
*/
private long minRt;

/**
* 任务平均耗时(单位:ms)
*/
private double avg;

/**
* 满足50%的任务执行所需的最低耗时
*/
private double tp50;

/**
* 满足75%的任务执行所需的最低耗时
*/
private double tp75;

/**
* 满足90%的任务执行所需的最低耗时
*/
private double tp90;

/**
* 满足95%的任务执行所需的最低耗时
*/
private double tp95;

/**
* 满足99%的任务执行所需的最低耗时
*/
private double tp99;

/**
* 满足99.9%的任务执行所需的最低耗时
*/
private double tp999;

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public void collect(ThreadPoolStats poolStats, List<String> types) {
}
}

public void collectVTtask(VTExecutorStats vtTaskStats, List<String> types) {
if (vtTaskStats == null || CollectionUtils.isEmpty(types)) {
public void collectVTExecutor(VTExecutorStats vtExecutorStats, List<String> types) {
if (vtExecutorStats == null || CollectionUtils.isEmpty(types)) {
return;
}
for (String collectorType : types) {
MetricsCollector collector = COLLECTORS.get(collectorType.toLowerCase());
if (collector != null) {
collector.collect(vtTaskStats);
collector.collect(vtExecutorStats);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ private void collectMetrics(Set<String> executorNames) {
executorNames.forEach(x -> {
ExecutorWrapper wrapper = DtpRegistry.getExecutorWrapper(x);
if(wrapper.isVirtualThreadExecutor()) {
doCollectVTTask(ExecutorConverter.toVTExecutorMetrics(wrapper));
doCollectVTExecutor(ExecutorConverter.toVTExecutorMetrics(wrapper));
} else {
doCollect(ExecutorConverter.toMetrics(wrapper));
}
});
publishCollectEvent();
}

private void doCollectVTTask(VTExecutorStats vtTaskStats) {
private void doCollectVTExecutor(VTExecutorStats vtExecutorStats) {
try {
CollectorHandler.getInstance().collectVTtask(vtTaskStats, dtpProperties.getCollectorTypes());
CollectorHandler.getInstance().collectVTExecutor(vtExecutorStats, dtpProperties.getCollectorTypes());
} catch (Exception e) {
log.error("DynamicTp monitor, VTTask collect error.", e);
log.error("DynamicTp monitor, VTExecutor collect error.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void collect(ThreadPoolStats poolStats) {
}

@Override
public void collect(VTExecutorStats vtTaskStats) {
log.info("dynamic.vt metrics: {}", JsonUtil.toJson(vtTaskStats));
public void collect(VTExecutorStats vtExecutorStats) {
log.info("dynamic.vt metrics: {}", JsonUtil.toJson(vtExecutorStats));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void collect(ThreadPoolStats threadPoolStats) {
}

@Override
public void collect(VTExecutorStats vtTaskStats) {
String metrics = JsonUtil.toJson(vtTaskStats);
public void collect(VTExecutorStats vtExecutorStats) {
String metrics = JsonUtil.toJson(vtExecutorStats);
if (LogHelper.getMonitorLogger() == null) {
log.error("Cannot find monitor logger...");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public interface MetricsCollector {

/**
* Collect virtual thread key metrics.
* @param vtTaskStats
* @param vtExecutorStats
*/
void collect(VTExecutorStats vtTaskStats);
void collect(VTExecutorStats vtExecutorStats);

/**
* Collector type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.dromara.dynamictp.example.collector;

import org.dromara.dynamictp.common.entity.ThreadPoolStats;
import org.dromara.dynamictp.common.entity.VTExecutorStats;
import org.dromara.dynamictp.common.util.JsonUtil;
import org.dromara.dynamictp.core.monitor.collector.AbstractCollector;

Expand All @@ -40,6 +41,10 @@ public void collect(ThreadPoolStats poolStats) {
esClient.save(JsonUtil.toJson(poolStats));
}

@Override
public void collect(VTExecutorStats vtExecutorStats) {
esClient.save(JsonUtil.toJson(vtExecutorStats));
}
@Override
public String type() {
return "es";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.dromara.dynamictp.example.collector;

import org.dromara.dynamictp.common.entity.ThreadPoolStats;
import org.dromara.dynamictp.common.entity.VTExecutorStats;
import org.dromara.dynamictp.common.util.JsonUtil;
import org.dromara.dynamictp.core.monitor.collector.AbstractCollector;

Expand All @@ -40,6 +41,11 @@ public void collect(ThreadPoolStats poolStats) {
esClient.save(JsonUtil.toJson(poolStats));
}

@Override
public void collect(VTExecutorStats vtExecutorStats) {
esClient.save(JsonUtil.toJson(vtExecutorStats));
}

@Override
public String type() {
return "es";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.dromara.dynamictp.example.collector;

import org.dromara.dynamictp.common.entity.ThreadPoolStats;
import org.dromara.dynamictp.common.entity.VTExecutorStats;
import org.dromara.dynamictp.common.util.JsonUtil;
import org.dromara.dynamictp.core.monitor.collector.AbstractCollector;

Expand All @@ -40,6 +41,10 @@ public void collect(ThreadPoolStats poolStats) {
esClient.save(JsonUtil.toJson(poolStats));
}

@Override
public void collect(VTExecutorStats vtExecutorStats) {
esClient.save(JsonUtil.toJson(vtExecutorStats));
}
@Override
public String type() {
return "es";
Expand Down
Loading

0 comments on commit e29ebd4

Please sign in to comment.