def run(args): log = logger().getlogger pg = postgresql(args) pgb = pgbouncer(args) if args.sendtrap: info = {} log.info("sendtrap start") pgInfo = pg.info() info.update(pgInfo) pgbInfo = pgb.info() info.update(pgbInfo) log.info("sendtrap result: {}".format(info)) zbx = sendproto(pg.config['zbx_server'], pg.config['zbx_port']) resp = zbx.send(info) log.info("send status: {}".format(resp)) elif args.discover: info = {} log.info("discover start") pgInfo = pg.discover() pgbInfo = pgb.discover() info['data'] = pgInfo + pgbInfo log.info("discover result: {}".format( json.dumps(info, sort_keys=True, indent=4, separators=(',', ':')))) print(json.dumps(info, indent=4))
def pgbouncer_resume(self, dbname): """ resume given database """ from options import TERSE if not TERSE: print "resume %s;" % dbname p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.pgbouncer_port) p.resume(dbname)
def pgbouncer_databases(self): """ return pgbouncer database list: name, database, host, port """ p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.pgbouncer_port) for d in p.databases(): yield d['name'], d['database'], d['host'], d['port'] return
def pgbouncer_pause(self, dbname): """ pause given database """ from options import VERBOSE if VERBOSE: print "pause %s;" % dbname p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.pgbouncer_port) p.pause(dbname)
def switch(self): """ edit pgbouncer configuration file to have canonical dbname point to given date (backup_date) """ p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.postgres_port) newconffile = p.switch_to_database(self.dbname, self.dated_dbname, self.postgres_port) self.pgbouncer_update_conf(newconffile)
def pgbouncer_del_database(self, dbname): """ edit pgbouncer configuration file to add a database """ from options import VERBOSE p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.postgres_port) newconffile = p.del_database(dbname) self.pgbouncer_update_conf(newconffile) if VERBOSE: print "deleted a pgbouncer database %s" % dbname
def pgbouncer_add_database(self, dbname=None): """ edit pgbouncer configuration file to add a database """ from options import TERSE p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.postgres_port) if dbname is None: dbname = self.dated_dbname newconffile = p.add_database(dbname, self.postgres_port) self.pgbouncer_update_conf(newconffile) if not TERSE: print "added a pgbouncer database %s" % dbname
def pgbouncer_add_database(self, dbname = None): """ edit pgbouncer configuration file to add a database """ from options import TERSE p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host, self.postgres_port) if dbname is None: dbname = self.dated_dbname newconffile = p.add_database(dbname, self.postgres_port) self.pgbouncer_update_conf(newconffile) if not TERSE: print "added a pgbouncer database %s" % dbname