1# Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2# This source code is licensed under both the GPLv2 (found in the 3# COPYING file in the root directory) and Apache 2.0 License 4# (found in the LICENSE.Apache file in the root directory). 5 6from advisor.rule_parser import RulesSpec 7from advisor.db_log_parser import DatabaseLogs, DataSource 8from advisor.db_options_parser import DatabaseOptions 9from advisor.db_stats_fetcher import LogStatsParser, OdsStatsFetcher 10import argparse 11 12 13def main(args): 14 # initialise the RulesSpec parser 15 rule_spec_parser = RulesSpec(args.rules_spec) 16 rule_spec_parser.load_rules_from_spec() 17 rule_spec_parser.perform_section_checks() 18 # initialize the DatabaseOptions object 19 db_options = DatabaseOptions(args.rocksdb_options) 20 # Create DatabaseLogs object 21 db_logs = DatabaseLogs( 22 args.log_files_path_prefix, db_options.get_column_families() 23 ) 24 # Create the Log STATS object 25 db_log_stats = LogStatsParser( 26 args.log_files_path_prefix, args.stats_dump_period_sec 27 ) 28 data_sources = { 29 DataSource.Type.DB_OPTIONS: [db_options], 30 DataSource.Type.LOG: [db_logs], 31 DataSource.Type.TIME_SERIES: [db_log_stats] 32 } 33 if args.ods_client: 34 data_sources[DataSource.Type.TIME_SERIES].append(OdsStatsFetcher( 35 args.ods_client, 36 args.ods_entity, 37 args.ods_tstart, 38 args.ods_tend, 39 args.ods_key_prefix 40 )) 41 triggered_rules = rule_spec_parser.get_triggered_rules( 42 data_sources, db_options.get_column_families() 43 ) 44 rule_spec_parser.print_rules(triggered_rules) 45 46 47if __name__ == '__main__': 48 parser = argparse.ArgumentParser(description='Use this script to get\ 49 suggestions for improving Rocksdb performance.') 50 parser.add_argument( 51 '--rules_spec', required=True, type=str, 52 help='path of the file containing the expert-specified Rules' 53 ) 54 parser.add_argument( 55 '--rocksdb_options', required=True, type=str, 56 help='path of the starting Rocksdb OPTIONS file' 57 ) 58 parser.add_argument( 59 '--log_files_path_prefix', required=True, type=str, 60 help='path prefix of the Rocksdb LOG files' 61 ) 62 parser.add_argument( 63 '--stats_dump_period_sec', required=True, type=int, 64 help='the frequency (in seconds) at which STATISTICS are printed to ' + 65 'the Rocksdb LOG file' 66 ) 67 # ODS arguments 68 parser.add_argument( 69 '--ods_client', type=str, help='the ODS client binary' 70 ) 71 parser.add_argument( 72 '--ods_entity', type=str, 73 help='the servers for which the ODS stats need to be fetched' 74 ) 75 parser.add_argument( 76 '--ods_key_prefix', type=str, 77 help='the prefix that needs to be attached to the keys of time ' + 78 'series to be fetched from ODS' 79 ) 80 parser.add_argument( 81 '--ods_tstart', type=int, 82 help='start time of timeseries to be fetched from ODS' 83 ) 84 parser.add_argument( 85 '--ods_tend', type=int, 86 help='end time of timeseries to be fetched from ODS' 87 ) 88 args = parser.parse_args() 89 main(args) 90