This is a script based on the script for custom monitoring Tomcat using LoadRunner. this article describes how parameters interact and how parameters and variables are copied and transferred. the following code comments are written according to your own understanding, and the correctness is not guaranteed.
[CPP]View plaincopy
- Action ()
- {
- // Define a three-character array for condition judgment
- Char JFM [100];
- Char JTM [100];
- Char jmm [100];
- // You must declare the data conversion function in advance. Otherwise, the monitoring result is incorrect.
- Double atof (const char * string );
- // The following three web_reg_save_param documents capture monitoring data from Tomcat:
- Web_reg_save_param ("jvm_free_memory ",
- "LB = free memory :",
- "RB = Mb ",
- "Ord = 1 ",
- Last );
- Web_reg_save_param ("jvm_total_memory ",
- "LB = total memory :",
- "RB = Mb ",
- "Ord = 1 ",
- Last );
- Web_reg_save_param ("jvm_max_memory ",
- "LB = max memory :",
- "RB = Mb ",
- "Ord = 1 ",
- Last );
- // Set monitoring transactions
- Lr_start_transaction ("status ");
- // Log on to Tomcat
- Web_set_user ("admin", "admin", "localhost: 8080 ");
- // Tomcat monitoring URL
- Web_url ("status ",
- "Url = http: // localhost: 8080/manager/status ",
- "Resource = 0 ",
- "Reccontenttype = text/html ",
- "Snapshot = t1.inf ",
- "Mode = html ",
- Last );
- Lr_end_transaction ("status", lr_pass );
- // User-defined monitoring of atat_jvm usage
- // Lr_user_data_point ("JVM free memory", atof (lr_eval_string ("{jvm_free_memory }")));
- // Lr_user_data_point ("JVM total memory", atof (lr_eval_string ("{jvm_total_memory }")));
- // Lr_user_data_point ("JVM Max memory", atof (lr_eval_string ("{jvm_max_memory }")));
- Lr_output_message ("**********************************");
- // Print Monitoring Value
- Lr_output_message (lr_eval_string ("{jvm_free_memory }"));
- Lr_output_message (lr_eval_string ("{jvm_total_memory }"));
- Lr_output_message (lr_eval_string ("{jvm_max_memory }"));
- Lr_output_message ("**********************************");
- // Save the parameter value in another parameter (in principle, it is similar to the reference in C ++)
- Lr_save_string (lr_eval_string ("{jvm_free_memory}"), "jfreemem ");
- Lr_save_string (lr_eval_string ("{jvm_total_memory}"), "jtotalmem ");
- Lr_save_string (lr_eval_string ("{jvm_max_memory}"), "jmaxmem ");
- Lr_output_message ("**********************************");
- // Print the value in "Reference"
- Lr_output_message (lr_eval_string ("{jfreemem }"));
- Lr_output_message (lr_eval_string ("{jtotalmem }"));
- Lr_output_message (lr_eval_string ("{jmaxmem }"));
- Lr_output_message ("**********************************");
- // Assign the parameter value to the variable (String Array)
- Strcpy (JFM, lr_eval_string ("{jvm_free_memory }"));
- Strcpy (JTM, lr_eval_string ("{jvm_total_memory }"));
- Strcpy (jmm, lr_eval_string ("{jvm_max_memory }"));
- // Perform logical judgment
- If (strcmp (JFM, "") = 0 & strcmp (JTM, "") = 0 & strcmp (jmm, "") = 0 ){
- Lr_output_message ("% s", "No parameter ");
- } Else {
- Lr_output_message ("% s", "parameter ");
- }
- // Output the actual value
- Lr_output_message ("**********************************");
- Lr_output_message ("% s", JFM );
- Lr_output_message ("% s", JTM );
- Lr_output_message ("% s", jmm );
- Lr_output_message ("**********************************");
- // Save the variable value in another parameter (in principle, it is similar to the reference in C ++)
- Lr_save_string (JFM, "jfreemem ");
- Lr_save_string (JTM, "jtotalmem ");
- Lr_save_string (jmm, "jmaxmem ");
- Lr_output_message ("**********************************");
- Return 0;
- }
Conversion between LoadRunner parameters and variables