压力测试web交互接口

压力测试web交互接口

更新记录

日期 更新人 更新内容
2019-11-20 叶木盛 初始编写

规范

接口域

http://ip:port

请求方式

POST包体

数据类型

application/json

内容编码

UTF-8

请求包体的参数

参数 类型 长度 必须? 示例值 描述
data Object - - 请求包体的根节点

请求包体参数格式示例

  1. {
  2. "data": {
  3. "field1": "value1",
  4. "field2": "value2"
  5. }
  6. }

返回的消息字段

字段名 类型 长度 示例值 描述
status Int 3 1 消息状态码,0=无数据或失败,1=有数据或成功
message String 200 success 后端对错误的描述
data Object - 返回的数据。失败时为空对象
timestamp Int 10 1509878777 服务端的时间戳,秒级

返回的消息字段格式示例

  1. {
  2. "status": 0,
  3. "message": "success",
  4. "data": {
  5. "field1": "value1",
  6. "field2": "value2"
  7. },
  8. "timestamp": 1509898888
  9. }

接口列表

机器基本信息上传接口

包括测试机、调度机、被测机的基本的静态数据。

接口地址

  1. ### 请求参数
  2. | 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 |
  3. | --------- | ------ | ---- | ------ | ------------ | ---------------- |
  4. | serial | String | 100 | | 435435332523 | 机器唯一序列号 |
  5. | memTotal | Float | 7,2 | | 32.00 | 内存占用,单位GB |
  6. | cpuCore | Int | 4 | | 4 | cpu核心数 |
  7. | cpuThread | Int | 4 | | 8 | CPU线程数 |
  8. | diskTotal | Float | 7,2 | | 1024.00 | 磁盘总量,单位GB |
  9. ### 请求示例
  10. ```json
  11. {
  12. "data": {
  13. "serial": "999993333999933",
  14. "memTotal": 32.00,
  15. "cpuCore": 4,
  16. "cpuThread": 8,
  17. "diskTotal": 1024.00
  18. }
  19. }

CURL命令请求示例

  1. 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状态判断是否成功

返回示例

  1. {
  2. "status": 0,
  3. "message": "success",
  4. "data": {},
  5. "timestamp": 1509898888
  6. }

机器性能数据上传接口

包括测试机、调度机、被测机的性能数据相同,性能数据实时刷新,需要实时轮循上传数据

接口地址

  1. ### 请求参数
  2. | 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 |
  3. | ----------------- | ------ | ---- | ------ | ------------ | ---------------------- |
  4. | serial | String | 100 | | 435435332523 | 机器唯一序列号 |
  5. | memUse | String | 7,2 | | 32.23 | 内存占用,单位GB |
  6. | memFree | Float | 7,2 | | 3.23 | 内存空闲,单位GB |
  7. | memCache | Float | 7,2 | | 30.20 | 内存缓存占用,单位GB |
  8. | cpuFree | Float | 5,2 | | 90.00 | cpu空闲,单位 % |
  9. | cpuUser | Float | 5,2 | | 12.20 | cpu用户占用,单位% |
  10. | cpuSystem | Float | 5,2 | | 12.89 | cpu系统占用,单位% |
  11. | cpuIoWaitTime | Int | 5 | | 12 | cpu IO等等时间,单位ms |
  12. | cpuFreeTime | Int | 5 | | 54 | CPU空闲时间,单位ms |
  13. | cpuInterruptTime | Int | 5 | | 454 | cpu中断时间,单位ms |
  14. | networkTrafficIn | Float | 7,2 | | 421.32 | 传入网络流量,单位 KB |
  15. | networkTrafficOut | Float | 7,2 | | 123.2 | 传出网络流量,单位KB |
  16. | diskWriteSpeed | Float | 7,2 | | 82.21 | 磁盘写速率,单位MB |
  17. | diskReadSpeed | Float | 7,2 | | 90.00 | 磁盘读速率,单位MB |
  18. | diskUse | Float | 7,2 | | 2231.23 | 磁盘占用,单位MB |
  19. | diskInode | Float | 7,2 | | 231.23 | 磁盘inode使用情况 |
  20. ### 请求示例
  21. ```json
  22. {
  23. "data": {
  24. "serial": "999993333999933",
  25. "memUse": 13.12,
  26. "memFree": 32.22
  27. ...
  28. }
  29. }

CURL命令请求示例

  1. 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状态判断是否成功

返回示例

  1. {
  2. "status": 0,
  3. "message": "success",
  4. "data": {},
  5. "timestamp": 1509898888
  6. }

任务获取接口

任务由调度机获取

接口地址

  1. ### 请求参数
  2. | 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 |
  3. | --------- | ------ | ---- | ------ | ------------ | ------------------------------------------------------------ |
  4. | serial | String | 13 | | 435435332523 | 机器唯一序列号 |
  5. | lastOptId | Int | 11 | | 123 | 上一次查询返回的最大ID,用于过滤已下发的任务,若需要重新获取所有任务,传值 0 即可。 |
  6. ### 请求示例
  7. ```json
  8. {
  9. "data": {
  10. "serial": "999993333999933",
  11. "lastOptId": 0
  12. }
  13. }

返回字段

字段名 类型 长度 示例值 描述
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:删除任务;

设备状态上报接口

通过设备上报当前动作,更新设备状态和任务状态

接口地址

  1. ### 请求参数
  2. | 参数名 | 类型 | 长度 | 必须? | 示例值 | 描述 |
  3. | ------ | ------ | ---- | ------ | ------------ | ------------------------------------------------------------ |
  4. | serial | String | 13 | | 435435332523 | 机器唯一序列号 |
  5. | taskId | Int | 11 | | 123 | 任务ID,当状态与任务有关时,需要带上任务ID,用于更新任务状态 |
  6. | action | Int | 11 | | 1 | 机器当前动作:<br />15:获取任务失败<br />16:下载脚本成功<br />17:下载脚本失败<br />18:任务运行<br />19:任务结束<br />20:任务完成<br />25:机器空闲<br />26:机器启动<br /> |
  7. ### 请求示例
  8. ```json
  9. {
  10. "data": {
  11. "serial": "999993333999933",
  12. "action": 18,
  13. "taskId": 12
  14. }
  15. }

返回字段

返回示例

  1. {
  2. "status": 0,
  3. "message": "update success!",
  4. "data": {},
  5. "timestamp": 1509898888
  6. }

测试结果上传接口

结果由jmeter工具生成,再压缩为zip,通过表单方式上传到接口。

zip文件名:result_serial_taskId_yyyymmddhhiiss.zip

其中serial=机器序列号,taskId=任务ID,yyyymmddhhiiss=年月日+时间

请求方式

form表单 post方式上传

表单元素:

file: zip文件

md5: zip文件的md5

接口地址

{接口域}/uapi/jmeter/uploadResult

请求示例

  1. curl -F "file=@/Users/coolwind/Downloads/result_5dad7fa457b63_9_20191120121212.zip" -F "md5=af1fa7bf3eb33a89b499ef25a21c39f8" http://autosense.com.cn/uapi/jmeter/uploadResult

返回示例

  1. {
  2. "status":1,
  3. "message":"upload success",
  4. "data":{
  5. "zipId":1
  6. },
  7. "timestamp":1574235406
  8. }

请求参数

zabbix机器性能常用接口

登录

  1. 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

返回

  1. {"jsonrpc":"2.0","result":"2fde552ac4261455786a3758d6fc8414","id":1}

获取主机组ID

  1. 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

返回

  1. {
  2. "jsonrpc":"2.0",
  3. "result":[
  4. {
  5. "groupid":"2"
  6. }
  7. ],
  8. "id":1
  9. }

通过主机组ID获取主机

  1. 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

返回

  1. {
  2. "jsonrpc":"2.0",
  3. "result":[
  4. {
  5. "hostid":"10257",
  6. "host":"192.168.1.144"
  7. },
  8. {
  9. "hostid":"10258",
  10. "host":"192.168.1.16"
  11. },
  12. {
  13. "hostid":"10084",
  14. "host":"Zabbix server"
  15. }
  16. ],
  17. "id":1
  18. }

通过主机ID获取监控数据

  1. 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获取监控项

  1. 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获取监控项

  1. 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

返回

  1. {
  2. "jsonrpc":"2.0",
  3. "result":[
  4. {
  5. "itemid":"28414",
  6. "key_":"agent.hostname",
  7. "name":"Host name of zabbix_agentd running",
  8. "hostid":"10257",
  9. "units":""
  10. },
  11. {
  12. "itemid":"28415",
  13. "key_":"agent.ping",
  14. "name":"Agent ping",
  15. "hostid":"10257",
  16. "units":""
  17. },
  18. {
  19. "itemid":"28416",
  20. "key_":"agent.version",
  21. "name":"Version of zabbix_agent(d) running",
  22. "hostid":"10257",
  23. "units":""
  24. },
  25. {
  26. "itemid":"28417",
  27. "key_":"kernel.maxfiles",
  28. "name":"Maximum number of opened files",
  29. "hostid":"10257",
  30. "units":""
  31. },
  32. {
  33. "itemid":"28418",
  34. "key_":"kernel.maxproc",
  35. "name":"Maximum number of processes",
  36. "hostid":"10257",
  37. "units":""
  38. },
  39. {
  40. "itemid":"28488",
  41. "key_":"net.if.in[docker0]",
  42. "name":"Incoming network traffic on $1",
  43. "hostid":"10257",
  44. "units":"bps"
  45. },
  46. {
  47. "itemid":"28487",
  48. "key_":"net.if.in[enp1s0]",
  49. "name":"Incoming network traffic on $1",
  50. "hostid":"10257",
  51. "units":"bps"
  52. },
  53. {
  54. "itemid":"28490",
  55. "key_":"net.if.out[docker0]",
  56. "name":"Outgoing network traffic on $1",
  57. "hostid":"10257",
  58. "units":"bps"
  59. },
  60. {
  61. "itemid":"28489",
  62. "key_":"net.if.out[enp1s0]",
  63. "name":"Outgoing network traffic on $1",
  64. "hostid":"10257",
  65. "units":"bps"
  66. },
  67. {
  68. "itemid":"28419",
  69. "key_":"proc.num[,,run]",
  70. "name":"Number of running processes",
  71. "hostid":"10257",
  72. "units":""
  73. },
  74. {
  75. "itemid":"28420",
  76. "key_":"proc.num[]",
  77. "name":"Number of processes",
  78. "hostid":"10257",
  79. "units":""
  80. },
  81. {
  82. "itemid":"28421",
  83. "key_":"system.boottime",
  84. "name":"Host boot time",
  85. "hostid":"10257",
  86. "units":"unixtime"
  87. },
  88. {
  89. "itemid":"28422",
  90. "key_":"system.cpu.intr",
  91. "name":"Interrupts per second",
  92. "hostid":"10257",
  93. "units":"ips"
  94. },
  95. {
  96. "itemid":"28423",
  97. "key_":"system.cpu.load[percpu,avg15]",
  98. "name":"Processor load (15 min average per core)",
  99. "hostid":"10257",
  100. "units":""
  101. },
  102. {
  103. "itemid":"28424",
  104. "key_":"system.cpu.load[percpu,avg1]",
  105. "name":"Processor load (1 min average per core)",
  106. "hostid":"10257",
  107. "units":""
  108. },
  109. {
  110. "itemid":"28425",
  111. "key_":"system.cpu.load[percpu,avg5]",
  112. "name":"Processor load (5 min average per core)",
  113. "hostid":"10257",
  114. "units":""
  115. },
  116. {
  117. "itemid":"28426",
  118. "key_":"system.cpu.switches",
  119. "name":"Context switches per second",
  120. "hostid":"10257",
  121. "units":"sps"
  122. },
  123. {
  124. "itemid":"28427",
  125. "key_":"system.cpu.util[,idle]",
  126. "name":"CPU $2 time",
  127. "hostid":"10257",
  128. "units":"%"
  129. },
  130. {
  131. "itemid":"28428",
  132. "key_":"system.cpu.util[,interrupt]",
  133. "name":"CPU $2 time",
  134. "hostid":"10257",
  135. "units":"%"
  136. },
  137. {
  138. "itemid":"28429",
  139. "key_":"system.cpu.util[,iowait]",
  140. "name":"CPU $2 time",
  141. "hostid":"10257",
  142. "units":"%"
  143. },
  144. {
  145. "itemid":"28430",
  146. "key_":"system.cpu.util[,nice]",
  147. "name":"CPU $2 time",
  148. "hostid":"10257",
  149. "units":"%"
  150. },
  151. {
  152. "itemid":"28431",
  153. "key_":"system.cpu.util[,softirq]",
  154. "name":"CPU $2 time",
  155. "hostid":"10257",
  156. "units":"%"
  157. },
  158. {
  159. "itemid":"28432",
  160. "key_":"system.cpu.util[,steal]",
  161. "name":"CPU $2 time",
  162. "hostid":"10257",
  163. "units":"%"
  164. },
  165. {
  166. "itemid":"28433",
  167. "key_":"system.cpu.util[,system]",
  168. "name":"CPU $2 time",
  169. "hostid":"10257",
  170. "units":"%"
  171. },
  172. {
  173. "itemid":"28434",
  174. "key_":"system.cpu.util[,user]",
  175. "name":"CPU $2 time",
  176. "hostid":"10257",
  177. "units":"%"
  178. },
  179. {
  180. "itemid":"28435",
  181. "key_":"system.hostname",
  182. "name":"Host name",
  183. "hostid":"10257",
  184. "units":""
  185. },
  186. {
  187. "itemid":"28436",
  188. "key_":"system.localtime",
  189. "name":"Host local time",
  190. "hostid":"10257",
  191. "units":"unixtime"
  192. },
  193. {
  194. "itemid":"28437",
  195. "key_":"system.swap.size[,free]",
  196. "name":"Free swap space",
  197. "hostid":"10257",
  198. "units":"B"
  199. },
  200. {
  201. "itemid":"28438",
  202. "key_":"system.swap.size[,pfree]",
  203. "name":"Free swap space in %",
  204. "hostid":"10257",
  205. "units":"%"
  206. },
  207. {
  208. "itemid":"28439",
  209. "key_":"system.swap.size[,total]",
  210. "name":"Total swap space",
  211. "hostid":"10257",
  212. "units":"B"
  213. },
  214. {
  215. "itemid":"28440",
  216. "key_":"system.uname",
  217. "name":"System information",
  218. "hostid":"10257",
  219. "units":""
  220. },
  221. {
  222. "itemid":"28441",
  223. "key_":"system.uptime",
  224. "name":"System uptime",
  225. "hostid":"10257",
  226. "units":"uptime"
  227. },
  228. {
  229. "itemid":"28442",
  230. "key_":"system.users.num",
  231. "name":"Number of logged in users",
  232. "hostid":"10257",
  233. "units":""
  234. },
  235. {
  236. "itemid":"28443",
  237. "key_":"vfs.file.cksum[/etc/passwd]",
  238. "name":"Checksum of $1",
  239. "hostid":"10257",
  240. "units":""
  241. },
  242. {
  243. "itemid":"28491",
  244. "key_":"vfs.fs.inode[/,pfree]",
  245. "name":"Free inodes on $1 (percentage)",
  246. "hostid":"10257",
  247. "units":"%"
  248. },
  249. {
  250. "itemid":"28492",
  251. "key_":"vfs.fs.inode[/boot,pfree]",
  252. "name":"Free inodes on $1 (percentage)",
  253. "hostid":"10257",
  254. "units":"%"
  255. },
  256. {
  257. "itemid":"28493",
  258. "key_":"vfs.fs.size[/,free]",
  259. "name":"Free disk space on $1",
  260. "hostid":"10257",
  261. "units":"B"
  262. },
  263. {
  264. "itemid":"28495",
  265. "key_":"vfs.fs.size[/,pfree]",
  266. "name":"Free disk space on $1 (percentage)",
  267. "hostid":"10257",
  268. "units":"%"
  269. },
  270. {
  271. "itemid":"28497",
  272. "key_":"vfs.fs.size[/,total]",
  273. "name":"Total disk space on $1",
  274. "hostid":"10257",
  275. "units":"B"
  276. },
  277. {
  278. "itemid":"28499",
  279. "key_":"vfs.fs.size[/,used]",
  280. "name":"Used disk space on $1",
  281. "hostid":"10257",
  282. "units":"B"
  283. },
  284. {
  285. "itemid":"28494",
  286. "key_":"vfs.fs.size[/boot,free]",
  287. "name":"Free disk space on $1",
  288. "hostid":"10257",
  289. "units":"B"
  290. },
  291. {
  292. "itemid":"28496",
  293. "key_":"vfs.fs.size[/boot,pfree]",
  294. "name":"Free disk space on $1 (percentage)",
  295. "hostid":"10257",
  296. "units":"%"
  297. },
  298. {
  299. "itemid":"28498",
  300. "key_":"vfs.fs.size[/boot,total]",
  301. "name":"Total disk space on $1",
  302. "hostid":"10257",
  303. "units":"B"
  304. },
  305. {
  306. "itemid":"28500",
  307. "key_":"vfs.fs.size[/boot,used]",
  308. "name":"Used disk space on $1",
  309. "hostid":"10257",
  310. "units":"B"
  311. },
  312. {
  313. "itemid":"28444",
  314. "key_":"vm.memory.size[available]",
  315. "name":"Available memory",
  316. "hostid":"10257",
  317. "units":"B"
  318. },
  319. {
  320. "itemid":"28445",
  321. "key_":"vm.memory.size[total]",
  322. "name":"Total memory",
  323. "hostid":"10257",
  324. "units":"B"
  325. }
  326. ],
  327. "id":1
  328. }

通过主机IP获取主机ID

  1. 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

返回

  1. {"jsonrpc":"2.0","result":[{"hostid":"10254"}],"id":1}

通过监控项获取监控项ID

  1. 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

返回

  1. {
  2. "jsonrpc":"2.0",
  3. "result":[
  4. {
  5. "itemid":"28271",
  6. "key_":"system.cpu.switches",
  7. "name":"Context switches per second"
  8. },
  9. {
  10. "itemid":"28272",
  11. "key_":"system.cpu.util[,idle]",
  12. "name":"CPU $2 time"
  13. },
  14. {
  15. "itemid":"28273",
  16. "key_":"system.cpu.util[,interrupt]",
  17. "name":"CPU $2 time"
  18. },
  19. {
  20. "itemid":"28274",
  21. "key_":"system.cpu.util[,iowait]",
  22. "name":"CPU $2 time"
  23. },
  24. {
  25. "itemid":"28275",
  26. "key_":"system.cpu.util[,nice]",
  27. "name":"CPU $2 time"
  28. },
  29. {
  30. "itemid":"28276",
  31. "key_":"system.cpu.util[,softirq]",
  32. "name":"CPU $2 time"
  33. },
  34. {
  35. "itemid":"28277",
  36. "key_":"system.cpu.util[,steal]",
  37. "name":"CPU $2 time"
  38. },
  39. {
  40. "itemid":"28278",
  41. "key_":"system.cpu.util[,system]",
  42. "name":"CPU $2 time"
  43. },
  44. {
  45. "itemid":"28279",
  46. "key_":"system.cpu.util[,user]",
  47. "name":"CPU $2 time"
  48. },
  49. {
  50. "itemid":"28282",
  51. "key_":"system.swap.size[,free]",
  52. "name":"Free swap space"
  53. },
  54. {
  55. "itemid":"28283",
  56. "key_":"system.swap.size[,pfree]",
  57. "name":"Free swap space in %"
  58. },
  59. {
  60. "itemid":"28266",
  61. "key_":"system.boottime",
  62. "name":"Host boot time"
  63. },
  64. {
  65. "itemid":"28281",
  66. "key_":"system.localtime",
  67. "name":"Host local time"
  68. },
  69. {
  70. "itemid":"28280",
  71. "key_":"system.hostname",
  72. "name":"Host name"
  73. },
  74. {
  75. "itemid":"28267",
  76. "key_":"system.cpu.intr",
  77. "name":"Interrupts per second"
  78. },
  79. {
  80. "itemid":"28287",
  81. "key_":"system.users.num",
  82. "name":"Number of logged in users"
  83. },
  84. {
  85. "itemid":"28269",
  86. "key_":"system.cpu.load[percpu,avg1]",
  87. "name":"Processor load (1 min average per core)"
  88. },
  89. {
  90. "itemid":"28268",
  91. "key_":"system.cpu.load[percpu,avg15]",
  92. "name":"Processor load (15 min average per core)"
  93. },
  94. {
  95. "itemid":"28270",
  96. "key_":"system.cpu.load[percpu,avg5]",
  97. "name":"Processor load (5 min average per core)"
  98. },
  99. {
  100. "itemid":"28285",
  101. "key_":"system.uname",
  102. "name":"System information"
  103. },
  104. {
  105. "itemid":"28286",
  106. "key_":"system.uptime",
  107. "name":"System uptime"
  108. },
  109. {
  110. "itemid":"28284",
  111. "key_":"system.swap.size[,total]",
  112. "name":"Total swap space"
  113. }
  114. ],
  115. "id":1
  116. }

获取主机基本静态数据

如:磁盘大小、CPU核心、CPU线程、

  1. 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获取性能数据

性能数据每分种更新一次

  1. 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

返回示例

  1. {
  2. "jsonrpc":"2.0",
  3. "result":[
  4. {
  5. "itemid":"28271",
  6. "clock":"1574242811",
  7. "value":"1610",
  8. "ns":"585909259"
  9. },
  10. {
  11. "itemid":"28271",
  12. "clock":"1574242751",
  13. "value":"1652",
  14. "ns":"559525530"
  15. },
  16. {
  17. "itemid":"28271",
  18. "clock":"1574242691",
  19. "value":"1638",
  20. "ns":"534175889"
  21. },
  22. {
  23. "itemid":"28271",
  24. "clock":"1574242631",
  25. "value":"1651",
  26. "ns":"508846817"
  27. },
  28. {
  29. "itemid":"28271",
  30. "clock":"1574242571",
  31. "value":"1640",
  32. "ns":"483839541"
  33. }
  34. ],
  35. "id":1
  36. }

通过主机id,获取当前主机的监控数据

  1. 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