1、打开loadrunnder11
点击“create/Edit Script”
2、选择“Web(HTTP/HTML)”
去掉Record the application startup前面的“√”,
(因为不用录制,而是自己写脚本)
3、编写脚本
4、设置并发数
1 设置迭代数
2 Insert Action 可以添加已经编写好的脚本,delete 可以删除已经编写好的脚本(删除的脚本文件不运行相当于禁用)
5、脚本
5.1 获取指定时间范围内的最大最小值
GetMaxAction(){
lr_start_transaction(“获取指定时间范围内的最大最小值”);
//首先使用web_reg_save_param方法保存服务器返回的参数
//web_reg_save_param (“S_respond”,“LB=”,“RB=”,LAST);
web_set_user(“userName”,
“passWord”, //r_decrypt(“58cf7265b1677820107f74”), //可以选择对密码加密
“10.172.4.2:18082”);
web_set_sockets_option(“INITIAL_BASIC_AUTH”,“1”);
web_custom_request(“web_custom_request”,
“Method=POST”,
“URL=https://10.198.5.5:8888/dr/v2/?pry”,
“RecContentType=application/json”,
“EncType=application/json”,
“Mode=HTTP”,
“Body={“queryType”: “timeseries”,“dataSource”: “wikipedia”,“intervals”: [“2015-09-12T00:00:00.000Z/2015-09-12T02:00:00.000Z”],“granularity”: “hour”,“aggregations”: [{“type”: “doubleMax”,“name”: “doubleMax”,“fieldName”: “added” },{“type”: “doubleMin”,“name”: “doubleMin”,“fieldName”: “added” },{“type”: “longMax”,“name”: “longMax”,“fieldName”: “added” },{“type”: “longMin”,“name”: “longMin”,“fieldName”: “added” }]}”,
LAST);
lr_end_transaction(“获取指定时间范围内的最大最小值”,LR_AUTO);
//直接打印服务器返回的字符串
//lr_output_message(lr_eval_string("{S_respond}"));
return 0;
}
5.2获取指定时间范围内的字段和,字段个数以及平均值
GetSumAction(){
lr_start_transaction(“获取指定时间范围内的字段和,字段个数以及平均值”);
//首先使用web_reg_save_param方法保存服务器返回的参数
//web_reg_save_param (“S_respond”,“LB=”,“RB=”,LAST);
web_set_user(“userName”,
“passWord”, //r_decrypt(“58cf7265b1677820107f74”), //可以选择对密码加密
“10.198.5.5:8888”);
web_set_sockets_option(“INITIAL_BASIC_AUTH”,“1”);
web_custom_request(“web_custom_request”,
“Method=POST”,
“URL=https://10.198.5.5:8888/dr/v2/?pty”,
“RecContentType=application/json”,
“EncType=application/json”,
“Mode=HTTP”,
“Body={“queryType”: “timeseries”,“dataSource”: “wikipedia”,“intervals”: [“2015-09-12T00:00:00.000Z/2015-09-12T02:00:00.000Z”],“granularity”: “hour”,“aggregations”: [{“type”: “doubleSum”,“name”: “doubleSum”,“fieldName”: “added”},{“type”: “count”,“name”: “count”}],“postAggregations”: [{“fields”: [{“type”: “fieldAccess”,“fieldName”: “doubleSum”},{“type”: “fieldAccess”, “fieldName”: “count”}],“type”: “arithmetic”,“name”: “average”,“fn”:”/"}]}",
LAST);
lr_end_transaction(“获取指定时间范围内的字段和,字段个数以及平均值”,LR_AUTO);
//直接打印服务器返回的字符串
//lr_output_message(lr_eval_string("{S_respond}"));
return 0;
}
5.4 SQl查询前10条
GetLimitSQL(){
lr_start_transaction(“查询前10条”);
//首先使用web_reg_save_param方法保存服务器返回的参数
//web_reg_save_param (“S_respond”,“LB=”,“RB=”,LAST);
web_set_user(“userName”,
“PassWord”, //r_decrypt(“58cf7265b1677820107f74”), //可以选择对密码加密
“10.198.5.5:8888”);
web_set_sockets_option(“INITIAL_BASIC_AUTH”,“1”);
web_custom_request(“web_custom_request”,
“Method=POST”,
“URL=https://10.198.5.5:8888/dr/v2/sql?pry”,
“RecContentType=application/json”,
“EncType=application/json”,
“Mode=HTTP”,
“Body={“query”:“select * from \“powertsdb-metric-node\” limit 10 " }”,
LAST);
lr_end_transaction(“查询前10条”,LR_AUTO);
//直接打印服务器返回的字符串
//lr_output_message(lr_eval_string(”{S_respond}"));
return 0;
}
6、设置场景
6.1 在脚本编辑页面进行设置
设置并发数:Number of Vusers
6.2 自动跳转至Controter窗口
在场景中,设置如下参数,双击可进入设置,解释下,各个参数的意思
Start Vusers:下图的意思是,开启20个虚拟用户,每15秒开启2个。
Duration:持续时间,意思是,20个用户开启之后,持续5分钟运行。
Stop Vusers:停止虚拟用户,每30秒停止5个虚拟用户。
6.3 点击 start 后,打开Analysis