天天看點

使用LoadRunner監測MySQL資料庫的性能

  相信大家對loadrunner應該十分熟悉了,是以在這裡,我大概介紹下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可以根據自己的需要設定。

  點選“add”,儲存即可。到此為止,sitescope已經能夠監測到資料的資訊了。接下去是連接配接loadrunner。

  打開 loadrunner的controller,在“run”中添加“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");

else

     mysql_free_result(p_res_ptr);

  printf("\nclose connection");

  mysql_close(conn);  

//"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));

  printf("\nsucess in mysql query");

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;

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;

====================================分割線================================

最新内容請見作者的github頁:http://qaseven.github.io/