forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodetool-toppartitions
executable file
·75 lines (66 loc) · 2.43 KB
/
nodetool-toppartitions
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
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
#
# Copyright (C) 2018-present ScyllaDB
#
#
# This file is part of Scylla.
#
# Scylla is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Scylla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
#
import argparse
import os
import json
from functools import reduce
import requests
def scylla_api_get(item, params={}):
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
response = requests.get('http://127.0.0.1:10000/{}'.format(item), headers=headers, params=params)
return response
def toppartitions(kscf, duration, list_size, capacity):
r = scylla_api_get('column_family/toppartitions/{}'.format(kscf), {
'duration': str(duration),
'list_size': str(list_size),
'capacity': str(capacity)})
return json.loads(r.text)
def print_pks(title, map):
print(title)
w = reduce(lambda n, r: max(len(r['partition']), n), map, len('Partition')+3)
print((" %-{}s%s".format(w)) % ('Partition', 'Count'))
for r in map:
print((" %-{}s%s".format(w)) % (r['partition'], r['count']))
print()
ap = argparse.ArgumentParser(description='Samples database reads and writes and reports the most active partitions in a specified table')
ap.add_argument('-k', type=int,
default=10, dest='list_size',
help='The number of the top partitions to list (default: 10)')
ap.add_argument('-s', type=int,
default=256, dest='capacity',
help='The capacity of stream summary (default: 256)')
ap.add_argument('keyspace',
help='Name of keyspace')
ap.add_argument('table',
help='Name of column family')
ap.add_argument('duration', type=int,
help='Query duration in milliseconds')
args = ap.parse_args()
res = toppartitions("{}:{}".format(args.keyspace, args.table), args.duration, args.list_size, args.capacity)
if res == {}:
print("(nothing reported)")
exit(1)
print_pks("READ", res["read"])
print_pks("WRITE", res["write"])
exit(0)