方法二:通过编写脚本来进行监控

 

// mysql_dll.cpp : Defines the entry point for the DLL application.

#include "stdafx.h"
#include "stdlib.h"

MYSQL *conn=NULL;
MYSQL_RES *p_res_ptr=NULL;
MYSQL_ROW sqlrows;


BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}

extern "C" int _declspec(dllexport) init_mysql_connection(char *str_server,char *str_username,char *str_pwd,char *str_Table)
{
conn=mysql_init(NULL);

    if(!conn)
{
  printf("\nFailed to initate MySQL connection");
  return 1;
  exit(0);
}
    else
{
  printf("\nSuccess to initate MySQL connection");
  if (!mysql_real_connect(conn,str_server,str_username,str_pwd,str_Table,0,NULL,0))
  {
   printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(conn));
  }
  else
  {
   printf("\nLogged on to %s sucessfully",str_server);
   return 0;
  }
  return 0;
}
}

extern "C" int _declspec(dllexport) close_mysql_connection()
{
if(conn=NULL)
{
  printf("\nConnection is Null");
  return 1;
  exit(0);
}
else
{
     mysql_free_result(p_res_ptr);
  printf("\nClose connection");
  mysql_close(conn);  
  return 0;
}
}

//"show status like \'qcache%\'"

extern "C" int _declspec(dllexport) get_mysql_table_query(char *str_query)
{
int res=0;
res=mysql_query(conn,str_query);
if(res)
{
  printf("Failed to mysql query: Error: %s\n", mysql_error(conn));
  return 1;
}
else
{
  printf("\nSucess in Mysql Query");
  return 0;

}

}

 

extern "C" int _declspec(dllexport) get_mysql_query_data(char *str_query,char *str_data)
{
    unsigned long u1_numrow=0;
    unsigned int i_index = 0;
p_res_ptr=mysql_use_result(conn);

if(p_res_ptr){

  while((sqlrows=mysql_fetch_row(p_res_ptr))){
 
   if(*sqlrows[0]=*str_query)
   {
    strcpy(str_data,sqlrows[1]);
  
  
   }
  }
}

return NULL;

}

 

lr 9.1中代码:
Action()
{

        int i=0;
        double x;
        char *str_data;


        str_data=(char *)malloc(20*sizeof(char));
        lr_load_dll("D:\\vc\\mysql_dll\\Debug\\mysql_dll.dll");
        i= init_mysql_connection("localhost","root","123456","mysql");
        lr_output_message("%d",i);
  
       for(;;)
       {
            get_mysql_query_data("Qcache_hits",str_data);
            i=get_mysql_table_query("show status like \'qcache%\'");
            lr_output_message("%d",i);
            x = atof(str_data);
            lr_user_data_point("hits",x);
            lr_think_time(5);
       }
        lr_output_message("%d",x);
     close_mysql_connection();
return 0;
}