MySQL:如何编写daemon plugin(12)
PLUGIN_VAR_OPCMDARG,
"disable monitor if 0,default TRUE",
NULL, NULL, TRUE);
struct st_mysql_sys_var*vars_system_var[] = {
MYSQL_SYSVAR(monitors_state),
NULL
};
/*创建status变量,可通过showstatus查看*/
static structst_mysql_show_var sys_status_var[] =
{
{"monitor_num", (char *)&monitor_num, SHOW_LONG},
{0, 0, 0}
};
/*线程函数,后台线程启动后,会持续执行该函数*/
pthread_handler_tmonitoring(void *p)
{
char buffer[MONITORING_BUFFER];
char time_str[20];
while(1) {
/*每隔5秒记录一次,我们也可以把5修改为一个可配置的系统变量*/
sleep(5);
if (!monitor_state)
continue;
monitor_num++;
/*获取当前时间,mysql自有函数*/
get_date(time_str, GETDATE_DATE_TIME,0);
snprintf(buffer, MONITORING_BUFFER,"%s: %u of %lu clients connected, "
"%lu connections made\n",
time_str, thread_count,
max_connections, thread_id);
/*使用getrusage函数来获得当前进程的运行状态,具体man getrusage*/
if (getrusage(RUSAGE_SELF, &usage)== 0){
snprintf(buffer+strlen(buffer) ,
MONITORING_BUFFER, "user time:%d,system time:%d,"
"maxrss:%d,ixrss:%d,idrss:%d,"
相关新闻>>
- 发表评论
-
- 最新评论 更多>>