hbase + falcon监控目录大小

blackfish 发布于2年前
0 条问题

为了更好的学习hbase的磁盘占用情况,写了个hbase脚本

#!/usr/bin/env python
#coding: utf8
import os
import sys
import re
import commands
import time
import json
import urllib2
a = commands.getoutput("hadoop dfs -du /hbase")
print a
a2 = a.replace('\n',' ').split(" ")
while '' in a2: a2.remove('')
for x in range(0,len(a2)): 
    if a2[x] == "/hbase/WALs": 
        value1 = a2[x-2]
for x in range(0,len(a2)): 
    if a2[x] == "/hbase/archive": 
        value2 = a2[x-2]
for x in range(0,len(a2)): 
    if a2[x] == "/hbase/data": 
        value3 = a2[x-2]
for x in range(0,len(a2)): 
    if a2[x] == "/hbase/oldWALs": 
        value4 = a2[x-2]
print value1
print value2
print value3
print value4
# 准备上报数据
p = []
# 定义时间戳
timestamp = int(time.time())
def predata(endpoint,metric,key,value,timestamp,step,vtype):
    tags = ''
    i = {
        'Metric' :'%s.%s'%(metric,key),
        'Endpoint': endpoint,
        'Timestamp': timestamp,
        'Step': step,
        'value': value,
        'CounterType': vtype,
        'TAGS': tags
        }
    return i
p.append(predata("userdefine","hbase","size.wals",value1,timestamp,60,"GAUGE"))
p.append(predata("userdefine","hbase","size.archive",value2,timestamp,60,"GAUGE"))
p.append(predata("userdefine","hbase","size.data",value3,timestamp,60,"GAUGE"))
p.append(predata("userdefine","hbase","size.oldwals",value4,timestamp,60,"GAUGE"))
print json.dumps(p, sort_keys=True,indent = 4)
#sys.exit(0)
# 上报
method = "POST"
handler = urllib2.HTTPHandler()
opener = urllib2.build_opener(handler)
url = "http://127.0.0.1:1988/v1/push"
request = urllib2.Request(url, data=json.dumps(p))
request.add_header('Content-Type','application/json')
request.get_method = lambda: method
try:
    connection = opener.open(request)
except urllib2.HTTPError,e:
    connection = e
if connection.code == 200:
    print connection.read()
else:
    print '{"err":1,"msg":"%s"}' % connection
需要 登录 后回复方可回复, 如果你还没有账号你可以 注册 一个帐号。