qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

使用LoadRunner监测MySQL数据库的性能

   方法一:要想使用LoadRunner监测MySQL数据性能,LoadRunner没有提供直接监测 MySQL的功能,所以,我们需要借助sitescope监控,然后在LoadRunner显示sitescope监测结果,这样间接地监控MySQL性能。

  相信大家对LoadRunner应该十分熟悉了,所以在这里,我大概介绍下sitescope的安装和使用。

   sitescope是安装在被监测数据库所在的计算机上的,是一个比较新的软件,在网上很难下载在免费使用版,我是找了一下午才在一个论坛里找到一位老好心人上传的7.9.5版本和license,相当的好用,真是要谢谢这位兄台了!下载地址:http://bbs.51testing.com/viewthread.php?tid=80283

  软件下载好后,安装应该很容易了。安装好后系统重启,再次开机时,会自动跳出sitescope的初始网页,要求输入license等资料。保存后自动跳出网页提示,输入对应的网址进入sitescope主界面。(sitescope是运行在浏览器上的一款软件,每次要打开时,只要打开浏览器输入对应的网址即可进入对应的sitescope主界面。)

  监测MySQL需要使用到JDBC驱动程序,为了让sitescope能够监测到 MySQL。下载地址:http://www.mysql.com/downloads/connector/j/

   下载成功后,解压文件,把“mysql-connector-java-5.1.12-bin.jar”这个压缩文件复制到(sitescope安装目录下)sitescope\java\lib\ext下,重启系统。

  进入sitescope主界面,点击“create group”,输入自定义的组名,即可成功添加group。

  进入新建的组,在“Add to Group”一栏下点击monitor,新添加monitor。

  然后“Add Database Query monitor”。

  这里是关键:

  Database Connection URL:jdbc:mysql://<database hostname>[:<tcp port>]/<database>

  for example:要连接MySQL的数据库aBigDatabase,用MySQL的标准端口3306,则为 jdbc:mysql://206.168.191.19/aBigDatabase

  Query:show status where variable_name like ’innodb_buffer_pool_pages_total’

  Database Driver:org.gjt.mm.mysql.Driver

  updates时间和title可以根据自己的需要设置。

  Database User Name和Database Password需要咨询数据库管理员,拿到超级用户的用户名和密码。

  点击“Add”,保存即可。到此为止,sitescope已经能够监测到数据的信息了。接下去是连接LoadRunner。

  打开 LoadRunner的Controller,在“run”中添加“sitescope”,即可成功监测到被测数据库的信息了。哈哈,大功告成了!!!

  备注:

  MercyrySiteScope介绍:它是一款无代理监测解决方案,可确保分布式IT基础架构——如服务器、操作系统、网络设备、网络服务、应用和应用组件的可用性和性能。这款主动的、基于Web界面的基础架构监测解决方案是非常简洁的,而且完全根据客户度身定制,无需在您的上线系统中增加额外的代理。

  SiteScope为上线系统提供24×7的监控服务,为维护工程师及时发现问题提供帮助,确保系统架构内一切组建的正常运作。SiteScope在大量增加检测周期的同时也降低了维护人员的工作成本 。

  SiteScope能够监控UNIX服务器资源、windows服务器资源、weblogic应用服务器、IIS应用服务器、Oracle数据库、 SQLServer数据库、F5、URL地址、Ping、内存、CPU、磁盘空间、服务等等系统架构内各种组建的运行状况;监控器按照指定频率对目标进行检测,一旦发现异常会及时向管理员发送意外事件的报警,警报可以通过声音提醒、email、短信等方式发送;另外,SiteScope还可以生成监测活动的汇总报告,该对象从日志文件中读取历史信息,接着总结、筛选信息,并生成图表格式的报告。

  SiteScope利用Database Query monitor监控指定的数据库,通过SiteScope监控器的SHOW STATUS命令,获得相应数据,命令如下:

  show status where variable_name like ’innodb_buffer_pool_pages_total’

  为了确保监控请确认LoadRunner and SiteScope之间的端口, SiteScope和MySQL必须打开TCP 8888和TCP 3306 . 还有SiteScope要监控必须要确保有JDBC的安装。

  以下为监控前需要注意的地方:

  1. SiteScope to be deployed.

  2. Sufficient license points for Database Query monitor.

  3. TCP 8888 (default) opened two-way for LoadRunner to SiteScope.

  4. TCP 3306 (default) opened two-way for SiteScope to MySQL.

  5. Monitoring privileges for SiteScope to monitor MySQL.

  6. JDBC driver to be installed on SiteScope.

  7. Have knowledge of the counter you want to monitor.

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

// 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;
}


posted on 2012-06-04 15:10 顺其自然EVO 阅读(1376) 评论(1)  编辑  收藏 所属分类: loadrunner性能测试

评论

# re: 使用LoadRunner监测MySQL数据库的性能 2012-10-29 10:24

你好,请问sitescope是一定要安装到mysql的机器上吗  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2012年6月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜