port=int(port), connect_timeout=3, charset='utf8') cur = conn.cursor() conn.select_db('information_schema') except MySQLdb.Error, e: logger_msg = "check mysql second %s:%s failure: %d %s" % ( host, port, e.args[0], e.args[1]) logger.warning(logger_msg) connect = 0 sql = "insert into mysql_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param = (server_id, host, port, tags, connect) func.mysql_exec(sql, param) try: func.check_db_status(server_id, host, port, tags, 'mysql') except Exception, e: logger.error(e) sys.exit(1) def main(): func.mysql_exec( "insert into mysql_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from mysql_status", '') func.mysql_exec('delete from mysql_status;', '') func.mysql_exec( "insert into mysql_replication_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from mysql_replication", '')
func.update_db_status_init(role, version, host, port, tags) except Exception, e: logger_msg = "check memcache %s:%s : %s" % (host, port, e) logger.warning(logger_msg) try: curr_connections = 0 sql = "replace into memcache_status(server_id,host,port,tags,curr_connections) values(%s,%s,%s,%s,%s)" param = (server_id, host, port, tags, curr_connections) func.mysql_exec(sql, param) except Exception, e: logger.error(e) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id, host, port, tags, 'memcache') sys.exit(1) def main(): func.mysql_exec( "replace into memcache_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from memcache_status;", '') func.mysql_exec( 'delete from memcache_status where server_id not in (select id from db_servers_memcache where monitor=1);', '') #func.mysql_exec('delete from memcache_status;','') #get memcache servers list servers = func.mysql_query( 'select id,host,port,tags from db_servers_memcache where is_delete=0 and monitor=1;' )
logger.warning(logger_msg) time.sleep(3) try: conn=MySQLdb.connect(host=host,user=username,passwd=password,port=int(port),connect_timeout=3,charset='utf8') cur=conn.cursor() conn.select_db('information_schema') except MySQLdb.Error,e: logger_msg="check mysql second %s:%s failure: %d %s" %(host,port,e.args[0],e.args[1]) logger.warning(logger_msg) connect = 0 sql="insert into mysql_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param=(server_id,host,port,tags,connect) func.mysql_exec(sql,param) try: func.check_db_status(server_id,host,port,tags,'mysql') except Exception, e: logger.error(e) sys.exit(1) def main(): func.mysql_exec("insert into mysql_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from mysql_status",'') func.mysql_exec('delete from mysql_status;','') func.mysql_exec("insert into mysql_replication_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from mysql_replication",'') func.mysql_exec('delete from mysql_replication;','') #get mysql servers list servers = func.mysql_query('select id,host,port,username,password,tags from db_servers_mysql where is_delete=0 and monitor=1;')
logger.warning(logger_msg) try: connect = 0 sql = "insert into mongodb_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param = (server_id, host, port, tags, connect) func.mysql_exec(sql, param) except Exception, e: logger.error(e) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id, host, port, tags, 'mongodb') sys.exit(1) def main(): func.mysql_exec( "insert into mongodb_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from mongodb_status;", '') func.mysql_exec('delete from mongodb_status;', '') #get mongodb servers list servers = func.mysql_query( 'select id,host,port,username,password,tags from db_servers_mongodb where is_delete=0 and monitor=1;' )
logger.warning(logger_msg) try: connect = 0 sql = "insert into redis_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param = (server_id, host, port, tags, connect) func.mysql_exec(sql, param) except Exception, e: logger.error(e) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id, host, port, tags, 'redis') sys.exit(1) def main(): func.mysql_exec( "insert into redis_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from redis_status;", '') func.mysql_exec('delete from redis_status;', '') func.mysql_exec( "insert into redis_replication_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from redis_replication;", '') func.mysql_exec('delete from redis_replication;', '') servers = func.mysql_query(
logger.warning(logger_msg) try: connect = 0 sql = "insert into sqlserver_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param = (server_id, host, port, tags, connect) func.mysql_exec(sql, param) except Exception, e: logger.error(e) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id, host, port, tags, "sqlserver") sys.exit(1) def main(): func.mysql_exec( "insert into sqlserver_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from sqlserver_status;", "", ) func.mysql_exec("delete from sqlserver_status;", "") servers = func.mysql_query( "select id,host,port,username,password,tags from db_servers_sqlserver where is_delete=0 and monitor=1;" )
logger_msg="check oracle %s : %s" %(url,str(e).strip('\n')) logger.warning(logger_msg) try: connect=0 sql="insert into oracle_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param=(server_id,host,port,tags,connect) func.mysql_exec(sql,param) except Exception, e: logger.error(str(e).strip('\n')) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id,host,port,tags,'oracle') try: #get info by v$instance connect = 1 instance_name = oracle.get_instance(conn,'instance_name') instance_role = oracle.get_instance(conn,'instance_role') database_role = oracle.get_database(conn,'database_role') db_name = oracle.get_database(conn,'name') open_mode = oracle.get_database(conn,'open_mode') protection_mode = oracle.get_database(conn,'protection_mode') if database_role == 'PRIMARY': database_role_new = 'm' dg_stats = '-1' dg_delay = '-1'
logger.warning(logger_msg) try: connect=0 sql="insert into redis_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param=(server_id,host,port,tags,connect) func.mysql_exec(sql,param) except Exception, e: logger.error(e) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id,host,port,tags,'redis') sys.exit(1) def main(): func.mysql_exec("insert into redis_status_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from redis_status;",'') func.mysql_exec('delete from redis_status;','') func.mysql_exec("insert into redis_replication_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from redis_replication;",'') func.mysql_exec('delete from redis_replication;','') servers = func.mysql_query('select id,host,port,password,tags from db_servers_redis where is_delete=0 and monitor=1;') logger.info("check redis controller started.") if servers:
logger.warning(logger_msg) try: connect=0 sql="insert into mongodb_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param=(server_id,host,port,tags,connect) func.mysql_exec(sql,param) except Exception, e: logger.error(e) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id,host,port,tags,'mongodb') sys.exit(1) def main(): servers = func.mysql_query('select id,host,port,username,password,tags from db_servers_mongodb where is_delete=0 and monitor=1;') logger.info("check mongodb controller started.") if servers: plist = [] for row in servers: server_id=row[0] host=row[1]
logger_msg="check oracle %s : %s" %(url,str(e).strip('\n')) logger.warning(logger_msg) try: connect=0 sql="insert into oracle_status(server_id,host,port,tags,connect) values(%s,%s,%s,%s,%s)" param=(server_id,host,port,tags,connect) func.mysql_exec(sql,param) except Exception, e: logger.error(str(e).strip('\n')) sys.exit(1) finally: sys.exit(1) finally: func.check_db_status(server_id,host,port,tags,'oracle') try: #get info by v$instance connect = 1 instance_name = oracle.get_instance(conn,'instance_name') instance_role = oracle.get_instance(conn,'instance_role') database_role = oracle.get_database(conn,'database_role') open_mode = oracle.get_database(conn,'open_mode') protection_mode = oracle.get_database(conn,'protection_mode') if database_role == 'PRIMARY': database_role_new = 'm' dg_stats = '-1' dg_delay = '-1' else: database_role_new = 's'