MySQL:如何编写daemon plugin(15)
return 1;
}
get_date(time_str, GETDATE_DATE_TIME, 0);
sprintf(buffer, "Monitoring started at%s\n", time_str);
write(monitoring_file, buffer,strlen(buffer));
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
if (pthread_create(&monitoring_thread,&attr,
monitoring, NULL) != 0){
fprintf(stderr, "Plugin'monitoring': "
"Could not create monitoringthread!\n");
return 1;
}
return 0;
}
/*卸载插件时调用*/
static intmonitoring_plugin_deinit(void *p)
{
char buffer[MONITORING_BUFFER];
char time_str[20];
/*通知后台线程结束*/
pthread_cancel(monitoring_thread);
pthread_join(monitoring_thread, NULL);
get_date(time_str, GETDATE_DATE_TIME, 0);
sprintf(buffer, "Monitoring stopped at%s\n", time_str);
write(monitoring_file, buffer,strlen(buffer));
close(monitoring_file);
return 0;
}
struct st_mysql_daemonmonitoring_plugin = { MYSQL_DAEMON_INTERFACE_VERSION };
/*声明插件*/
mysql_declare_plugin(monitoring)
{
MYSQL_DAEMON_PLUGIN,
&monitoring_plugin,
"monitoring",
"yinfeng",
"a daemon montor,log process usagestate",
PLUGIN_LICENSE_GPL,
monitoring_plugin_init,
monitoring_plugin_deinit,
0x0100,
sys_status_var,
vars_system_var,
NULL
相关新闻>>
- 发表评论
-
- 最新评论 更多>>