统计Azure存储的HBase各表数据量
场景:HBase存储在Azure上,现在通过访问Azure Storage的接口,获取HBase中各个表的数据量。
注意:
1、Azure存储,默认的副本数为2,即共存3份,但只收1份的费用,取到的size也是1份的大小。如果是自建HDFS,则不同。
2、此处访问的是Azure Storage的接口,还可以访问HBase的接口来获取数据量(另行验证)。
c#代码:
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
public class HBaseResourceFetcher
{ private CloudBlobContainer blobContainer; public HBaseResourceFetcher()
{
StorageCredentials storageCred = new StorageCredentials(
AppConfigGetter.Get(ConfigConstants.KEY_STORAGEACCOUNTNAME),
AppConfigGetter.Get(ConfigConstants.KEY_STORAGEACCOUNTKEY));
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCred,
AppConfigGetter.Get(ConfigConstants.KEY_ENDPOINTSUFFIX), true);
var blobClient = storageAccount.CreateCloudBlobClient();
this.blobContainer = blobClient.GetContainerReference(
AppConfigGetter.Get(ConfigConstants.KEY_STORAGECONTAINERNAME));
} public Dictionary<string, ResourceEntity> GetHBaseTableSizeInfo()
{
Dictionary<string, ResourceEntity> result = new Dictionary<string, ResourceEntity>();
CloudBlobDirectory directory = this.blobContainer.GetDirectoryReference("hbase/data/default");
if (directory == null)
return result; var items = directory.ListBlobs();
foreach (var item in items)
{
if (item is CloudBlobDirectory)
{
var dir = item as CloudBlobDirectory;
string key = dir.Prefix.Replace("hbase/data/default/", "").Replace("/", "");
if (result.ContainsKey(key)) continue;
result.Add(key, new ResourceEntity() {
Type = ResourceType.HBase,
TableName=key,
CopiesNum=,//Azure存储,HDFS默认的副本数为2,即共存3份,但只收1份的费用,故此处记为0
Size_B = GetFileSizeByBlobPath(dir.Prefix)//Azure存储,HDFS默认的副本数为2,即共存3份,但只收1份的费用,此处取到的size也是1份的大小
});
}
}
return result;
} public long GetFileSizeByBlobPath(string directoryPath)
{
CloudBlobDirectory directory = this.blobContainer.GetDirectoryReference(directoryPath);
if (directory == null)
return ;
var items = directory.ListBlobs(true, BlobListingDetails.All).Where(item => (item as CloudBlockBlob).Properties.Length > );
long size = ;
foreach (var item in items)
{
var tmp = (item as CloudBlockBlob);
if (tmp.Name.Contains(".regioninfo") || tmp.Name.Contains(".tableinfo") || tmp.Name.Contains("recovered.edits")) continue;
string[] guid = tmp.Name.Replace(directoryPath, "").Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
size += tmp.Properties.Length;
}
return size;
}
}
统计Azure存储的HBase各表数据量的更多相关文章
- 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作
CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...
- sql server编写通用脚本自动统计各表数据量心得
工作过程中,如果一个数据库的表比较多,手工编写统计脚本就会比较繁琐,于是摸索出自动生成各表统计数据量脚本的通用方法,直接上代码: /* 脚本来源:https://www.cnblogs.com/zha ...
- HBase协处理器统计表数据量
1.Java代码实现 import org.apache.hadoop.hbase.client.coprocessor.AggregationClient; import org.apache.ha ...
- SOME:收缩数据库日志文件,查看表数据量和空间占用,查看表结构索引修改时间
---收缩数据库日志文件 USE [master]ALTER DATABASE yourdatabasename SET RECOVERY SIMPLE WITH NO_WAITALTER DATAB ...
- 表数据量影响MySQL索引选择
现象 新建了一张员工表,插入了少量数据,索引中所有的字段均在where条件出现时,正确走到了idx_nap索引,但是where出现部分自左开始的索引时,却进行全表扫描,与MySQL官方所说的最左匹配原 ...
- [源码分享] HIVE表数据量统计&邮件
概要: 计算HIVE BI库下每天数据表总大小及增量 输出: 总大小:xxxG 日同比新增数据量:xxxG 周同比新增数据量:xxxG 月同比新增数据量:xxxG 总表数:xxx 日新增表数:xxx ...
- MySQL单表数据量过千万,采坑优化记录,完美解决方案
问题概述 使用阿里云rds for MySQL数据库(就是MySQL5.6版本),有个用户上网记录表6个月的数据量近2000万,保留最近一年的数据量达到4000万,查询速度极慢,日常卡死.严重影响业务 ...
- HBase 清空表数据
public int clearTableByTableName(String tableName) throws Exception { logger.debug("======InitH ...
- sql sever 查询用户所有的表和各个表数据量
和oracle有区别, 需要关联表 SELECT A.NAME ,B.ROWS FROM sysobjects A JOIN sysindexes B ON A.id = B.id WHERE A ...
随机推荐
- 动态We API层(动态生成js)
ABP动态webapi前端怎么调用? 研究abp项目时,页面js文件中一直不明白abp.services... 是从哪里来的 在调试SimpleTaskSystem的AngularJs demo时,一 ...
- 不使用JavaScript让IE浏览器支持HTML5元素——张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=2515 如果我们不做什 ...
- Spring Boot—04文件上传
package com.smartmap.sample.ch1.controller.view; import java.io.File; import java.io.IOException; im ...
- U-Push 3.1.5SDK 集成的一些坑
1.老是mPushAgent.register中onFailure获取不到deviceToken so文件配置有误,需重新配置: PushSDK .x默认只提供armeabi和x86两种so文件夹,若 ...
- Hive设置变量
hive --define --hivevar --hiveconf set 1.hivevar命名空间 用户自定义变量 hive -d name=zhangsan hive --define nam ...
- leetCode题解之Number of Lines To Write String
1.题目描述 2.分析 使用一个map将字母和数字对应起来,方便后续使用. 3.代码 vector<int> numberOfLines(vector<int>& wi ...
- Angular常用语句
循环执行 )* ))))); //重点 : 返回deferred.promise才能链式执行then方法 return def.promise;} log : function (msg) { con ...
- Oracle EBS AR 更新客户
DECLARE l_return_status ); l_msg_count NUMBER; l_msg_data ); l_rec_type hz ...
- 避免重复插入数据sql server
insert into TN_JOBS(JAVA_ID,SERVER_IP,SERVER_PORT,JOB_CODE,JOB_NAME,JOB_START_TIME,JOB_MSG,JOB_STATU ...
- consul日常操作命令
#开发模式运行agent consul agent -dev #查看consul 集群成员 consul members [-detailed] members命令的输出基于gossip协议,并最终一 ...