首页 > 学院 > 操作系统 > 正文

hbase + falcon监控目录大小

2024-06-28 16:03:47
字体:
来源:转载
供稿:网友

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

#!/usr/bin/env python#coding: utf8import osimport sysimport reimport commandsimport timeimport jsonimport urllib2a = commands.getoutput("hadoop dfs -du /hbase")PRint aa2 = 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 value1print value2print value3print 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 ip.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: methodtry: connection = opener.open(request)except urllib2.HTTPError,e: connection = eif connection.code == 200: print connection.read()else: print '{"err":1,"msg":"%s"}' % connection
上一篇:wmi入门

下一篇:SSL

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表