feat(monitor): 增加关于hudi表文件数的监控指标

This commit is contained in:
v-zhangjc9
2024-10-12 17:17:15 +08:00
parent 8fda8f7669
commit 7d33227d70
6 changed files with 316 additions and 162 deletions

View File

@@ -205,6 +205,41 @@ public class HudiCommand {
fileSystem.close();
}
@ShellMethod("Max meta files")
public void maxMetaFiles() throws IOException {
MutableList<P> list = Lists.mutable.<P>empty().asSynchronized();
FileSystem fileSystem = FileSystem.get(new Configuration());
infoService
.tableMetaList()
.collect(TableMeta::getHudi)
.collect(TableMeta.HudiMeta::getTargetHdfsPath)
.asParallel(ExecutorProvider.EXECUTORS_20, 1)
.forEach(hdfs -> {
Path root = new Path(hdfs, ".hoodie");
try {
FileStatus[] statuses = fileSystem.listStatus(root);
long num = 0;
for (FileStatus status : statuses) {
if (status.isFile()) {
num++;
}
if (StrUtil.containsIgnoreCase(status.getPath().toString(), "INVALID")) {
logger.info("{}", status.getPath().toString());
}
}
list.add(new P(num, hdfs));
logger.info("Count: {} Hdfs: {}", num, hdfs);
} catch (IOException e) {
logger.warn("List file error", e);
}
});
MutableList<P> listP = list.select(p -> p.count > 1000);
for (P maxP : listP) {
logger.info("Max: {} Hdfs: {}", maxP.count, maxP.hdfs);
}
fileSystem.close();
}
@ShellMethod("Get timeline instants")
public void timelineInstant(@ShellOption(help = "root hdfs path") String hdfs) {
hudiService.timelineHdfsAllActive(hdfs).forEach(instant -> logger.info(instant.toString()));
@@ -229,4 +264,14 @@ public class HudiCommand {
public interface Runnable {
void run(LongAdder counter);
}
private static final class P {
String hdfs;
long count;
public P(long count, String hdfs) {
this.count = count;
this.hdfs = hdfs;
}
}
}