Пример #1
0
from functionname import FunctionName
from indexname import IndexName
from tabletoastname import TableToastName
from indextoastname import IndexToastName



lt=LogTime()

work_cursor=database.db_conn.cursor()
work_cursor.execute("SELECT id FROM host_cluster WHERE alive AND observable")



for hc_id in work_cursor.fetchall():
    hc=HostCluster(hc_id[0])
    hc.discover_cluster_params()
    hc.stat(lt.id)
    for dbs in hc.get_dependants(obs=True):
	db_conn_string=hc.return_conn_string(dbs['db_name'])
	dn=DatabaseName(dbs['id'],db_conn_string)
	dn.stat(lt.id)
	db_cursor=dn.get_prod_cursor()
	if db_cursor:
	    for sn_id in dn.get_dependants(obs=True):
		sn=SchemaName(sn_id)
		sn.discover_tables(db_cursor)
		sn.discover_functions(db_cursor)
		for tbl_id in sn.get_tables():
		    tn=TableName(tbl_id)
		    tn.stat(lt.id,db_cursor)
Пример #2
0
conn=psycopg2.connect(settings.custom_dsn('pg_mon'))

#cur=database.db_conn.cursor()
cur=conn.cursor()
get_stat=cur.mogrify("SELECT id FROM host_cluster WHERE {0}=%s AND param_port=%s".format(host_search),(host,port))
cur.execute(get_stat)
res_id=cur.fetchone()
print res_id
#sys.exit()
cur.close()
#conn.close()
if not res_id:
    print "No PostgreSQL cluster found for host: {0} port {1}".format(host,port)
#    cur.close()
    conn.close()
    sys.exit(2)


hc=HostCluster(conn,res_id[0])
for dbs in hc.get_dependants():
    print dbs
#    if dbs['db_name'] == db_name:
#	print hc.return_conn_string(dbname=db_name)
#	conn.close()
#	sys.exit(0)

print "No PostgreSQL cluster found for host: {0} port {1} database {2}".format(host,port,db_name)
#cur.close()
sys.exit(2)

Пример #3
0
    elif param in ('-p','--port'):
	if not isinstance(value,int) and value <= 0:
	    print "Port parameter is incorrect: {0}".format(value)
	    sys.exit(2)
	else:
	    port=value
    elif param in ("-s","--dsn"):
	string_output=False

cur=database.db_conn.cursor()
get_stat=cur.mogrify("SELECT id FROM host_cluster WHERE {0}=%s AND param_port=%s".format(host_search),(host,port))
cur.execute(get_stat)
res_id=cur.fetchone()

if not res_id:
    print "No PostgreSQL cluster found for host: {0} port {1}".format(host,port)
    cur.close()
    sys.exit(2)

hc=HostCluster(res_id[0])
for dbs in hc.get_dependants():
    if dbs['db_name'] == db_name:
	print hc.return_conn_string(dbname=db_name)
	cur.close()
	sys.exit(0)

print "No PostgreSQL cluster found for host: {0} port {1} database {2}".format(host,port,db_name)
cur.close()
sys.exit(2)

Пример #4
0
    def run(self):
	signal.signal(signal.SIGTERM,self._sig_term)
	signal.signal(signal.SIGHUP,self._sig_reload)

	cur_minute=self._get_current_time('%M')
	delay=60*(settings.runtime_stat_interval - (cur_minute % settings.runtime_stat_interval)) - self._get_current_time()
	logger.info("Starting PgMon daemon")
	logger.debug("Delay to iterations: {0}".format(delay))
	time.sleep(delay)

	while True:

	    regular_stat=False
	    current_time_minute=self._get_current_time('%M')

	    lt_id=False
	    ltm_id=False


	    if not self._set_pg_mon_conn():
		self._delay()
		continue
	    if settings.runtime_stat_enable:
		ltm=logtime_mt.LogTimeMT(self.pg_mon_conn)
		ltm_id=ltm.get_id()
		if not ltm_id:
		    self._rollback()
		    continue
		self.pg_mon_conn.commit()
		logger.debug("Obtained ltm_id: {0}".format(ltm_id))

	    if (current_time_minute % settings.regular_stat_interval) == 0:
		lt=logtime.LogTime(self.pg_mon_conn)
		lt_id=lt.get_id()
		if not lt_id:
		    self._rollback()
		    continue
		regular_stat=True
		self.pg_mon_conn.commit()
		logger.debug("Obtained lt_id: {0}".format(lt_id))

	    cur=self._get_cursor()
	    try:
		cur.execute("SELECT id FROM host_cluster WHERE alive AND observable")
	    except Exception as e:
		logger.critical("Cannot obtain list of clusters from pg_mon DB: {0}".format(e.pgerror))
		cur.close()
		self._rollback()
		continue
	    hc_ids=cur.fetchall()
	    cur.close()


###############################################################
################# HostClusters ################################
	    for hc_id in hc_ids:
		logger.debug("hc_id: {0}".format(hc_id[0]))
		hc=HostCluster(self.pg_mon_conn,hc_id[0])
		if not hc.discover_cluster_params():
		    logger.critical("Cannot discover clusters params for HC: {0}".format(hc.get_field('hostname')))
#		    continue
		if not hc.discover_databases():
		    logger.critical("Cannot discover databases for host ID: {0}".format(hc_id))
		if settings.runtime_stat_enable:
		    logger.debug("Runtime is enabled")
		    if not hc.runtime_stat(ltm_id):
			logger.error("Error from hc.runtime_stat()")
		if regular_stat:
		    logger.debug("Getting hc regular stat")
		    if not hc.stat(lt_id):
			logger.error("Error from hc.stat()")
		hc.__del__()
	    self.pg_mon_conn.close()
	    self._delay()