-
Notifications
You must be signed in to change notification settings - Fork 8
/
cbclusterstats
executable file
·61 lines (46 loc) · 1.87 KB
/
cbclusterstats
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from optparse import OptionParser
import sys
import logging
import collector
import processor
log = logging.getLogger('cbclusterstats')
log.setLevel(logging.INFO)
log.addHandler(logging.StreamHandler())
def parse_opt():
usage = "usage: %prog CLUSTER USERNAME PASSWORD OPTIONS"
parser = OptionParser(usage)
parser.add_option('-c', '--cluster', dest='cluster', default='',
help='default port is 8091',
metavar='HOST[:PORT]')
parser.add_option('-u', '--user', dest='user', default='',
help='admin username of the cluster',
metavar='USERNAME')
parser.add_option('-p', '--password', dest='password', default='',
help='admin password of the cluster',
metavar='PASSWORD')
parser.add_option('-o', '--output', dest='txtfile', default='clusterstats.txt',
help='default output filename is "clusterstats.txt"',
metavar='FILENAME')
parser.add_option('-d', '--debug', dest='debug', default=False,
action="store_true")
options, args = parser.parse_args()
if options.debug:
log.setLevel(logging.DEBUG)
if not options.cluster or not options.user or not options.password:
parser.print_help()
sys.exit(2)
return options.cluster, options.user, options.password, options.txtfile, \
args
def main():
(cluster, user, password, txtfile, opts) = parse_opt()
#make snapshot for the current cluster status
retriever = collector.StatsCollector(log)
retriever.collect_data(cluster, user, password, opts)
#analyze the snapshot and historic data
performer = processor.StatsAnalyzer(log)
performer.run_analysis()
performer.run_report(txtfile)
if __name__ == '__main__':
main()