def do_pgc_tune(p_comp, email, print_json=False): tune_metadata = "tuning_service_descriptor" tuning_service = get_json_file(tune_metadata, print_json) tune_request = {} tune_request['tune_request'] = {} util.read_env_file(p_comp) port = util.get_comp_port(p_comp) pg = PgInstance("localhost", "postgres", "postgres", int(port)) pg.connect() tune_request['tune_request']['postgres_config'] = pg.get_raw_pg_settings() pg.close() tune_request['tune_request']['email'] = email tune_request['tune_request']['user_agent'] = 'pgc {}'.format( util.get_pgc_version()) tune_request['tune_request']['postgres_config'][ 'postgres_version'] = util.get_column('version', p_comp) tune_request['tune_request']['system_config'] = api.info( True, 'na', 'na', False) # Web request tune_url = tuning_service['bigtuna']['url'] tune_url = tune_url + tuning_service['bigtuna']['path'] req = urllib2.Request(tune_url) req.add_header('Content-Type', 'application/json') tune_result = urllib2.urlopen(req, json.dumps(tune_request)) result = json.load(tune_result) if print_json: print( json.dumps(result, sort_keys=True, indent=2, separators=(',', ': '))) else: for key in result['tune_result']: print("{0} = {1}".format(key, result['tune_result'][key]))
parser = argparse.ArgumentParser() parser.add_argument("--port", type=int, default=0) parser.add_argument("--autostart", choices=["on", "off"]) parser.add_argument("--datadir", type=str, default="") parser.add_argument("--logdir", type=str, default="") parser.add_argument("--svcname", type=str, default="") parser.usage = parser.format_usage().replace("--autostart {on,off}", "--autostart={on,off}") args = parser.parse_args() isJson = os.getenv("isJson", None) autostart = util.get_column('autostart', pgver) app_datadir = util.get_comp_datadir(pgver) port = util.get_comp_port(pgver) is_running = False if app_datadir != "" and util.is_socket_busy(int(port), pgver): is_running = True msg = "You cannot change the configuration when the server is running." if isJson: jsonMsg = {} jsonMsg['status'] = "error" jsonMsg['component'] = pgver jsonMsg['msg'] = msg print(json.dumps([jsonMsg])) else: print(msg)
#################################################################### ###### Copyright (c) 2015-2019 BigSQL ########## #################################################################### import os, sys, util APG_HOME = os.getenv('APG_HOME', '') sys.path.append(os.path.join(APG_HOME, 'hub', 'scripts', 'lib')) from PgInstance import PgInstance import json pgver = "pg9X" port = int(util.get_comp_port(pgver)) util.read_env_file(pgver) try: pg = PgInstance("localhost", "postgres", "postgres", port) pg.connect() activities = pg.get_current_activity() pg.close() print(json.dumps(activities, indent=2)) except Exception as e: pass sys.exit(0)