Skip to content

Instantly share code, notes, and snippets.

@vagetablechicken
Created April 4, 2023 07:17
Show Gist options
  • Save vagetablechicken/06522732096dd253e542f0f0139c5d9a to your computer and use it in GitHub Desktop.
Save vagetablechicken/06522732096dd253e542f0f0139c5d9a to your computer and use it in GitHub Desktop.
import requests
import json
# detect table status about data
db = 'disk_test'
ns_leader = '172.24.4.27:7123'
url = f'http://{ns_leader}/NameServer/ShowTable'
res = requests.get(url, json={"show_all": True})
tables = json.loads(res.text)['table_info']
tablet2partition = {}
tablet2count = {}
tablet2mem = {}
def collect(parts, field):
dist = {}
for part in parts:
for replica in part['partition_meta']:
if replica['endpoint'] not in dist:
dist[replica['endpoint']] = 0
dist[replica['endpoint']] += replica[field] if field else 1
return dist
def add_merge(dist, dist2):
for key, value in dist2.items():
dist[key] = dist.get(key, 0) + value
return dist
for table in tables:
if db:
if table['db'] != db:
continue
print(table['db'], table['name'])
parts = table['table_partition']
part_dist = collect(parts,'')
print('partition dist(include replica)', part_dist)
print('partition size:', len(parts))
count_dist = collect(parts, 'record_cnt')
mem_dist = collect(parts, 'record_byte_size')
print('record count dist(include replica)', count_dist)
print('mem dist(include replica)', mem_dist)
add_merge(tablet2partition, part_dist)
add_merge(tablet2count, count_dist)
add_merge(tablet2mem, mem_dist)
print('total')
print('tablet2partition', tablet2partition)
print('tablet2count', tablet2count)
print('tablet2mem', tablet2mem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment