如何通过api获取hdfs整体信息?

李昊甦 2013-05-25 05:43:11
Cluster Summary
599 files and directories, 356 blocks = 955 total. Heap Size is 35.62 MB / 888.94 MB (4%)

Configured Capacity : 575.08 GB
DFS Used : 9.49 GB
Non DFS Used : 68.39 GB
DFS Remaining : 497.2 GB
DFS Used% : 1.65 %
DFS Remaining% : 86.46 %
Live Nodes : 3
Dead Nodes : 0
Decommissioning Nodes : 0
Number of Under-Replicated Blocks : 6

就是上面这些信息,该怎么得到?
...全文
300 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
撸大湿 2013-05-26
  • 打赏
  • 举报
回复

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;

public class hdfstest01 {

public static void main(String[] agrs) throws Exception {
Configuration myConf = new Configuration();
myConf.set("fs.default.name", "hdfs://master.nj.hadoop:9000");
FileSystem myFS = FileSystem.get(myConf);
DistributedFileSystem dfs = new DistributedFileSystem();
DistributedFileSystem hdfs = (DistributedFileSystem) FileSystem.get(myConf);
DatanodeInfo[] dataNodeStats = hdfs.getDataNodeStats();
System.out.println("Configured Capacity (单位字节):" + hdfs.getRawCapacity());
System.out.println("DFS Used (单位字节):" + hdfs.getRawUsed());
System.out.println("DFS Remaining (单位字节) :" + hdfs.getDiskStatus().getRemaining());
System.out.println("DFS Used% :更具上面的信息自己算百分比");
System.out.println("DFS Remaining% : 更具上面的信息自己算百分比");
System.out.println("Node信息参考下方代码27行");
System.out.println("Number of Under-Replicated Blocks :" + hdfs.getUnderReplicatedBlocksCount());



System.out.println("-----------------------------------");
//Nodes 信息
for (DatanodeInfo dataNode : dataNodeStats) {
System.out.println("-----------------------------------");
//上方的所有数据,都可以通过下面DatanodeInfo的方法累加
System.out.println(dataNode.getHostName() + "\t" + dataNode.getName() + "\t" + dataNode.getAdminState() + "\t"
+ dataNode.getDatanodeReport());
}
}
}

20,807

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧