Skip to content

Commit 7476e1d

Browse files
committed
fixed printing all hosts stats for each host iteration
1 parent 997da75 commit 7476e1d

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

hbase_region_requests.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
sys.exit(4)
5151

5252
__author__ = 'Hari Sekhon'
53-
__version__ = '0.5'
53+
__version__ = '0.5.1'
5454

5555

5656
class HBaseRegionsRequests(CLI):
@@ -160,10 +160,10 @@ def run_host(self, host, url):
160160
for bean in beans:
161161
log.debug('processing Regions bean')
162162
if bean['name'] == 'Hadoop:service=HBase,name=RegionServer,sub=Regions':
163-
self.process_bean(bean, uptime)
163+
self.process_bean(host, bean, uptime)
164164
self.print_stats(host)
165165

166-
def process_bean(self, bean, uptime):
166+
def process_bean(self, host, bean, uptime):
167167
region_regex = re.compile('^Namespace_{namespace}_table_({table})_region_(.+)_metric_(.+)RequestCount'\
168168
.format(namespace=self.namespace, table=self.table))
169169
stats = self.stats
@@ -175,23 +175,26 @@ def process_bean(self, bean, uptime):
175175
region = match.group(2)
176176
metric_type = match.group(3)
177177
log.info('matched table %s region %s %s request count = %s', table, region, metric_type, bean[key])
178-
if table not in stats:
179-
stats[table] = {}
180-
if region not in stats[table]:
181-
stats[table][region] = {}
178+
if host not in stats:
179+
stats[host] = {}
180+
if table not in stats[host]:
181+
stats[host][table] = {}
182+
if region not in stats[host][table]:
183+
stats[host][table][region] = {}
182184
if self.since_uptime:
183-
stats[table][region][metric_type] = bean[key] / uptime
185+
stats[host][table][region][metric_type] = bean[key] / uptime
184186
else:
185187
# this isn't perfect - will result on a region split as well as first run
186188
# but it's generally good enough
187189
if key not in last:
188190
self.first_iteration = 1
189191
else:
190-
stats[table][region][metric_type] = (bean[key] - last[key]) / self.interval
192+
stats[host][table][region][metric_type] = (bean[key] - last[key]) / self.interval
191193
last[key] = bean[key]
192-
if 'read' in stats[table][region] and 'write' in stats[table][region]:
194+
if 'read' in stats[host][table][region] and 'write' in stats[host][table][region]:
193195
#log.debug('calculating total now we have read and write info')
194-
stats[table][region]['total'] = stats[table][region]['read'] + stats[table][region]['write']
196+
stats[host][table][region]['total'] = stats[host][table][region]['read'] + \
197+
stats[host][table][region]['write']
195198

196199
def print_stats(self, host):
197200
stats = self.stats
@@ -206,8 +209,8 @@ def print_stats(self, host):
206209
.format(tstamp, self.interval, plural(self.interval)))
207210
self.first_iteration = 0
208211
return
209-
for table in sorted(stats):
210-
for region in sorted(stats[table]):
212+
for table in sorted(stats[host]):
213+
for region in sorted(stats[host][table]):
211214
table_region = region
212215
if len(stats) > 1:
213216
table_region = '{}_{}'.format(table, region)
@@ -216,7 +219,7 @@ def print_stats(self, host):
216219
for metric in ('read', 'write', 'total'):
217220
if (not show) or metric in show:
218221
print('{:20s}\t{:20s}\t{:40s}\t{:10s}\t{:8.0f}'\
219-
.format(tstamp, host, table_region, metric, stats[table][region][metric]))
222+
.format(tstamp, host, table_region, metric, stats[host][table][region][metric]))
220223
print()
221224

222225
# some extra effort to make it look the same as HBase presents it as

0 commit comments

Comments
 (0)