压力测试web交互接口
压力测试web交互接口
更新记录
| 日期 | 更新人 | 更新内容 |
|---|---|---|
| 2019-11-20 | 叶木盛 | 初始编写 |
规范
接口域
请求方式
POST包体
数据类型
application/json
内容编码
UTF-8
请求包体的参数
| 参数 | 类型 | 长度 | 必须? | 示例值 | 描述 |
|---|---|---|---|---|---|
| data | Object | - | 是 | - | 请求包体的根节点 |
请求包体参数格式示例
{"data": {"field1": "value1","field2": "value2"}}
返回的消息字段
| 字段名 | 类型 | 长度 | 示例值 | 描述 |
|---|---|---|---|---|
| status | Int | 3 | 1 | 消息状态码,0=无数据或失败,1=有数据或成功 |
| message | String | 200 | success | 后端对错误的描述 |
| data | Object | - | 返回的数据。失败时为空对象 | |
| timestamp | Int | 10 | 1509878777 | 服务端的时间戳,秒级 |
返回的消息字段格式示例
{"status": 0,"message": "success","data": {"field1": "value1","field2": "value2"},"timestamp": 1509898888}
接口列表
机器基本信息上传接口
包括测试机、调度机、被测机的基本的静态数据。
接口地址
### 请求参数| 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 || --------- | ------ | ---- | ------ | ------------ | ---------------- || serial | String | 100 | 是 | 435435332523 | 机器唯一序列号 || memTotal | Float | 7,2 | 是 | 32.00 | 内存占用,单位GB || cpuCore | Int | 4 | 是 | 4 | cpu核心数 || cpuThread | Int | 4 | 是 | 8 | CPU线程数 || diskTotal | Float | 7,2 | 是 | 1024.00 | 磁盘总量,单位GB |### 请求示例```json{"data": {"serial": "999993333999933","memTotal": 32.00,"cpuCore": 4,"cpuThread": 8,"diskTotal": 1024.00}}
CURL命令请求示例
curl -H 'Content-Type:application/json' -X POST -d '{"data": {"serial": "5daeb45db6093","memTotal": 320, "cpuCore": 4,"cpuThread": 8, "diskTotal": 1024}}' http://{{接口域}}/uapi/jmeter/machine
返回字段
无,根据status状态判断是否成功
返回示例
{"status": 0,"message": "success","data": {},"timestamp": 1509898888}
机器性能数据上传接口
包括测试机、调度机、被测机的性能数据相同,性能数据实时刷新,需要实时轮循上传数据
接口地址
### 请求参数| 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 || ----------------- | ------ | ---- | ------ | ------------ | ---------------------- || serial | String | 100 | 是 | 435435332523 | 机器唯一序列号 || memUse | String | 7,2 | 是 | 32.23 | 内存占用,单位GB || memFree | Float | 7,2 | 是 | 3.23 | 内存空闲,单位GB || memCache | Float | 7,2 | 是 | 30.20 | 内存缓存占用,单位GB || cpuFree | Float | 5,2 | 是 | 90.00 | cpu空闲,单位 % || cpuUser | Float | 5,2 | 是 | 12.20 | cpu用户占用,单位% || cpuSystem | Float | 5,2 | 是 | 12.89 | cpu系统占用,单位% || cpuIoWaitTime | Int | 5 | 是 | 12 | cpu IO等等时间,单位ms || cpuFreeTime | Int | 5 | 是 | 54 | CPU空闲时间,单位ms || cpuInterruptTime | Int | 5 | 是 | 454 | cpu中断时间,单位ms || networkTrafficIn | Float | 7,2 | 是 | 421.32 | 传入网络流量,单位 KB || networkTrafficOut | Float | 7,2 | 是 | 123.2 | 传出网络流量,单位KB || diskWriteSpeed | Float | 7,2 | 是 | 82.21 | 磁盘写速率,单位MB || diskReadSpeed | Float | 7,2 | 是 | 90.00 | 磁盘读速率,单位MB || diskUse | Float | 7,2 | 是 | 2231.23 | 磁盘占用,单位MB || diskInode | Float | 7,2 | 是 | 231.23 | 磁盘inode使用情况 |### 请求示例```json{"data": {"serial": "999993333999933","memUse": 13.12,"memFree": 32.22...}}
CURL命令请求示例
curl -H 'Content-Type:application/json' -X POST -d '{"data": {"serial": "5daeb45db6093","memUse": 30.54, "memFree": 41.11,"memCache": 18.00, "cpuFree": 10.24,"cpuUser": 90.98,"cpuSystem":1.21,"cpuIoWaitTime":123,"cpuFreeTime":43,"cpuInterruptTime":8,"networkTrafficIn": 32.12,"networkTrafficOut": 123.32,"diskWriteSpeed":89,"diskReadSpeed": 129.21,"diskUse": 12,"diskInode":22}}' http://{{接口域}}/uapi/jmeter/performance
返回字段
无,根据status状态判断是否成功
返回示例
{"status": 0,"message": "success","data": {},"timestamp": 1509898888}
任务获取接口
任务由调度机获取
接口地址
### 请求参数| 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 || --------- | ------ | ---- | ------ | ------------ | ------------------------------------------------------------ || serial | String | 13 | 是 | 435435332523 | 机器唯一序列号 || lastOptId | Int | 11 | 否 | 123 | 上一次查询返回的最大ID,用于过滤已下发的任务,若需要重新获取所有任务,传值 0 即可。 |### 请求示例```json{"data": {"serial": "999993333999933","lastOptId": 0}}
返回字段
| 字段名 | 类型 | 长度 | 示例值 | 描述 |
|---|---|---|---|---|
| tasks | Object | 消息状态码,0=无数据或失败,1=有数据或成功 |
||
| lastOptId | Int | 11 | 131 | 最后一次查询的最大ID,客户端需存下来,下次请求获取任务时带上。 |
tasks节点字段
| 字段名 | 类型 | 长度 | 示例值 | 描述 |
|---|---|---|---|---|
| taskId | Int | 11 | 1122 | 任务ID |
| taskName | verchar | 50 | 任务名称 | 任务名称 |
| startTime | date | 2019-11-18 15:12:11 | 任务开始时间 | |
| agentSerial | verchar | 13 | 5dad7d2e1513a | 测试机序列号 |
| scriptUrl | verchar | 50 | http://172.18.1.93:8081/statics/jmeter/script/201911/20191112170138.zip | 测试脚本下载地址 |
| scriptVars | Object | 脚本参数的变量/值,json格式,变量数量根据脚本实际使用情况有所不同。以实际返回的数据为准 | ||
| optType | Int | 1 | 2 | 任务操作类型: 1:新任务; 2:暂停任务; 3:启动任务; 4:删除任务; |
设备状态上报接口
通过设备上报当前动作,更新设备状态和任务状态
接口地址
### 请求参数| 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 || ------ | ------ | ---- | ------ | ------------ | ------------------------------------------------------------ || serial | String | 13 | 是 | 435435332523 | 机器唯一序列号 || taskId | Int | 11 | 否 | 123 | 任务ID,当状态与任务有关时,需要带上任务ID,用于更新任务状态 || action | Int | 11 | 是 | 1 | 机器当前动作:<br />15:获取任务失败<br />16:下载脚本成功<br />17:下载脚本失败<br />18:任务运行<br />19:任务结束<br />20:任务完成<br />25:机器空闲<br />26:机器启动<br /> |### 请求示例```json{"data": {"serial": "999993333999933","action": 18,"taskId": 12}}
返回字段
无
返回示例
{"status": 0,"message": "update success!","data": {},"timestamp": 1509898888}
测试结果上传接口
结果由jmeter工具生成,再压缩为zip,通过表单方式上传到接口。
zip文件名:result_serial_taskId_yyyymmddhhiiss.zip
其中serial=机器序列号,taskId=任务ID,yyyymmddhhiiss=年月日+时间
请求方式
form表单 post方式上传
表单元素:
file: zip文件
md5: zip文件的md5
接口地址
{接口域}/uapi/jmeter/uploadResult
请求示例
curl -F "file=@/Users/coolwind/Downloads/result_5dad7fa457b63_9_20191120121212.zip" -F "md5=af1fa7bf3eb33a89b499ef25a21c39f8" http://autosense.com.cn/uapi/jmeter/uploadResult
返回示例
{"status":1,"message":"upload success","data":{"zipId":1},"timestamp":1574235406}
请求参数
zabbix机器性能常用接口
登录
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "user.login","params":{"user": "admin", "password": "zabbix"}, "id": 1, "auth": null}' http://192.168.1.69:8080/api_jsonrpc.php
返回
{"jsonrpc":"2.0","result":"2fde552ac4261455786a3758d6fc8414","id":1}
获取主机组ID
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "hostgroup.get","params":{"output": ["groupid"], "filter": {"name": ["Linux servers"]}}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
返回
{"jsonrpc":"2.0","result":[{"groupid":"2"}],"id":1}
通过主机组ID获取主机
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "host.get","params":{"output": ["host", "hostid"],"filter": {"groupids": 2}}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
返回
{"jsonrpc":"2.0","result":[{"hostid":"10257","host":"192.168.1.144"},{"hostid":"10258","host":"192.168.1.16"},{"hostid":"10084","host":"Zabbix server"}],"id":1}
通过主机ID获取监控数据
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "history.get","params":{"hostids": "10257", "sortfield": "clock", "sortorder": "ASC"}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
通过主机组ID获取监控项
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "item.get","params":{"output":["itemid","key_","name", "hostid","units"],"templateids": "10001"}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
通过主机host获取监控项
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "item.get","params":{"output":["itemid","key_","name", "hostid","units"],"host": "192.168.1.16"}, "id": 1, "auth": "704bfc948a2ca10dc2b718d2fd0c6c51"}' http://192.168.1.69:8080/api_jsonrpc.php
返回
{"jsonrpc":"2.0","result":[{"itemid":"28414","key_":"agent.hostname","name":"Host name of zabbix_agentd running","hostid":"10257","units":""},{"itemid":"28415","key_":"agent.ping","name":"Agent ping","hostid":"10257","units":""},{"itemid":"28416","key_":"agent.version","name":"Version of zabbix_agent(d) running","hostid":"10257","units":""},{"itemid":"28417","key_":"kernel.maxfiles","name":"Maximum number of opened files","hostid":"10257","units":""},{"itemid":"28418","key_":"kernel.maxproc","name":"Maximum number of processes","hostid":"10257","units":""},{"itemid":"28488","key_":"net.if.in[docker0]","name":"Incoming network traffic on $1","hostid":"10257","units":"bps"},{"itemid":"28487","key_":"net.if.in[enp1s0]","name":"Incoming network traffic on $1","hostid":"10257","units":"bps"},{"itemid":"28490","key_":"net.if.out[docker0]","name":"Outgoing network traffic on $1","hostid":"10257","units":"bps"},{"itemid":"28489","key_":"net.if.out[enp1s0]","name":"Outgoing network traffic on $1","hostid":"10257","units":"bps"},{"itemid":"28419","key_":"proc.num[,,run]","name":"Number of running processes","hostid":"10257","units":""},{"itemid":"28420","key_":"proc.num[]","name":"Number of processes","hostid":"10257","units":""},{"itemid":"28421","key_":"system.boottime","name":"Host boot time","hostid":"10257","units":"unixtime"},{"itemid":"28422","key_":"system.cpu.intr","name":"Interrupts per second","hostid":"10257","units":"ips"},{"itemid":"28423","key_":"system.cpu.load[percpu,avg15]","name":"Processor load (15 min average per core)","hostid":"10257","units":""},{"itemid":"28424","key_":"system.cpu.load[percpu,avg1]","name":"Processor load (1 min average per core)","hostid":"10257","units":""},{"itemid":"28425","key_":"system.cpu.load[percpu,avg5]","name":"Processor load (5 min average per core)","hostid":"10257","units":""},{"itemid":"28426","key_":"system.cpu.switches","name":"Context switches per second","hostid":"10257","units":"sps"},{"itemid":"28427","key_":"system.cpu.util[,idle]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28428","key_":"system.cpu.util[,interrupt]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28429","key_":"system.cpu.util[,iowait]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28430","key_":"system.cpu.util[,nice]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28431","key_":"system.cpu.util[,softirq]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28432","key_":"system.cpu.util[,steal]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28433","key_":"system.cpu.util[,system]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28434","key_":"system.cpu.util[,user]","name":"CPU $2 time","hostid":"10257","units":"%"},{"itemid":"28435","key_":"system.hostname","name":"Host name","hostid":"10257","units":""},{"itemid":"28436","key_":"system.localtime","name":"Host local time","hostid":"10257","units":"unixtime"},{"itemid":"28437","key_":"system.swap.size[,free]","name":"Free swap space","hostid":"10257","units":"B"},{"itemid":"28438","key_":"system.swap.size[,pfree]","name":"Free swap space in %","hostid":"10257","units":"%"},{"itemid":"28439","key_":"system.swap.size[,total]","name":"Total swap space","hostid":"10257","units":"B"},{"itemid":"28440","key_":"system.uname","name":"System information","hostid":"10257","units":""},{"itemid":"28441","key_":"system.uptime","name":"System uptime","hostid":"10257","units":"uptime"},{"itemid":"28442","key_":"system.users.num","name":"Number of logged in users","hostid":"10257","units":""},{"itemid":"28443","key_":"vfs.file.cksum[/etc/passwd]","name":"Checksum of $1","hostid":"10257","units":""},{"itemid":"28491","key_":"vfs.fs.inode[/,pfree]","name":"Free inodes on $1 (percentage)","hostid":"10257","units":"%"},{"itemid":"28492","key_":"vfs.fs.inode[/boot,pfree]","name":"Free inodes on $1 (percentage)","hostid":"10257","units":"%"},{"itemid":"28493","key_":"vfs.fs.size[/,free]","name":"Free disk space on $1","hostid":"10257","units":"B"},{"itemid":"28495","key_":"vfs.fs.size[/,pfree]","name":"Free disk space on $1 (percentage)","hostid":"10257","units":"%"},{"itemid":"28497","key_":"vfs.fs.size[/,total]","name":"Total disk space on $1","hostid":"10257","units":"B"},{"itemid":"28499","key_":"vfs.fs.size[/,used]","name":"Used disk space on $1","hostid":"10257","units":"B"},{"itemid":"28494","key_":"vfs.fs.size[/boot,free]","name":"Free disk space on $1","hostid":"10257","units":"B"},{"itemid":"28496","key_":"vfs.fs.size[/boot,pfree]","name":"Free disk space on $1 (percentage)","hostid":"10257","units":"%"},{"itemid":"28498","key_":"vfs.fs.size[/boot,total]","name":"Total disk space on $1","hostid":"10257","units":"B"},{"itemid":"28500","key_":"vfs.fs.size[/boot,used]","name":"Used disk space on $1","hostid":"10257","units":"B"},{"itemid":"28444","key_":"vm.memory.size[available]","name":"Available memory","hostid":"10257","units":"B"},{"itemid":"28445","key_":"vm.memory.size[total]","name":"Total memory","hostid":"10257","units":"B"}],"id":1}
通过主机IP获取主机ID
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "host.get","params":{"output": ["hostid"], "filter": {"host": "192.168.1.144"}}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
返回
{"jsonrpc":"2.0","result":[{"hostid":"10254"}],"id":1}
通过监控项获取监控项ID
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "item.get","params":{"output":["itemid","key_","name"],"hostids": "10259", "search": {"key_": "cpu"},"sortfield": "name"}, "id": 1, "auth": "704bfc948a2ca10dc2b718d2fd0c6c51"}' http://192.168.1.69:8080/api_jsonrpc.php
返回
{"jsonrpc":"2.0","result":[{"itemid":"28271","key_":"system.cpu.switches","name":"Context switches per second"},{"itemid":"28272","key_":"system.cpu.util[,idle]","name":"CPU $2 time"},{"itemid":"28273","key_":"system.cpu.util[,interrupt]","name":"CPU $2 time"},{"itemid":"28274","key_":"system.cpu.util[,iowait]","name":"CPU $2 time"},{"itemid":"28275","key_":"system.cpu.util[,nice]","name":"CPU $2 time"},{"itemid":"28276","key_":"system.cpu.util[,softirq]","name":"CPU $2 time"},{"itemid":"28277","key_":"system.cpu.util[,steal]","name":"CPU $2 time"},{"itemid":"28278","key_":"system.cpu.util[,system]","name":"CPU $2 time"},{"itemid":"28279","key_":"system.cpu.util[,user]","name":"CPU $2 time"},{"itemid":"28282","key_":"system.swap.size[,free]","name":"Free swap space"},{"itemid":"28283","key_":"system.swap.size[,pfree]","name":"Free swap space in %"},{"itemid":"28266","key_":"system.boottime","name":"Host boot time"},{"itemid":"28281","key_":"system.localtime","name":"Host local time"},{"itemid":"28280","key_":"system.hostname","name":"Host name"},{"itemid":"28267","key_":"system.cpu.intr","name":"Interrupts per second"},{"itemid":"28287","key_":"system.users.num","name":"Number of logged in users"},{"itemid":"28269","key_":"system.cpu.load[percpu,avg1]","name":"Processor load (1 min average per core)"},{"itemid":"28268","key_":"system.cpu.load[percpu,avg15]","name":"Processor load (15 min average per core)"},{"itemid":"28270","key_":"system.cpu.load[percpu,avg5]","name":"Processor load (5 min average per core)"},{"itemid":"28285","key_":"system.uname","name":"System information"},{"itemid":"28286","key_":"system.uptime","name":"System uptime"},{"itemid":"28284","key_":"system.swap.size[,total]","name":"Total swap space"}],"id":1}
获取主机基本静态数据
如:磁盘大小、CPU核心、CPU线程、
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "item.get","params":{"output":["itemid","key_","name"],"hostids": "10254", "search": {"key_": "vfs.fs.size[/,total]"},"sortfield": "name"}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
通过监控项ID获取性能数据
性能数据每分种更新一次
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "history.get","params":{"history":0,"itemids": ["28548","28547","28549"],"sortfield": "clock", "sortorder": "DESC"}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php
返回示例
{"jsonrpc":"2.0","result":[{"itemid":"28271","clock":"1574242811","value":"1610","ns":"585909259"},{"itemid":"28271","clock":"1574242751","value":"1652","ns":"559525530"},{"itemid":"28271","clock":"1574242691","value":"1638","ns":"534175889"},{"itemid":"28271","clock":"1574242631","value":"1651","ns":"508846817"},{"itemid":"28271","clock":"1574242571","value":"1640","ns":"483839541"}],"id":1}
通过主机id,获取当前主机的监控数据
curl -H 'Content-Type:application/json-rpc' -X POST -d '{"jsonrpc": "2.0", "method": "history.get","params":{"hostids": "10257", "time_from": 1574242931 ,"sortfield": "clock", "sortorder": "DESC"}, "id": 1, "auth": "2fde552ac4261455786a3758d6fc8414"}' http://192.168.1.69:8080/api_jsonrpc.php