void perf_pop (void) { struct perf *prev; struct perf *cur; prev = get_perf (-2); cur = get_perf (-1); ASSERT (cur); perf_stop (cur); if (prev) perf_resume (prev); pop_perf_index (); }
void perf_push (int type) { struct perf *prev; struct perf *cur; ASSERT (SIZE(metric_names) == PERF_N); push_perf_index (type); prev = get_perf (-2); cur = get_perf (-1); ASSERT (cur); if (prev) perf_interrupt (prev); perf_start (cur); }
int main(int argc,char **argv) { int opt; int digit_optind = 0; char *dbprofile = "/etc/my.cnf"; int lc,lcw,lt,prs,conferr; //Innodb locks number. CNF cnf; cnf.host = (char *)malloc(sizeof(char)*128); cnf.user = (char *)malloc(sizeof(char)*128); cnf.password = (char *)malloc(sizeof(char)*128); cnf.port = 0; cnf.socket = (char *)malloc(sizeof(char)*128); cnf.pidfile = (char *)malloc(sizeof(char)*128); memset(cnf.host,0,128); memset(cnf.user,0,128); memset(cnf.password,0,128); memset(cnf.socket,0,128); memset(cnf.pidfile,0,128); if(argc <= 1){ //如果没有给参数,就去/etc/my.cnf中取 parse_cnf(dbprofile,&cnf); }else{ while(1){ int this_option_optind = optind? optind: 1; int option_index = 0; static struct option long_options[] = { {"osinfo",no_argument,0,'o'}, {"appls",no_argument,0,'a'}, {"bufps",no_argument,0,'b'} }; opt = getopt_long(argc,argv,"h:P:u:p:s:",long_options,&option_index); if(opt == -1) break; switch(opt){ case 'h': sprintf(cnf.host,"%s",optarg); break; case 'P': cnf.port = atoi(optarg); break; case 'u': sprintf(cnf.user,optarg); break; case 'p': sprintf(cnf.password,optarg); break; case 's': sprintf(cnf.socket,optarg); break; default: fprintf(stdout,"Parametera Error"); } } } PLA *pla; pla = (PLA*)malloc(sizeof(PLA)); //定义Osinfo的一个实例 Osinfo *os; int get_os_info_res = 0; os = (Osinfo *)malloc(sizeof(Osinfo)); malloc_os_info(os); os->port = cnf.port; //获取操作系统状态信息 get_os_info_res = get_os_info(os); if(get_os_info_res == -1){ perror("get_os_info()"); exit(1); } /*创建一个数据库快照实例并初始化这个实例。*/ MysqlSnapshot ms; malloc_ms(&ms); /*性能指标信息*/ PERF perf; malloc_perf(&perf); /*Innodb Locks Summary*/ INNODB_LOCK ail[]={0}; INNODB_LOCK **il; il = (INNODB_LOCK **)&ail; INNODB_LOCKWAIT ailw[]={0}; INNODB_LOCKWAIT **ilw; ilw = (INNODB_LOCKWAIT **)&ailw; INNODB_TRX ait[]={0}; INNODB_TRX **it; it = (INNODB_TRX **)&ait; MYPS amps[]={0}; MYPS **procs; procs = (MYPS **)&s; //得到CPU硬件信息 get_cpu_hardinfo(os); //得到内存信息 get_mem_info(os); //得到系统负载信息 get_loadavg_info(os); //得到CPU运行状态 get_cpuavg_info(os); /*创建一个MySQL数据库连接*/ MYSQL *conn = NULL; conn = mysql_init(NULL); //连接到MySQL服务。 mysql_real_connect(conn,cnf.host,cnf.user,cnf.password,NULL,cnf.port,cnf.socket,0); if(conn->net.last_errno != 0){ fprintf(stdout,"%s,host=%s,port=%d,region=%s,sport=%d Connection_ErrMsg=\"%s\",Connection_Errno=%d\n","ParateraDB",os->hostname,os->port,"DatabaseConnection",cnf.port,conn->net.last_error,conn->net.last_errno); exit(conn->net.last_errno); } fprintf(stdout,"%s,host=%s,port=%d,region=%s,sport=%d Connection_errMsg=\"OK\",Connection_Errno=%d\n","ParateraDB",os->hostname,os->port,"DatabaseConnection",cnf.port,conn->net.last_errno); //if(strstr(mysql_get_server_info(conn),"5.6") == NULL){ // fprintf(stderr,"Server Unknown\n"); // exit(0); //} //得到数据库服务器快照信息 get_mysql_snapshot(&ms,conn); //获取系统性能信息 get_perf(&ms,&perf,conn); //打印数据库服务器快照信息 get_process_summary(conn,procs,&prs); //打印数据库服务器快照信息 get_innodb_locks_summary(conn,il,&lc); get_innodb_lockwait_summary(conn,ilw,&lcw); //获取INNODB存储引擎的SQL查询内容. get_innodb_transactions_summary(conn,it,<); //得到文件系统使用信息 get_fsusage(&ms); processlist_analysis(conn,pla); influx_files_output(os,&ms,&perf); influx_appls_output(os,&ms,&perf,pla); influx_locks_output(os,&ms); influx_bufps_output(os,&ms,&perf); influx_query_output(os,&ms,&perf); influx_threads_output(os,&ms,&perf); influx_logs_output(os,&ms,&perf); if(strstr(ms.version,"5.6") != NULL){ ShowSlaveStatus(&ms,conn); influx_slave_status_output(&ms,os); } else if(strstr(ms.version,"5.7") != NULL){ ShowSlaveStatus7(&ms,conn); influx_slave_status_output7(&ms,os); } else{ fprintf(stderr,"Not Support Database Version\n"); } influx_mmtrk_output(os,&ms); influx_wsrep_output(&ms,os); exit(0); }