Friday, March 2, 2012

Monitoring specific MySQL counters using LoadRunner

You can monitor MySQL database using Sitescope. However, if you don't have access to the Sitescope application then you can write a simple LoadRunner script to monitor specific MySQL counters and plot the values using lr_user_data_point LR function. The following script is an enhancement to MySQL script detailed in my earlier post.

NOTE:
All session related information in MySQL is stored in a table called "SESSION_STATUS". Therefore, we will be querying this table for MySQL counter values.

For demonstration purpose, the script below will query the values for LAST_QUERY_COST, OPENED_TABLES, QCACHE_HITS, SELECT_FULL_JOIN and SELECT_SCAN counters.

Global declaration
#include "C:\\Program Files\\MySQL\\oldfiles\\include\\mysql.h" //mySQL.h path is included 

/*MySQL structure defined*/
MYSQL *mySQL;
MYSQL_ROW row;
MYSQL_RES *result;
int MyRC;

char *MySQLserver = "localhost"; // Location where server is running
char *MySQLuser = "root"; // User name used to connect to the database
char *MySQLpassword = ""; // Not a good idea to leave password empty
char *MySQLdatabase = "information_schema"; //Database name 
int MySQLport = 3306; // Database port

Vvuser_int
//libmysql.dll file loaded using lr_load_dll function
 MyRC= lr_load_dll("C:\\Program Files\\MySQL\\MySQL Connector C 6.0.2\\lib\\opt\\libmysql.dll"); 

 //Initialise mySQL connection handler
 mySQL= mysql_init(NULL);

 // Connect to the database
 mysql_real_connect(mySQL,MySQLserver, MySQLuser, MySQLpassword, MySQLdatabase, MySQLport,NULL,0);

 return 0;

Query Function
double atof(const char *string); // Explicit declaration
Query()
{  
    int i=0;
    float VarValue[5]; //Float variable array
    /*Save SQL statement into variable into sqlQuery.
     This query returns values for the variable name ={LAST_QUERY_COST,OPENED_TABLES,QCACHE_HITS,SELECT_FULL_JOIN,SELECT_SCAN}*/ 
 lr_param_sprintf("sqlQuery","select variable_value from session_status where variable_name IN"
      "('LAST_QUERY_COST','OPENED_TABLES','QCACHE_HITS','SELECT_FULL_JOIN','SELECT_SCAN')");

 mysql_query(mySQL, lr_eval_string ("{sqlQuery}")); //Execute SQL statement

 result = mysql_store_result(mySQL);   //Result of the sql statement is placed into MYSQL_RES result structure
  
 row=mysql_fetch_row(result);   
     
 while(row!=NULL) //Iterate through to last row
 {
  VarValue[i]=atof(row[0]);  //Save float row value to VarValue
  row=mysql_fetch_row(result);  //Retrive next row of the fetched result
  i++;
 }

/*Use lr_user_data_point function to generate the graph*/
 lr_user_data_point("LAST_QUERY_COST", VarValue[0]);
 lr_user_data_point("OPEN_TABLES", VarValue[1]);
 lr_user_data_point("QCACHE_HITS", VarValue[2]);
 lr_user_data_point("SELECT_FULL_JOIN", VarValue[3]);
 lr_user_data_point("SELECT_SCAN", VarValue[4]);

 return 0;
}

vuser_end
/*Free the memory allocated to result structure and close the database connection*/
 mysql_free_result(result);
 mysql_close(mySQL);
 return 0;



NOTE: Make sure you are explicitly declaring the atof function before using it or else you will get totally different values. See the screenshot of the values received for the above counters when atof was not declared explicitly before using it.

Friday, December 30, 2011

Loadrunner SOAP over JMS script for Websphere MQ

Question:
How to submit a SOAP over JMS request to Websphere MQ using LoadRunner SOA protocol?

Solution:
Prerequisite
  1. JMS Queue details
  2. Websphere MQ Client installed (if not installed, instructions are below)
  3. Websphere MQ jar files installed (if not installed, instructions are below)
  4. JDK installed (if not installed, instructions are below)

JMS Queue Details
Depending on which queue(s) you want to send and receive a message from as well as the MQ architecture design, you will require following MQ information from your Websphere MQ Admin.
  • HostName
  • Channel
  • Port
  • Queue Manager
  • Input Queue
  • Output Queue
  • Queue Connection Factory
  • Username and password

For example, in my case, to send a message to an Input Queue, following information was required:
  • HostName – xxx.xxx.xxx
  • Channel - ICF.DEF.SVRCONN
  • Port - 1414(might be different)
  • Queue Manager - Not Required
  • Input Queue - Input_queue_name
  • Output Queue - Not Required
  • Queue Connection Factory - qcf
  • Username and password - Not required
Webshere MQ Jar files
  1. Install JAVA JDK on your local machine
  2. Copy MQ jar files into the JDK...->Java ->jre-> ext folder. You will need to get these jar files from your Webpshere MQ admin
  3. Also, since we are using fscontext as initial context factory, you will need to download and save fscontext and providerutil.jar files in the above mentioned folder
How to create JNDI binding
  1. Install Websphere MQ Client application on your local machine.
  2. Navigate to the location where JMSAdmin.config file is located and open it. We are going to select a context factory to use and path where to create the binding file. In my case this file is located at C:\Program Files (x86)\IBM\WebSphere MQ\Java\bin Update and save the file with following details:
  3. INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory PROVIDER_URL=file:/C:/JNDI
  4. Create a new qm.scp file (make sure this file is in the same folder as JMSAdmin.bat file) and put there the MQ details. The .scp file will look like this:
  5. DEFINE QCF(qcf) tran(client) chan(ICF.DEF.SVRCONN) host(xxx.xxx.xxx) port(1414) DISPLAY QCF(qcf) DEFINE Q(Input_queue) QUEUE(Input_queue) DISPLAY Q(Input_queue) end
  6. Create the JNDI folder on your C drive. This is where your binding file will automatically be saved.
  7. Navigate to “...\WebSphere MQ\Java\bin” and edit JMSAdmin.bat by replacing “java” text with the full java path incase it is not already defined in your System environment settings.
  8. Navigate to Websphere MQ Java bin folder via the command prompt and execute the JMSAdmin Tool (JMSAdmin. Bat file) with qm.scp as the parameter. This will generate a .bindings file in the JNDI folder automatically.



  9. You will see something like this when JMSAdmin bat application is executed.
    Cool, JNDI binding is done.
Creating a Webservices Loadrunner Script
  1. Open up a new web services script.
  2. Press F4 to Navigate to Run-time setting and update the following fields in JMS->Advanced option:
  3. -JVM Home: JAVA path
    -JNDI initial context factory: com.sun.jndi.fscontext.RefFSContextFactory
    -JNDI provider URL: file:/C:/JNDI/
    -JMS connection factory: QCF name
  4. Now you are ready to create your MQ script.
  5. You can then use Web Services jms_set_general_property, jms_send_message_queue, jms_set_message_property and jms_receive_message_property functions.
NOTE: JMS Bindings Extensions are not supported in Loadrunner 11.

Thursday, December 22, 2011

How to monitor JVM running in Loadrunner mmdrv process

If you are testing SOAP over JMS using Web Services protocol in Loadrunner, you can monitor JVM(in process) which is invoked by mmdrv.exe, either using JConsole or JVisualVM or any other tool that allows you to monitor JVM.

Before you use JConsole or JVisualVM, you will need to set jmxremote parameter in Loadrunner. To do so, add “-Dcom.sun.management.jmxremote” as a Value in the “Additional VM Parameters” textbox. See the figure below.

Now, run your script and open up JVisualVM to monitor the JVM running within the mmdrv process.

NOTE: If you are using JVisualVM tool for monitoring then you do not need to set remote jmx parameter. It is only required for Jconsole.

Wednesday, November 9, 2011

WebSphere MQ - 'java' is not recognized as an internal... error message

Problem:
You might get the 'java' is not recognized error message when generating a binding for WebSphere MQ using JMSAdmin tool.

Example:
C:\...\WebSphere MQ\Java\bin>JMSAdmin < qm.scp

Running the batch file might give you the following error message:
'java' is not recognized as an internal or external command, operable program or batch file.

Solution:
Step 1: Open up your JMSAdmin batch file using notepad. It will look something like this.

Step 2: Find out the full Java path on your local machine. In my case the Java file is located in the following folder:
C:\Program Files (x86)\Java\jdk1.7.0_01\bin\Java

Step 3: Replace “Java” with your Java path from Step 2. Save the file.

Step 4: Run the JMSAdmin again. This time your binding is created.

Sunday, November 6, 2011

Connecting to Opensolaris from Mac using SSH

Following is a command on how to access an Opensolaris system (VM) running on a local machine. In this case it is my Mac.

NOTE: Make sure you have a username & password setup on Opensolaris to access it via SSH. More information on SSH can be found here.

Command:
$ ssh -x username@hostaddress

example:
$ssh -x hpseera@192.161.11.111