-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·64 lines (54 loc) · 1.71 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# Manages other scripts
import time
import os
import hbase
import ConfigParser
import signal
import logging
import sys
def signal_handler(signal, frame):
print 'SIGINT, stopping'
global should_cont
should_cont=False
logging.basicConfig(level=logging.INFO)
config = ConfigParser.RawConfigParser()
config.read('client.cfg')
use_statsd=config.getboolean('general','usestatsd')
c=None
# create statsd connection
if use_statsd:
logging.info("using StatsD: %s:%s" % (config.get('statsd','host'),config.getint('statsd','port')))
import statsd
c = statsd.StatsClient(
config.get('statsd','host'),
config.getint('statsd','port'),
prefix='hbase.%s' % config.get('general','cluster'),
)
# connect to hbase
logging.info("using Hbase: %s with %s region and %s master" % (config.get('hbase','host'), config.getint('hbase','region_port'), config.getint('hbase','master_port')))
hbase.config(
os.popen('hostname -f').read().rstrip(),
config.get('hbase','host'),
config.getint('hbase','region_port'),
config.getint('hbase','master_port'),
)
mode=config.get('general','mode')
logging.info("mode: %s" %(mode))
use_region=(mode=='both') or (mode=='region')
use_master=(mode=='both') or (mode=='master')
freq=config.getint('general','transmitfrequency')
should_cont=True
signal.signal(signal.SIGINT, signal_handler)
while should_cont:
try:
glob={}
if use_region: glob=dict(glob.items() + hbase.region_data().items())
if use_master: glob=dict(glob.items() + hbase.master_data().items())
if use_statsd:
for k in glob.keys():
c.gauge(k,glob[k])
logging.info("Reporting %s" %(glob))
except Exception as e:
logging.exception("")
if should_cont: time.sleep(freq)