场景: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各表数据量的更多相关文章

  1. 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作

    CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...

  2. sql server编写通用脚本自动统计各表数据量心得

    工作过程中,如果一个数据库的表比较多,手工编写统计脚本就会比较繁琐,于是摸索出自动生成各表统计数据量脚本的通用方法,直接上代码: /* 脚本来源:https://www.cnblogs.com/zha ...

  3. HBase协处理器统计表数据量

    1.Java代码实现 import org.apache.hadoop.hbase.client.coprocessor.AggregationClient; import org.apache.ha ...

  4. SOME:收缩数据库日志文件,查看表数据量和空间占用,查看表结构索引修改时间

    ---收缩数据库日志文件 USE [master]ALTER DATABASE yourdatabasename SET RECOVERY SIMPLE WITH NO_WAITALTER DATAB ...

  5. 表数据量影响MySQL索引选择

    现象 新建了一张员工表,插入了少量数据,索引中所有的字段均在where条件出现时,正确走到了idx_nap索引,但是where出现部分自左开始的索引时,却进行全表扫描,与MySQL官方所说的最左匹配原 ...

  6. [源码分享] HIVE表数据量统计&邮件

    概要: 计算HIVE BI库下每天数据表总大小及增量 输出: 总大小:xxxG 日同比新增数据量:xxxG 周同比新增数据量:xxxG 月同比新增数据量:xxxG 总表数:xxx 日新增表数:xxx ...

  7. MySQL单表数据量过千万,采坑优化记录,完美解决方案

    问题概述 使用阿里云rds for MySQL数据库(就是MySQL5.6版本),有个用户上网记录表6个月的数据量近2000万,保留最近一年的数据量达到4000万,查询速度极慢,日常卡死.严重影响业务 ...

  8. HBase 清空表数据

    public int clearTableByTableName(String tableName) throws Exception { logger.debug("======InitH ...

  9. sql sever 查询用户所有的表和各个表数据量

    和oracle有区别, 需要关联表 SELECT A.NAME ,B.ROWS  FROM sysobjects  A JOIN sysindexes B ON A.id = B.id WHERE A ...

随机推荐

  1. POJ2251(KB1-B 三维BFS)

    Dungeon Master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 40872 Accepted: 19936 Desc ...

  2. bzoj3167 [Heoi2013]Sao

    传送门 这题神坑啊……明明是你菜 首先大家都知道原题等价于给每个点分配一个$1$~$n$且两两不同的权值,同时还需要满足一些大于/小于关系的方案数. 先看一眼数据范围,既然写明了$n\le 1000$ ...

  3. 【代码笔记】iOS-iphone开发之获取系统字体

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NS ...

  4. DOM增删操作(创建删除表格)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  5. python之函数的参数

    1.位置参数: 例如计算一个整数的平方: def power(x) return x * x 显然参数x就是一个位置参数,如果要是计算5*5*5..............*5 ,这个函数就太麻烦了, ...

  6. css文字飞入效果

    一.页面的主体布局 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...

  7. linux 用户配置文件及其相关目录

    用户配置文件及其相关目录: /etc/passwd 用户信息文件/etc/shadow 影子文件/etc/group 组信息文件/etc/gshadow 组密码文件邮箱目录模板目录 /etc/pass ...

  8. 你写的什么垃圾代码让Vsync命令不能及时处理呢?(2)

    接上篇 1.TraceView Traceview看起来复杂,其实很简单: 上部分图中,X代表时间消耗,Y轴代表各个线程中的方法,且使用了不同颜色表示.面积越款,时间越长. 下部分为分析面板,分析面板 ...

  9. leetcode 之 Degree of an Array

    1.题目描述 Given a non-empty array of non-negative integers nums, the degree of this array is defined as ...

  10. 在 Azure 中的 Linux VM 上创建 MongoDB、Express、AngularJS 和 Node.js (MEAN) 堆栈

    本教程介绍如何在 Azure 中的 Linux VM 上实现 MongoDB.Express.AngularJS 和 Node.js (MEAN) 堆栈. 通过创建的 MEAN 堆栈,可以在数据库中添 ...