管理监控API (REST API)

用户可以通过 REST API 查询 MQTT 客户端连接(Connections)、会话(Sessions)、订阅(Subscriptions)和路由(Routes)信息,还可以检索和监控服务器的性能指标和统计数据。

URL 地址

REST API 访问URL地址:

  1. http(s)://host:8080/api/v3/

Basic 认证

使用 REST API 必须携带 HTTP Basic 格式的认证(Authentication)信息。因此,需要使用 Dashboard 中来创建的 AppID 和 AppSecret 进行认证:

  1. # 例如:获取当前集群状态
  2. curl -v --basic -u <appid>:<appsecret> -k http://localhost:8080/api/v3/brokers

API 信息

获取当前 REST API 列表

API 定义:

  1. GET api/v3/

请求示例:

  1. GET api/v3/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "name": "list_clientid",
  6. "method": "GET",
  7. "path": "/auth_clientid",
  8. "descr": "List available clientid in the cluster"
  9. },
  10. {
  11. "name": "lookup_clientid",
  12. "method": "GET",
  13. "path": "/auth_clientid/:clientid",
  14. "descr": "Lookup clientid in the cluster"
  15. },
  16. {
  17. "name": "add_clientid",
  18. "method": "POST",
  19. "path": "/auth_clientid",
  20. "descr": "Add clientid in the cluster"
  21. },
  22. {
  23. "name": "update_clientid",
  24. "method": "PUT",
  25. "path": "/auth_clientid/:clientid",
  26. "descr": "Update clientid in the cluster"
  27. },
  28. {
  29. "name": "delete_clientid",
  30. "method": "DELETE",
  31. "path": "/auth_clientid/:clientid",
  32. "descr": "Delete clientid in the cluster"
  33. },
  34. {
  35. "name": "list_username",
  36. "method": "GET",
  37. "path": "/auth_username",
  38. "descr": "List available username in the cluster"
  39. },
  40. {
  41. "name": "lookup_username",
  42. "method": "GET",
  43. "path": "/auth_username/:username",
  44. "descr": "Lookup username in the cluster"
  45. },
  46. {
  47. "name": "add_username",
  48. "method": "POST",
  49. "path": "/auth_username",
  50. "descr": "Add username in the cluster"
  51. },
  52. {
  53. "name": "update_username",
  54. "method": "PUT",
  55. "path": "/auth_username/:username",
  56. "descr": "Update username in the cluster"
  57. },
  58. {
  59. "name": "delete_username",
  60. "method": "DELETE",
  61. "path": "/auth_username/:username",
  62. "descr": "Delete username in the cluster"
  63. },
  64. {
  65. "name": "auth_user",
  66. "method": "POST",
  67. "path": "/auth",
  68. "descr": "Authenticate an user"
  69. },
  70. {
  71. "name": "create_user",
  72. "method": "POST",
  73. "path": "/users/",
  74. "descr": "Create an user"
  75. },
  76. {
  77. "name": "list_users",
  78. "method": "GET",
  79. "path": "/users/",
  80. "descr": "List users"
  81. },
  82. {
  83. "name": "update_user",
  84. "method": "PUT",
  85. "path": "/users/:name",
  86. "descr": "Update an user"
  87. },
  88. {
  89. "name": "delete_user",
  90. "method": "DELETE",
  91. "path": "/users/:name",
  92. "descr": "Delete an user"
  93. },
  94. {
  95. "name": "change_pwd",
  96. "method": "PUT",
  97. "path": "/change_pwd/:username",
  98. "descr": "Change password for an user"
  99. },
  100. {
  101. "name": "list_all_alarms",
  102. "method": "GET",
  103. "path": "/alarms/present",
  104. "descr": "List all alarms"
  105. },
  106. {
  107. "name": "list_node_alarms",
  108. "method": "GET",
  109. "path": "/alarms/present/:node",
  110. "descr": "List alarms of a node"
  111. },
  112. {
  113. "name": "list_all_alarm_history",
  114. "method": "GET",
  115. "path": "/alarms/history",
  116. "descr": "List all alarm history"
  117. },
  118. {
  119. "name": "list_node_alarm_history",
  120. "method": "GET",
  121. "path": "/alarms/history/:node",
  122. "descr": "List alarm history of a node"
  123. },
  124. {
  125. "name": "add_app",
  126. "method": "POST",
  127. "path": "/apps/",
  128. "descr": "Add Application"
  129. },
  130. {
  131. "name": "del_app",
  132. "method": "DELETE",
  133. "path": "/apps/:appid",
  134. "descr": "Delete Application"
  135. },
  136. {
  137. "name": "list_apps",
  138. "method": "GET",
  139. "path": "/apps/",
  140. "descr": "List Applications"
  141. },
  142. {
  143. "name": "lookup_app",
  144. "method": "GET",
  145. "path": "/apps/:appid",
  146. "descr": "Lookup Application"
  147. },
  148. {
  149. "name": "update_app",
  150. "method": "PUT",
  151. "path": "/apps/:appid",
  152. "descr": "Update Application"
  153. },
  154. {
  155. "name": "list_banned",
  156. "method": "GET",
  157. "path": "/banned/",
  158. "descr": "List banned"
  159. },
  160. {
  161. "name": "create_banned",
  162. "method": "POST",
  163. "path": "/banned/",
  164. "descr": "Create banned"
  165. },
  166. {
  167. "name": "delete_banned",
  168. "method": "DELETE",
  169. "path": "/banned/:who",
  170. "descr": "Delete banned"
  171. },
  172. {
  173. "name": "list_brokers",
  174. "method": "GET",
  175. "path": "/brokers/",
  176. "descr": "A list of brokers in the cluster"
  177. },
  178. {
  179. "name": "get_broker",
  180. "method": "GET",
  181. "path": "/brokers/:node",
  182. "descr": "Get broker info of a node"
  183. },
  184. {
  185. "name": "get_all_configs",
  186. "method": "GET",
  187. "path": "/configs/",
  188. "descr": "Get all configs"
  189. },
  190. {
  191. "name": "get_all_configs",
  192. "method": "GET",
  193. "path": "/nodes/:node/configs/",
  194. "descr": "Get all configs of a node"
  195. },
  196. {
  197. "name": "update_config",
  198. "method": "PUT",
  199. "path": "/configs/:app",
  200. "descr": "Update config of an application in the cluster"
  201. },
  202. {
  203. "name": "update_node_config",
  204. "method": "PUT",
  205. "path": "/nodes/:node/configs/:app",
  206. "descr": "Update config of an application on a node"
  207. },
  208. {
  209. "name": "get_plugin_configs",
  210. "method": "GET",
  211. "path": "/nodes/:node/plugin_configs/:plugin",
  212. "descr": "Get configurations of a plugin on the node"
  213. },
  214. {
  215. "name": "update_plugin_configs",
  216. "method": "PUT",
  217. "path": "/nodes/:node/plugin_configs/:plugin",
  218. "descr": "Update configurations of a plugin on the node"
  219. },
  220. {
  221. "name": "list_connections",
  222. "method": "GET",
  223. "path": "/connections/",
  224. "descr": "A list of connections in the cluster"
  225. },
  226. {
  227. "name": "list_node_connections",
  228. "method": "GET",
  229. "path": "nodes/:node/connections/",
  230. "descr": "A list of connections on a node"
  231. },
  232. {
  233. "name": "lookup_node_connections",
  234. "method": "GET",
  235. "path": "nodes/:node/connections/:clientid",
  236. "descr": "Lookup a connection on node"
  237. },
  238. {
  239. "name": "lookup_connections",
  240. "method": "GET",
  241. "path": "/connections/:clientid",
  242. "descr": "Lookup a connection in the cluster"
  243. },
  244. {
  245. "name": "lookup_node_connection_via_username",
  246. "method": "GET",
  247. "path": "/nodes/:node/connection/username/:username",
  248. "descr": "Lookup a connection via username in the cluster "
  249. },
  250. {
  251. "name": "lookup_connection_via_username",
  252. "method": "GET",
  253. "path": "/connection/username/:username",
  254. "descr": "Lookup a connection via username on a node "
  255. },
  256. {
  257. "name": "kickout_connection",
  258. "method": "DELETE",
  259. "path": "/connections/:clientid",
  260. "descr": "Kick out a connection"
  261. },
  262. {
  263. "name": "list_listeners",
  264. "method": "GET",
  265. "path": "/listeners/",
  266. "descr": "A list of listeners in the cluster"
  267. },
  268. {
  269. "name": "list_node_listeners",
  270. "method": "GET",
  271. "path": "/nodes/:node/listeners",
  272. "descr": "A list of listeners on the node"
  273. },
  274. {
  275. "name": "list_all_metrics",
  276. "method": "GET",
  277. "path": "/metrics/",
  278. "descr": "A list of metrics of all nodes in the cluster"
  279. },
  280. {
  281. "name": "list_node_metrics",
  282. "method": "GET",
  283. "path": "/nodes/:node/metrics/",
  284. "descr": "A list of metrics of a node"
  285. },
  286. {
  287. "name": "list_nodes",
  288. "method": "GET",
  289. "path": "/nodes/",
  290. "descr": "A list of nodes in the cluster"
  291. },
  292. {
  293. "name": "get_node",
  294. "method": "GET",
  295. "path": "/nodes/:node",
  296. "descr": "Lookup a node in the cluster"
  297. },
  298. {
  299. "name": "list_all_plugins",
  300. "method": "GET",
  301. "path": "/plugins/",
  302. "descr": "List all plugins in the cluster"
  303. },
  304. {
  305. "name": "list_node_plugins",
  306. "method": "GET",
  307. "path": "/nodes/:node/plugins/",
  308. "descr": "List all plugins on a node"
  309. },
  310. {
  311. "name": "load_plugin",
  312. "method": "PUT",
  313. "path": "/nodes/:node/plugins/:plugin/load",
  314. "descr": "Load a plugin"
  315. },
  316. {
  317. "name": "unload_plugin",
  318. "method": "PUT",
  319. "path": "/nodes/:node/plugins/:plugin/unload",
  320. "descr": "Unload a plugin"
  321. },
  322. {
  323. "name": "reload_plugin",
  324. "method": "PUT",
  325. "path": "/nodes/:node/plugins/:plugin/reload",
  326. "descr": "Reload a plugin"
  327. },
  328. {
  329. "name": "mqtt_subscribe",
  330. "method": "POST",
  331. "path": "/mqtt/subscribe",
  332. "descr": "Subscribe a topic"
  333. },
  334. {
  335. "name": "mqtt_publish",
  336. "method": "POST",
  337. "path": "/mqtt/publish",
  338. "descr": "Publish a MQTT message"
  339. },
  340. {
  341. "name": "mqtt_unsubscribe",
  342. "method": "POST",
  343. "path": "/mqtt/unsubscribe",
  344. "descr": "Unsubscribe a topic"
  345. },
  346. {
  347. "name": "list_routes",
  348. "method": "GET",
  349. "path": "/routes/",
  350. "descr": "List routes"
  351. },
  352. {
  353. "name": "lookup_routes",
  354. "method": "GET",
  355. "path": "/routes/:topic",
  356. "descr": "Lookup routes to a topic"
  357. },
  358. {
  359. "name": "list_sessions",
  360. "method": "GET",
  361. "path": "/sessions/",
  362. "descr": "A list of sessions in the cluster"
  363. },
  364. {
  365. "name": "list_node_sessions",
  366. "method": "GET",
  367. "path": "nodes/:node/sessions/",
  368. "descr": "A list of sessions on a node"
  369. },
  370. {
  371. "name": "lookup_session",
  372. "method": "GET",
  373. "path": "/sessions/:clientid",
  374. "descr": "Lookup a session in the cluster"
  375. },
  376. {
  377. "name": "lookup_node_session",
  378. "method": "GET",
  379. "path": "nodes/:node/sessions/:clientid",
  380. "descr": "Lookup a session on the node"
  381. },
  382. {
  383. "name": "clean_presisent_session",
  384. "method": "DELETE",
  385. "path": "/sessions/persistent/:clientid",
  386. "descr": "Clean a persistent session in the cluster"
  387. },
  388. {
  389. "name": "clean_node_presisent_session",
  390. "method": "DELETE",
  391. "path": "nodes/:node/sessions/persistent/:clientid",
  392. "descr": "Clean a persistent session on the node"
  393. },
  394. {
  395. "name": "list_stats",
  396. "method": "GET",
  397. "path": "/stats/",
  398. "descr": "A list of stats of all nodes in the cluster"
  399. },
  400. {
  401. "name": "lookup_node_stats",
  402. "method": "GET",
  403. "path": "/nodes/:node/stats/",
  404. "descr": "A list of stats of a node"
  405. },
  406. {
  407. "name": "list_subscriptions",
  408. "method": "GET",
  409. "path": "/subscriptions/",
  410. "descr": "A list of subscriptions in the cluster"
  411. },
  412. {
  413. "name": "list_node_subscriptions",
  414. "method": "GET",
  415. "path": "/nodes/:node/subscriptions/",
  416. "descr": "A list of subscriptions on a node"
  417. },
  418. {
  419. "name": "lookup_client_subscriptions",
  420. "method": "GET",
  421. "path": "/subscriptions/:clientid",
  422. "descr": "A list of subscriptions of a client"
  423. },
  424. {
  425. "name": "lookup_client_subscriptions_with_node",
  426. "method": "GET",
  427. "path": "/nodes/:node/subscriptions/:clientid",
  428. "descr": "A list of subscriptions of a client on the node"
  429. },
  430. {
  431. "name": "create_rule",
  432. "method": "POST",
  433. "path": "/rules/",
  434. "descr": "Create a rule"
  435. },
  436. {
  437. "name": "list_rules",
  438. "method": "GET",
  439. "path": "/rules/",
  440. "descr": "A list of all rules"
  441. },
  442. {
  443. "name": "show_rule",
  444. "method": "GET",
  445. "path": "/rules/:id",
  446. "descr": "Show a rule"
  447. },
  448. {
  449. "name": "delete_rule",
  450. "method": "DELETE",
  451. "path": "/rules/:id",
  452. "descr": "Delete a rule"
  453. },
  454. {
  455. "name": "list_actions",
  456. "method": "GET",
  457. "path": "/actions/",
  458. "descr": "A list of all actions"
  459. },
  460. {
  461. "name": "show_action",
  462. "method": "GET",
  463. "path": "/actions/:name",
  464. "descr": "Show an action"
  465. },
  466. {
  467. "name": "list_resources",
  468. "method": "GET",
  469. "path": "/resources/",
  470. "descr": "A list of all resources"
  471. },
  472. {
  473. "name": "create_resource",
  474. "method": "POST",
  475. "path": "/resources/",
  476. "descr": "Create a resource"
  477. },
  478. {
  479. "name": "show_resource",
  480. "method": "GET",
  481. "path": "/resources/:id",
  482. "descr": "Show a resource"
  483. },
  484. {
  485. "name": "get_resource_status",
  486. "method": "GET",
  487. "path": "/resource_status/:id",
  488. "descr": "Get status of a resource"
  489. },
  490. {
  491. "name": "start_resource",
  492. "method": "POST",
  493. "path": "/resources/:id",
  494. "descr": "Start a resource"
  495. },
  496. {
  497. "name": "delete_resource",
  498. "method": "DELETE",
  499. "path": "/resources/:id",
  500. "descr": "Delete a resource"
  501. },
  502. {
  503. "name": "list_resource_types",
  504. "method": "GET",
  505. "path": "/resource_types/",
  506. "descr": "List all resource types"
  507. },
  508. {
  509. "name": "show_resource_type",
  510. "method": "GET",
  511. "path": "/resource_types/:name",
  512. "descr": "Show a resource type"
  513. },
  514. {
  515. "name": "list_resources_by_type",
  516. "method": "GET",
  517. "path": "/resource_types/:type/resources",
  518. "descr": "List all resources of a resource type"
  519. },
  520. {
  521. "name": "list_events",
  522. "method": "GET",
  523. "path": "/rule_events/",
  524. "descr": "List all events with detailed info"
  525. }
  526. ]
  527. }

集群与节点

获取集群基本信息

API 定义:

  1. GET api/v3/brokers/

请求示例:

  1. GET api/v3/brokers/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "datetime": "2019-04-29 10:56:41",
  6. "node": "emqx@127.0.0.1",
  7. "node_status": "Running",
  8. "otp_release": "R21/10.3.2",
  9. "sysdescr": "EMQ X Broker",
  10. "uptime": "3 minutes, 59 seconds",
  11. "version": "v3.1.0"
  12. }
  13. ]
  14. }

获取节点基本信息

API 定义:

  1. GET api/v3/brokers/${node}

请求示例:

  1. GET api/v3/brokers/emqx@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "data": {
  4. "datetime": "2019-04-29 10:59:59",
  5. "node_status": "Running",
  6. "otp_release": "R21/10.3.2",
  7. "sysdescr": "EMQ X Broker",
  8. "uptime": "7 minutes, 16 seconds",
  9. "version": "v3.1.0"
  10. }
  11. }

获取集群监控数据

API 定义:

  1. GET api/v3/nodes/

请求示例:

  1. GET api/v3/nodes/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "connections": 2,
  6. "load1": "2.75",
  7. "load15": "2.87",
  8. "load5": "2.57",
  9. "max_fds": 7168,
  10. "memory_total": "76.45M",
  11. "memory_used": "59.48M",
  12. "name": "emqx@127.0.0.1",
  13. "node": "emqx@127.0.0.1",
  14. "node_status": "Running",
  15. "otp_release": "R21/10.3.2",
  16. "process_available": 262144,
  17. "process_used": 331,
  18. "uptime": "1 days,18 hours, 45 minutes, 1 seconds",
  19. "version": "v3.1.0"
  20. }
  21. ]
  22. }

获取节点监控数据

API 定义:

  1. GET api/v3/nodes/${node}

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "data": {
  4. "connections": 1,
  5. "load1": "2.75",
  6. "load15": "2.87",
  7. "load5": "2.57",
  8. "max_fds": 7168,
  9. "memory_total": 80162816,
  10. "memory_used": 62254160,
  11. "name": "emqx@127.0.0.1",
  12. "node_status": "Running",
  13. "otp_release": "R21/10.3.2",
  14. "process_available": 262144,
  15. "process_used": 331,
  16. "uptime": "1 days,18 hours, 45 minutes, 1 seconds",
  17. "version": "v3.1.0"
  18. }
  19. }

连接信息(Connections)

获取集群连接信息

API 定义:

  1. GET api/v3/connections/

请求示例:

  1. GET api/v3/connections/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "clean_start": true,
  6. "client_id": "mosquitto_mqtt",
  7. "conn_mod": "emqx_connection",
  8. "connected_at": "2019-04-29 11:05:01",
  9. "heap_size": 2586,
  10. "ipaddress": "127.0.0.1",
  11. "is_bridge": false,
  12. "keepalive": 60,
  13. "mailbox_len": 0,
  14. "node": "emqx@127.0.0.1",
  15. "peercert": "nossl",
  16. "port": 64899,
  17. "proto_name": "MQIsdp",
  18. "proto_ver": 3,
  19. "recv_cnt": 2,
  20. "recv_msg": 0,
  21. "recv_oct": 47,
  22. "recv_pkt": 2,
  23. "reductions": 3588,
  24. "send_cnt": 2,
  25. "send_msg": 0,
  26. "send_oct": 9,
  27. "send_pend": 0,
  28. "send_pkt": 2,
  29. "username": "undefined",
  30. "zone": "external"
  31. }
  32. ],
  33. "meta": {
  34. "page": 1,
  35. "limit": 10000,
  36. "count": 1
  37. }
  38. }

获取节点连接信息

API 定义:

  1. GET api/v3/nodes/${node}/connections/

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/connections/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "clean_start": true,
  6. "client_id": "mosquitto_mqtt",
  7. "conn_mod": "emqx_connection",
  8. "connected_at": "2019-04-29 11:05:01",
  9. "heap_size": 610,
  10. "ipaddress": "127.0.0.1",
  11. "is_bridge": false,
  12. "keepalive": 60,
  13. "mailbox_len": 0,
  14. "node": "emqx@127.0.0.1",
  15. "peercert": "nossl",
  16. "port": 64899,
  17. "proto_name": "MQIsdp",
  18. "proto_ver": 3,
  19. "recv_cnt": 5,
  20. "recv_msg": 0,
  21. "recv_oct": 53,
  22. "recv_pkt": 5,
  23. "reductions": 6081,
  24. "send_cnt": 5,
  25. "send_msg": 0,
  26. "send_oct": 15,
  27. "send_pend": 0,
  28. "send_pkt": 5,
  29. "username": "undefined",
  30. "zone": "external"
  31. }
  32. ],
  33. "meta": {
  34. "page": 1,
  35. "limit": 10000,
  36. "count": 1
  37. }
  38. }

获取集群指定连接信息

API 定义:

  1. GET api/v3/connections/${clientid}

请求示例:

  1. GET api/v3/connections/mosquitto_mqtt

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "clean_start": true,
  6. "client_id": "mosquitto_mqtt",
  7. "conn_mod": "emqx_connection",
  8. "connected_at": "2019-04-29 11:05:01",
  9. "heap_size": 610,
  10. "ipaddress": "127.0.0.1",
  11. "is_bridge": false,
  12. "keepalive": 60,
  13. "mailbox_len": 0,
  14. "node": "emqx@127.0.0.1",
  15. "peercert": "nossl",
  16. "port": 64899,
  17. "proto_name": "MQIsdp",
  18. "proto_ver": 3,
  19. "recv_cnt": 8,
  20. "recv_msg": 0,
  21. "recv_oct": 59,
  22. "recv_pkt": 8,
  23. "reductions": 8560,
  24. "send_cnt": 8,
  25. "send_msg": 0,
  26. "send_oct": 21,
  27. "send_pend": 0,
  28. "send_pkt": 8,
  29. "username": "undefined",
  30. "zone": "external"
  31. }
  32. ]
  33. }

获取节点指定连接信息

API 定义:

  1. GET api/v3/nodes/${node}/connections/${clientid}

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/connections/mosquitto_mqtt

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "clean_start": true,
  6. "client_id": "mosquitto_mqtt",
  7. "conn_mod": "emqx_connection",
  8. "connected_at": "2019-04-29 11:05:01",
  9. "heap_size": 610,
  10. "ipaddress": "127.0.0.1",
  11. "is_bridge": false,
  12. "keepalive": 60,
  13. "mailbox_len": 0,
  14. "node": "emqx@127.0.0.1",
  15. "peercert": "nossl",
  16. "port": 64899,
  17. "proto_name": "MQIsdp",
  18. "proto_ver": 3,
  19. "recv_cnt": 14,
  20. "recv_msg": 0,
  21. "recv_oct": 71,
  22. "recv_pkt": 14,
  23. "reductions": 13534,
  24. "send_cnt": 14,
  25. "send_msg": 0,
  26. "send_oct": 33,
  27. "send_pend": 0,
  28. "send_pkt": 14,
  29. "username": "undefined",
  30. "zone": "external"
  31. }
  32. ]
  33. }

断开指定连接

API 定义:

  1. DELETE api/v3/connections/${clientid}

请求示例:

  1. DELETE api/v3/connections/mosquitto_mqtt

返回数据:

  1. {
  2. "code": 0
  3. }

会话(Sessions)

获取集群会话信息

API 定义:

  1. GET api/v3/sessions/

请求示例:

  1. GET api/v3/sessions/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "awaiting_rel_len": 0,
  6. "binding": "local",
  7. "clean_start": true,
  8. "client_id": "mqttjs_f79fbc5a4b",
  9. "created_at": "2019-04-29 11:28:04",
  10. "deliver_msg": 0,
  11. "enqueue_msg": 0,
  12. "expiry_interval": 0,
  13. "heap_size": 233,
  14. "inflight_len": 0,
  15. "mailbox_len": 0,
  16. "max_awaiting_rel": 100,
  17. "max_inflight": 32,
  18. "max_mqueue": 1000,
  19. "max_subscriptions": 0,
  20. "mqueue_dropped": 0,
  21. "mqueue_len": 0,
  22. "node": "emqx@127.0.0.1",
  23. "reductions": 211,
  24. "subscriptions_count": 0,
  25. "username": ""
  26. },
  27. {
  28. "awaiting_rel_len": 0,
  29. "binding": "local",
  30. "clean_start": true,
  31. "client_id": "mosquitto_mqtt",
  32. "created_at": "2019-04-29 11:28:28",
  33. "deliver_msg": 0,
  34. "enqueue_msg": 0,
  35. "expiry_interval": 0,
  36. "heap_size": 376,
  37. "inflight_len": 0,
  38. "mailbox_len": 0,
  39. "max_awaiting_rel": 100,
  40. "max_inflight": 32,
  41. "max_mqueue": 1000,
  42. "max_subscriptions": 0,
  43. "mqueue_dropped": 0,
  44. "mqueue_len": 0,
  45. "node": "emqx@127.0.0.1",
  46. "reductions": 202,
  47. "subscriptions_count": 0,
  48. "username": "undefined"
  49. }
  50. ],
  51. "meta": {
  52. "page": 1,
  53. "limit": 10000,
  54. "count": 2
  55. }
  56. }

获取集群指定会话信息

API 定义:

  1. GET api/v3/sessions/${clientid}

请求示例:

  1. GET api/v3/sessions/mosquitto_mqtt

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "awaiting_rel_len": 0,
  6. "binding": "local",
  7. "clean_start": true,
  8. "client_id": "mosquitto_mqtt",
  9. "created_at": "2019-04-29 11:28:28",
  10. "deliver_msg": 0,
  11. "enqueue_msg": 0,
  12. "expiry_interval": 0,
  13. "heap_size": 376,
  14. "inflight_len": 0,
  15. "mailbox_len": 0,
  16. "max_awaiting_rel": 100,
  17. "max_inflight": 32,
  18. "max_mqueue": 1000,
  19. "max_subscriptions": 0,
  20. "mqueue_dropped": 0,
  21. "mqueue_len": 0,
  22. "node": "emqx@127.0.0.1",
  23. "reductions": 453,
  24. "subscriptions_count": 1,
  25. "username": "undefined"
  26. }
  27. ]
  28. }

获取节点会话信息

API 定义:

  1. GET api/v3/nodes/${node}/sessions/

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/sessions/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "awaiting_rel_len": 0,
  6. "binding": "local",
  7. "clean_start": true,
  8. "client_id": "mqttjs_f79fbc5a4b",
  9. "created_at": "2019-04-29 11:28:04",
  10. "deliver_msg": 0,
  11. "enqueue_msg": 0,
  12. "expiry_interval": 0,
  13. "heap_size": 233,
  14. "inflight_len": 0,
  15. "mailbox_len": 0,
  16. "max_awaiting_rel": 100,
  17. "max_inflight": 32,
  18. "max_mqueue": 1000,
  19. "max_subscriptions": 0,
  20. "mqueue_dropped": 0,
  21. "mqueue_len": 0,
  22. "node": "emqx@127.0.0.1",
  23. "reductions": 211,
  24. "subscriptions_count": 0,
  25. "username": ""
  26. },
  27. {
  28. "awaiting_rel_len": 0,
  29. "binding": "local",
  30. "clean_start": true,
  31. "client_id": "mosquitto_mqtt",
  32. "created_at": "2019-04-29 11:28:28",
  33. "deliver_msg": 0,
  34. "enqueue_msg": 0,
  35. "expiry_interval": 0,
  36. "heap_size": 376,
  37. "inflight_len": 0,
  38. "mailbox_len": 0,
  39. "max_awaiting_rel": 100,
  40. "max_inflight": 32,
  41. "max_mqueue": 1000,
  42. "max_subscriptions": 0,
  43. "mqueue_dropped": 0,
  44. "mqueue_len": 0,
  45. "node": "emqx@127.0.0.1",
  46. "reductions": 453,
  47. "subscriptions_count": 1,
  48. "username": "undefined"
  49. }
  50. ],
  51. "meta": {
  52. "page": 1,
  53. "limit": 10000,
  54. "count": 2
  55. }
  56. }

获取节点指定会话信息

API 定义:

  1. GET api/v3/nodes/${node}/sessions/${clientid}

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/sessions/mosquitto_mqtt

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "payload": "hello",
  4. "qos": 1,
  5. "retain": false,
  6. "client_id": "mqttjs_ab9069449e"
  7. }

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "awaiting_rel_len": 0,
  6. "binding": "local",
  7. "clean_start": true,
  8. "client_id": "mosquitto_mqtt",
  9. "created_at": "2018-09-12 10:42:57",
  10. "deliver_msg": 0,
  11. "enqueue_msg": 0,
  12. "expiry_interval": 7200,
  13. "heap_size": 376,
  14. "inflight_len": 0,
  15. "mailbox_len": 0,
  16. "max_awaiting_rel": 100,
  17. "max_inflight": 32,
  18. "max_mqueue": 1000,
  19. "max_subscriptions": 0,
  20. "mqueue_dropped": 0,
  21. "mqueue_len": 0,
  22. "node": "emqx@127.0.0.1",
  23. "reductions": 203,
  24. "subscriptions_count": 0,
  25. "username": "mosquitto_mqtt"
  26. }
  27. ]
  28. }

订阅(Subscriptions)

获取集群订阅信息

API 定义:

  1. GET api/v3/subscriptions/

请求示例:

  1. GET api/v3/subscriptions/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "client_id": "mqttjs_f79fbc5a4b",
  6. "node": "emqx@127.0.0.1",
  7. "qos": 0,
  8. "topic": "testtopic/#"
  9. },
  10. {
  11. "client_id": "mosquitto_mqtt",
  12. "node": "emqx@127.0.0.1",
  13. "qos": 0,
  14. "topic": "t"
  15. }
  16. ],
  17. "meta": {
  18. "page": 1,
  19. "limit": 10000,
  20. "count": 2
  21. }
  22. }

获取集群指定连接订阅信息

API 定义:

  1. GET api/v3/subscriptions/${clientid}

请求示例:

  1. GET api/v3/subscriptions/mosquitto_mqtt

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "client_id": "mosquitto_mqtt",
  6. "node": "emqx@127.0.0.1",
  7. "qos": 0,
  8. "topic": "t"
  9. }
  10. ]
  11. }

获取节点订阅信息

API 定义:

  1. GET api/v3/nodes/${node}/subscriptions/

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/subscriptions/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "client_id": "mqttjs_f79fbc5a4b",
  6. "node": "emqx@127.0.0.1",
  7. "qos": 0,
  8. "topic": "testtopic/#"
  9. },
  10. {
  11. "client_id": "mosquitto_mqtt",
  12. "node": "emqx@127.0.0.1",
  13. "qos": 0,
  14. "topic": "t"
  15. }
  16. ],
  17. "meta": {
  18. "page": 1,
  19. "limit": 10000,
  20. "count": 2
  21. }
  22. }

获取节点指定连接订阅信息

API 定义:

  1. GET api/v3/nodes/${node}/subscriptions/${clientid}

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/subscriptions/mosquitto_mqtt

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "client_id": "mosquitto_mqtt",
  6. "node": "emqx@127.0.0.1",
  7. "qos": 0,
  8. "topic": "t"
  9. }
  10. ]
  11. }

路由(Routes)

获取集群路由表

API 定义:

  1. GET api/v3/routes/

请求示例:

  1. GET api/v3/routes/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "node": "emqx@127.0.0.1",
  6. "topic": "testtopic/#"
  7. },
  8. {
  9. "node": "emqx@127.0.0.1",
  10. "topic": "t"
  11. }
  12. ],
  13. "meta": {
  14. "page": 1,
  15. "limit": 10000,
  16. "count": 2
  17. }
  18. }

获取集群指定主题的路由信息

API 定义:

  1. GET api/v3/routes/${topic}

请求示例:

  1. GET api/v3/routes/t

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "node": "emqx@127.0.0.1",
  6. "topic": "t"
  7. }
  8. ]
  9. }

发布/订阅/取消订阅

发布消息

API 定义:

  1. POST api/v3/mqtt/publish

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "payload": "hello",
  4. "qos": 1,
  5. "retain": false,
  6. "client_id": "mqttjs_ab9069449e"
  7. }

请求示例:

  1. POST api/v3/mqtt/publish

返回数据:

  1. {
  2. "code": 0
  3. }

创建订阅

API 定义:

  1. POST api/v3/mqtt/subscribe

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "qos": 1,
  4. "client_id": "mqttjs_ab9069449e"
  5. }

请求示例:

  1. POST api/v3/mqtt/subscribe

返回数据:

  1. {
  2. "code": 0
  3. }

取消订阅

API 定义:

  1. POST api/v3/mqtt/unsubscribe

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "client_id": "mqttjs_ab9069449e"
  4. }

请求示例:

  1. POST api/v3/mqtt/unsubscribe

返回数据:

  1. {
  2. "code": 0
  3. }

插件(Plugins)

获取所有节点插件列表

API 定义:

  1. GET api/v3/plugins/

请求示例:

  1. GET api/v3/plugins/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "node": "emqx@127.0.0.1",
  6. "plugins": [
  7. {
  8. "name": "emqx_auth_clientid",
  9. "version": "v3.1.0",
  10. "description": "EMQ X Authentication with ClientId/Password",
  11. "active": false
  12. },
  13. {
  14. "name": "emqx_auth_http",
  15. "version": "v3.1.0",
  16. "description": "EMQ X Authentication/ACL with HTTP API",
  17. "active": false
  18. },
  19. {
  20. "name": "emqx_auth_jwt",
  21. "version": "v3.1.0",
  22. "description": "EMQ X Authentication with JWT",
  23. "active": false
  24. },
  25. {
  26. "name": "emqx_auth_ldap",
  27. "version": "v3.1.0",
  28. "description": "EMQ X Authentication/ACL with LDAP",
  29. "active": false
  30. },
  31. {
  32. "name": "emqx_auth_mongo",
  33. "version": "v3.1.0",
  34. "description": "EMQ X Authentication/ACL with MongoDB",
  35. "active": false
  36. },
  37. {
  38. "name": "emqx_auth_mysql",
  39. "version": "v3.1.0",
  40. "description": "EMQ X Authentication/ACL with MySQL",
  41. "active": false
  42. },
  43. {
  44. "name": "emqx_auth_pgsql",
  45. "version": "v3.1.0",
  46. "description": "EMQ X Authentication/ACL with PostgreSQL",
  47. "active": false
  48. },
  49. {
  50. "name": "emqx_auth_redis",
  51. "version": "v3.1.0",
  52. "description": "EMQ X Authentication/ACL with Redis",
  53. "active": false
  54. },
  55. {
  56. "name": "emqx_auth_username",
  57. "version": "v3.1.0",
  58. "description": "EMQ X Authentication with Username and Password",
  59. "active": false
  60. },
  61. {
  62. "name": "emqx_coap",
  63. "version": "v3.1.0",
  64. "description": "EMQ X CoAP Gateway",
  65. "active": false
  66. },
  67. {
  68. "name": "emqx_dashboard",
  69. "version": "v3.1.0",
  70. "description": "EMQ X Web Dashboard",
  71. "active": true
  72. },
  73. {
  74. "name": "emqx_delayed_publish",
  75. "version": "v3.1.0",
  76. "description": "EMQ X Delayed Publish",
  77. "active": false
  78. },
  79. {
  80. "name": "emqx_lua_hook",
  81. "version": "v3.1.0",
  82. "description": "EMQ X Lua Hooks",
  83. "active": false
  84. },
  85. {
  86. "name": "emqx_lwm2m",
  87. "version": "v3.1.0",
  88. "description": "EMQ X LwM2M Gateway",
  89. "active": false
  90. },
  91. {
  92. "name": "emqx_management",
  93. "version": "v3.1.0",
  94. "description": "EMQ X Management API and CLI",
  95. "active": true
  96. },
  97. {
  98. "name": "emqx_plugin_template",
  99. "version": "v3.1.0",
  100. "description": "EMQ X Plugin Template",
  101. "active": false
  102. },
  103. {
  104. "name": "emqx_psk_file",
  105. "version": "v3.1.0",
  106. "description": "EMQX PSK Plugin from File",
  107. "active": false
  108. },
  109. {
  110. "name": "emqx_recon",
  111. "version": "v3.1.0",
  112. "description": "EMQ X Recon Plugin",
  113. "active": true
  114. },
  115. {
  116. "name": "emqx_reloader",
  117. "version": "v3.1.0",
  118. "description": "EMQ X Reloader Plugin",
  119. "active": false
  120. },
  121. {
  122. "name": "emqx_retainer",
  123. "version": "v3.1.0",
  124. "description": "EMQ X Retainer",
  125. "active": true
  126. },
  127. {
  128. "name": "emqx_rule_engine",
  129. "version": "v3.1.0",
  130. "description": "EMQ X Rule Engine",
  131. "active": true
  132. },
  133. {
  134. "name": "emqx_sn",
  135. "version": "v3.1.0",
  136. "description": "EMQ X MQTT SN Plugin",
  137. "active": false
  138. },
  139. {
  140. "name": "emqx_statsd",
  141. "version": "v3.1.0",
  142. "description": "Statsd for EMQ X",
  143. "active": false
  144. },
  145. {
  146. "name": "emqx_stomp",
  147. "version": "v3.1.0",
  148. "description": "EMQ X Stomp Protocol Plugin",
  149. "active": false
  150. },
  151. {
  152. "name": "emqx_web_hook",
  153. "version": "v3.1.0",
  154. "description": "EMQ X Webhook Plugin",
  155. "active": false
  156. }
  157. ]
  158. }
  159. ]
  160. }

获取节点插件列表

API 定义:

  1. GET api/v3/nodes/${node}/plugins/

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/plugins/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "name": "emqx_auth_clientid",
  6. "version": "v3.1.0",
  7. "description": "EMQ X Authentication with ClientId/Password",
  8. "active": false
  9. },
  10. {
  11. "name": "emqx_auth_http",
  12. "version": "v3.1.0",
  13. "description": "EMQ X Authentication/ACL with HTTP API",
  14. "active": false
  15. },
  16. {
  17. "name": "emqx_auth_jwt",
  18. "version": "v3.1.0",
  19. "description": "EMQ X Authentication with JWT",
  20. "active": false
  21. },
  22. {
  23. "name": "emqx_auth_ldap",
  24. "version": "v3.1.0",
  25. "description": "EMQ X Authentication/ACL with LDAP",
  26. "active": false
  27. },
  28. {
  29. "name": "emqx_auth_mongo",
  30. "version": "v3.1.0",
  31. "description": "EMQ X Authentication/ACL with MongoDB",
  32. "active": false
  33. },
  34. {
  35. "name": "emqx_auth_mysql",
  36. "version": "v3.1.0",
  37. "description": "EMQ X Authentication/ACL with MySQL",
  38. "active": false
  39. },
  40. {
  41. "name": "emqx_auth_pgsql",
  42. "version": "v3.1.0",
  43. "description": "EMQ X Authentication/ACL with PostgreSQL",
  44. "active": false
  45. },
  46. {
  47. "name": "emqx_auth_redis",
  48. "version": "v3.1.0",
  49. "description": "EMQ X Authentication/ACL with Redis",
  50. "active": false
  51. },
  52. {
  53. "name": "emqx_auth_username",
  54. "version": "v3.1.0",
  55. "description": "EMQ X Authentication with Username and Password",
  56. "active": false
  57. },
  58. {
  59. "name": "emqx_coap",
  60. "version": "v3.1.0",
  61. "description": "EMQ X CoAP Gateway",
  62. "active": false
  63. },
  64. {
  65. "name": "emqx_dashboard",
  66. "version": "v3.1.0",
  67. "description": "EMQ X Web Dashboard",
  68. "active": true
  69. },
  70. {
  71. "name": "emqx_delayed_publish",
  72. "version": "v3.1.0",
  73. "description": "EMQ X Delayed Publish",
  74. "active": false
  75. },
  76. {
  77. "name": "emqx_lua_hook",
  78. "version": "v3.1.0",
  79. "description": "EMQ X Lua Hooks",
  80. "active": false
  81. },
  82. {
  83. "name": "emqx_lwm2m",
  84. "version": "v3.1.0",
  85. "description": "EMQ X LwM2M Gateway",
  86. "active": false
  87. },
  88. {
  89. "name": "emqx_management",
  90. "version": "v3.1.0",
  91. "description": "EMQ X Management API and CLI",
  92. "active": true
  93. },
  94. {
  95. "name": "emqx_plugin_template",
  96. "version": "v3.1.0",
  97. "description": "EMQ X Plugin Template",
  98. "active": false
  99. },
  100. {
  101. "name": "emqx_psk_file",
  102. "version": "v3.1.0",
  103. "description": "EMQX PSK Plugin from File",
  104. "active": false
  105. },
  106. {
  107. "name": "emqx_recon",
  108. "version": "v3.1.0",
  109. "description": "EMQ X Recon Plugin",
  110. "active": true
  111. },
  112. {
  113. "name": "emqx_reloader",
  114. "version": "v3.1.0",
  115. "description": "EMQ X Reloader Plugin",
  116. "active": false
  117. },
  118. {
  119. "name": "emqx_retainer",
  120. "version": "v3.1.0",
  121. "description": "EMQ X Retainer",
  122. "active": true
  123. },
  124. {
  125. "name": "emqx_rule_engine",
  126. "version": "v3.1.0",
  127. "description": "EMQ X Rule Engine",
  128. "active": true
  129. },
  130. {
  131. "name": "emqx_sn",
  132. "version": "v3.1.0",
  133. "description": "EMQ X MQTT SN Plugin",
  134. "active": false
  135. },
  136. {
  137. "name": "emqx_statsd",
  138. "version": "v3.1.0",
  139. "description": "Statsd for EMQ X",
  140. "active": false
  141. },
  142. {
  143. "name": "emqx_stomp",
  144. "version": "v3.1.0",
  145. "description": "EMQ X Stomp Protocol Plugin",
  146. "active": false
  147. },
  148. {
  149. "name": "emqx_web_hook",
  150. "version": "v3.1.0",
  151. "description": "EMQ X Webhook Plugin",
  152. "active": false
  153. }
  154. ]
  155. }

启用节点指定插件

API 定义:

  1. PUT api/v3/nodes/${node}/plugins/${plugin}/load

请求示例:

  1. PUT api/v3/nodes/emqx@127.0.0.1/plugins/emqx_auth_clientid/load

返回数据:

  1. {
  2. "code": 0
  3. }

关闭节点指定插件

API 定义:

  1. PUT api/v3/nodes/${node}/plugins/${plugin}/unload

请求示例:

  1. PUT api/v3/nodes/emqx@127.0.0.1/plugins/emqx_auth_clientid/unload

返回数据:

  1. {
  2. "code": 0
  3. }

监听器(Listeners)

获取集群监听器列表

API 定义:

  1. GET api/v3/listeners/

请求示例:

  1. GET api/v3/listeners/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "listeners": [
  6. {
  7. "acceptors": 16,
  8. "current_conns": 0,
  9. "listen_on": "8883",
  10. "max_conns": 102400,
  11. "protocol": "mqtt:ssl",
  12. "shutdown_count": [ ]
  13. },
  14. {
  15. "acceptors": 8,
  16. "current_conns": 2,
  17. "listen_on": "0.0.0.0:1883",
  18. "max_conns": 1024000,
  19. "protocol": "mqtt:tcp",
  20. "shutdown_count": {
  21. "closed": 2,
  22. "kicked": 1
  23. }
  24. },
  25. {
  26. "acceptors": 4,
  27. "current_conns": 0,
  28. "listen_on": "127.0.0.1:11883",
  29. "max_conns": 10240000,
  30. "protocol": "mqtt:tcp",
  31. "shutdown_count": [ ]
  32. },
  33. {
  34. "acceptors": 4,
  35. "current_conns": 1,
  36. "listen_on": "18083",
  37. "max_conns": 512,
  38. "protocol": "http:dashboard",
  39. "shutdown_count": [ ]
  40. },
  41. {
  42. "acceptors": 2,
  43. "current_conns": 0,
  44. "listen_on": "8080",
  45. "max_conns": 512,
  46. "protocol": "http:management",
  47. "shutdown_count": [ ]
  48. },
  49. {
  50. "acceptors": 4,
  51. "current_conns": 0,
  52. "listen_on": "8083",
  53. "max_conns": 102400,
  54. "protocol": "mqtt:ws",
  55. "shutdown_count": [ ]
  56. },
  57. {
  58. "acceptors": 4,
  59. "current_conns": 0,
  60. "listen_on": "8084",
  61. "max_conns": 16,
  62. "protocol": "mqtt:wss",
  63. "shutdown_count": [ ]
  64. }
  65. ],
  66. "node": "emqx@127.0.0.1"
  67. }
  68. ]
  69. }

获取节点监听器列表

API 定义:

  1. GET api/v3/nodes/${node}/listeners

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/listeners

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "acceptors": 16,
  6. "current_conns": 0,
  7. "listen_on": "8883",
  8. "max_conns": 102400,
  9. "protocol": "mqtt:ssl",
  10. "shutdown_count": [ ]
  11. },
  12. {
  13. "acceptors": 8,
  14. "current_conns": 2,
  15. "listen_on": "0.0.0.0:1883",
  16. "max_conns": 1024000,
  17. "protocol": "mqtt:tcp",
  18. "shutdown_count": {
  19. "closed": 2,
  20. "kicked": 1
  21. }
  22. },
  23. {
  24. "acceptors": 4,
  25. "current_conns": 0,
  26. "listen_on": "127.0.0.1:11883",
  27. "max_conns": 10240000,
  28. "protocol": "mqtt:tcp",
  29. "shutdown_count": [ ]
  30. },
  31. {
  32. "acceptors": 4,
  33. "current_conns": 1,
  34. "listen_on": "18083",
  35. "max_conns": 512,
  36. "protocol": "http:dashboard",
  37. "shutdown_count": [ ]
  38. },
  39. {
  40. "acceptors": 2,
  41. "current_conns": 0,
  42. "listen_on": "8080",
  43. "max_conns": 512,
  44. "protocol": "http:management",
  45. "shutdown_count": [ ]
  46. },
  47. {
  48. "acceptors": 4,
  49. "current_conns": 0,
  50. "listen_on": "8083",
  51. "max_conns": 102400,
  52. "protocol": "mqtt:ws",
  53. "shutdown_count": [ ]
  54. },
  55. {
  56. "acceptors": 4,
  57. "current_conns": 0,
  58. "listen_on": "8084",
  59. "max_conns": 16,
  60. "protocol": "mqtt:wss",
  61. "shutdown_count": [ ]
  62. }
  63. ]
  64. }

收发报文统计

获取集群收发报文统计

API 定义:

  1. GET api/v3/metrics/

请求示例:

  1. GET api/v3/metrics/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "node": "emqx@127.0.0.1",
  6. "metrics": {
  7. "bytes/received": 342,
  8. "packets/pubrel/sent": 0,
  9. "packets/pubcomp/missed": 0,
  10. "packets/sent": 13,
  11. "packets/pubrel/received": 0,
  12. "messages/qos1/received": 0,
  13. "packets/publish/received": 2,
  14. "packets/auth": 0,
  15. "messages/qos0/received": 2,
  16. "packets/pubcomp/received": 0,
  17. "packets/unsuback": 0,
  18. "packets/pubrec/missed": 0,
  19. "messages/qos1/sent": 0,
  20. "messages/qos2/sent": 0,
  21. "bytes/sent": 116,
  22. "messages/received": 2,
  23. "messages/dropped": 1,
  24. "messages/qos2/received": 0,
  25. "packets/connect": 5,
  26. "messages/qos0/sent": 4,
  27. "packets/disconnect/received": 0,
  28. "packets/pubrec/sent": 0,
  29. "packets/publish/sent": 4,
  30. "packets/pubrec/received": 0,
  31. "packets/received": 11,
  32. "packets/unsubscribe": 0,
  33. "packets/subscribe": 4,
  34. "packets/disconnect/sent": 0,
  35. "packets/pingresp": 0,
  36. "messages/qos2/dropped": 0,
  37. "packets/puback/missed": 0,
  38. "packets/pingreq": 0,
  39. "packets/connack": 5,
  40. "packets/pubrel/missed": 0,
  41. "messages/sent": 4,
  42. "packets/suback": 4,
  43. "messages/retained": 3,
  44. "packets/puback/sent": 0,
  45. "packets/puback/received": 0,
  46. "messages/qos2/expired": 0,
  47. "messages/forward": 0,
  48. "messages/expired": 0,
  49. "packets/pubcomp/sent": 0
  50. }
  51. }
  52. ]
  53. }

获取节点收发报文统计

API 定义:

  1. GET api/v3/nodes/${node}/metrics/

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/metrics/

返回数据:

  1. {
  2. "code": 0,
  3. "data": {
  4. "bytes/received": 342,
  5. "packets/pubrel/sent": 0,
  6. "packets/pubcomp/missed": 0,
  7. "packets/sent": 13,
  8. "packets/pubrel/received": 0,
  9. "messages/qos1/received": 0,
  10. "packets/publish/received": 2,
  11. "packets/auth": 0,
  12. "messages/qos0/received": 2,
  13. "packets/pubcomp/received": 0,
  14. "packets/unsuback": 0,
  15. "packets/pubrec/missed": 0,
  16. "messages/qos1/sent": 0,
  17. "messages/qos2/sent": 0,
  18. "bytes/sent": 116,
  19. "messages/received": 2,
  20. "messages/dropped": 1,
  21. "messages/qos2/received": 0,
  22. "packets/connect": 5,
  23. "messages/qos0/sent": 4,
  24. "packets/disconnect/received": 0,
  25. "packets/pubrec/sent": 0,
  26. "packets/publish/sent": 4,
  27. "packets/pubrec/received": 0,
  28. "packets/received": 11,
  29. "packets/unsubscribe": 0,
  30. "packets/subscribe": 4,
  31. "packets/disconnect/sent": 0,
  32. "packets/pingresp": 0,
  33. "messages/qos2/dropped": 0,
  34. "packets/puback/missed": 0,
  35. "packets/pingreq": 0,
  36. "packets/connack": 5,
  37. "packets/pubrel/missed": 0,
  38. "messages/sent": 4,
  39. "packets/suback": 4,
  40. "messages/retained": 3,
  41. "packets/puback/sent": 0,
  42. "packets/puback/received": 0,
  43. "messages/qos2/expired": 0,
  44. "messages/forward": 0,
  45. "messages/expired": 0,
  46. "packets/pubcomp/sent": 0
  47. }
  48. }

连接会话统计

获取集群连接会话统计

API 定义:

  1. GET api/v3/stats/

请求示例:

  1. GET api/v3/stats/

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "node": "emqx@127.0.0.1",
  6. "subscriptions/shared/max": 0,
  7. "subscriptions/max": 2,
  8. "subscribers/max": 2,
  9. "topics/count": 0,
  10. "subscriptions/count": 0,
  11. "topics/max": 1,
  12. "sessions/persistent/max": 2,
  13. "connections/max": 2,
  14. "subscriptions/shared/count": 0,
  15. "sessions/persistent/count": 0,
  16. "retained/count": 3,
  17. "routes/count": 0,
  18. "sessions/count": 0,
  19. "retained/max": 3,
  20. "sessions/max": 2,
  21. "routes/max": 1,
  22. "subscribers/count": 0,
  23. "connections/count": 0
  24. }
  25. ]
  26. }

获取节点连接会话统计

API 定义:

  1. GET api/v3/nodes/${node}/stats/

请求示例:

  1. GET api/v3/nodes/emqx@127.0.0.1/stats/

返回数据:

  1. {
  2. "code": 0,
  3. "data": {
  4. "subscriptions/shared/max": 0,
  5. "subscriptions/max": 2,
  6. "subscribers/max": 2,
  7. "topics/count": 0,
  8. "subscriptions/count": 0,
  9. "topics/max": 1,
  10. "sessions/persistent/max": 2,
  11. "connections/max": 2,
  12. "subscriptions/shared/count": 0,
  13. "sessions/persistent/count": 0,
  14. "retained/count": 3,
  15. "routes/count": 0,
  16. "sessions/count": 0,
  17. "retained/max": 3,
  18. "sessions/max": 2,
  19. "routes/max": 1,
  20. "subscribers/count": 0,
  21. "connections/count": 0
  22. }
  23. }

告警信息

获取集群当前告警信息

API 定义:

  1. GET api/v3/alarms/present

请求示例:

  1. GET api/v3/alarms/present

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "alarms": [],
  6. "node": "emqx@127.0.0.1"
  7. }
  8. ]
  9. }

获取节点当前告警信息

API 定义:

  1. GET api/v3/alarms/present/${node}

请求示例:

  1. GET api/v3/alarms/present/emqx@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "data": []
  4. }

获取集群历史告警信息

API 定义:

  1. GET api/v3/alarms/history

请求示例:

  1. GET api/v3/alarms/history

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "alarms": [
  6. {
  7. "clear_at": "2019-07-10 16:54:35",
  8. "desc": "82.60344181007542",
  9. "id": "cpu_high_watermark"
  10. }
  11. ],
  12. "node": "emqx@127.0.0.1"
  13. }
  14. ]
  15. }

获取节点历史告警信息

API 定义:

  1. GET api/v3/alarms/present/${node}

请求示例:

  1. GET api/v3/alarms/present/emqx@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "clear_at": "2019-07-10 16:54:35",
  6. "desc": "82.60344181007542",
  7. "id": "cpu_high_watermark"
  8. }
  9. ]
  10. }

黑名单

获取黑名单列表

API 定义:

  1. GET api/v3/banned/

请求示例:

  1. GET api/v3/banned/?_page=1&_limit=10000

返回数据:

  1. {
  2. "code": 0,
  3. "data": [],
  4. "meta": {
  5. "count": 0,
  6. "limit": 10000,
  7. "page": 1
  8. }
  9. }

创建黑名单

API 定义:

  1. POST api/v3/banned/

请求参数:

  1. {
  2. "who": "mqttjs_ab9069449e",
  3. "as": "client_id",
  4. "reason": "banned the clientId",
  5. "desc": "normal banned",
  6. "until": 1536146187
  7. }

请求示例:

  1. POST api/v3/banned/

返回数据:

  1. {
  2. "code": 0,
  3. "data": {
  4. "who": "mqttjs_ab9069449e",
  5. "as": "client_id",
  6. "reason": "banned the clientId",
  7. "desc": "normal banned",
  8. "until": 1536146187
  9. }
  10. }

删除指定黑名单

API 定义:

  1. DELETE api/v3/banned/${who}?as=${as}

请求示例:

  1. DELETE api/v3/banned/mqttjs_ab9069449e?as=client_id

返回数据:

  1. {
  2. "code": 0
  3. }

错误信息与数据分页

HTTP 状态码大于 500 时响应携带错误信息返回

错误示例:

  1. PUT api/v3/nodes/emqx@127.0.0.1/plugins/emqx_recon/load

返回数据:

  1. {
  2. "code": 102,
  3. "message": "already_started"
  4. }

分页参数与分页信息

请求示例中使用了 ?_page=1&_limit=10000 参数的接口均支持分页:

  1. _page: 当前页码
  2. _limit: 分页大小

返回数据:

  1. {
  2. "code": 0,
  3. "data": [],
  4. "meta": {
  5. "page": 1,
  6. "limit": 10000,
  7. "count": 0
  8. }
  9. }

规则引擎(rule engine)

创建规则

API 定义:

  1. POST api/v3/rules

参数定义:

name

String,规则名字

for

String,Hook 的名字,可以为: “message.publish”,”client.connected” … 详见 扩展插件 (Plugins)

rawsql

String,用于筛选和转换原始数据的 SQL 语句

actions

JSON Array,动作列表

name

String, 动作名字

params

JSON Object, 动作参数

description

String,可选,规则描述

请求参数示例:

  1. {
  2. "name": "test-rule",
  3. "for": "message.publish",
  4. "rawsql": "select * from \"t/a\"",
  5. "actions": [{
  6. "name": "built_in:inspect_action",
  7. "params": {
  8. "a": 1
  9. }
  10. }],
  11. "description": "test-rule"
  12. }

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "actions": [{
  5. "name": "built_in:inspect_action",
  6. "params": {
  7. "$resource": "built_in:test-resource",
  8. "a": 1
  9. }
  10. }],
  11. "description": "test-rule",
  12. "enabled": true,
  13. "for": "message.publish",
  14. "id": "test-rule:1556263150688255821",
  15. "name": "test-rule",
  16. "rawsql": "select * from \"t/a\""
  17. }
  18. }

查询规则

API 定义:

  1. GET api/v3/rules/${rule_id}

请求参数示例:

  1. GET api/v3/rules/test-rule:1556263150688255821

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "actions": [{
  5. "name": "built_in:inspect_action",
  6. "params": {
  7. "$resource": "built_in:test-resource",
  8. "a": 1
  9. }
  10. }],
  11. "description": "test-rule",
  12. "enabled": true,
  13. "for": "message.publish",
  14. "id": "test-rule:1556263150688255821",
  15. "name": "test-rule",
  16. "rawsql": "select * from \"t/a\""
  17. }
  18. }

获取当前规则列表

API 定义:

  1. GET api/v3/rules

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "actions": [{
  5. "name": "built_in:inspect_action",
  6. "params": {
  7. "$resource": "built_in:test-resource",
  8. "a": 1
  9. }
  10. }],
  11. "description": "test-rule",
  12. "enabled": true,
  13. "for": "message.publish",
  14. "id": "test-rule:1556263150688255821",
  15. "name": "test-rule",
  16. "rawsql": "select * from \"t/a\""
  17. }]
  18. }

删除规则

API 定义:

  1. DELETE api/v3/rules/${rule_id}

请求参数示例:

  1. DELETE api/v3/rules/test-rule:1556263150688255821

返回数据示例:

  1. {
  2. "code": 0
  3. }

获取当前动作列表

API 定义:

  1. GET api/v3/actions?for=${hook_type}

请求参示例:

  1. GET api/v3/actions

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "app": "emqx_rule_engine",
  5. "description": "Republish a MQTT message to a another topic",
  6. "for": "message.publish",
  7. "name": "built_in:republish_action",
  8. "params": {
  9. "target_topic": {
  10. "description": "Repubilsh the message to which topic",
  11. "format": "topic",
  12. "required": true,
  13. "title": "To Which Topic",
  14. "type": "string"
  15. }
  16. },
  17. "type": "built_in"
  18. }, {
  19. "app": "emqx_web_hook",
  20. "description": "Forward Events to Web Server",
  21. "for": "$events",
  22. "name": "web_hook:event_action",
  23. "params": {
  24. "$resource": {
  25. "description": "Bind a resource to this action",
  26. "required": true,
  27. "title": "Resource ID",
  28. "type": "string"
  29. },
  30. "template": {
  31. "description": "The payload template to be filled with variables before sending messages",
  32. "required": false,
  33. "schema": {},
  34. "title": "Payload Template",
  35. "type": "object"
  36. }
  37. },
  38. "type": "web_hook"
  39. }, {
  40. "app": "emqx_web_hook",
  41. "description": "Forward Messages to Web Server",
  42. "for": "message.publish",
  43. "name": "web_hook:publish_action",
  44. "params": {
  45. "$resource": {
  46. "description": "Bind a resource to this action",
  47. "required": true,
  48. "title": "Resource ID",
  49. "type": "string"
  50. }
  51. },
  52. "type": "web_hook"
  53. }, {
  54. "app": "emqx_rule_engine",
  55. "description": "Inspect the details of action params for debug purpose",
  56. "for": "$any",
  57. "name": "built_in:inspect_action",
  58. "params": {},
  59. "type": "built_in"
  60. }]
  61. }

请求参数示例:

  1. GET api/v3/actions?for=client.connected

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "app": "emqx_rule_engine",
  5. "description": "Inspect the details of action params for debug purpose",
  6. "for": "$any",
  7. "name": "built_in:inspect_action",
  8. "params": {},
  9. "type": "built_in"
  10. }]
  11. }

查询动作

API 定义:

  1. GET api/v3/actions/:action_name

请求参数示例:

  1. GET api/v3/actions/built_in:inspect_action

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "app": "emqx_rule_engine",
  5. "description": "Inspect the details of action params for debug purpose",
  6. "for": "$any",
  7. "name": "built_in:inspect_action",
  8. "params": {},
  9. "type": "built_in"
  10. }
  11. }

获取当前资源类型列表

API 定义:

  1. GET api/v3/resource_types

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "attrs": "undefined",
  5. "config": {
  6. "url": "http://host-name/chats"
  7. },
  8. "description": "forward msgs to host-name/chats",
  9. "id": "web_hook:webhook1",
  10. "name": "webhook1",
  11. "type": "web_hook"
  12. }, {
  13. "attrs": "undefined",
  14. "config": {
  15. "a": 1
  16. },
  17. "description": "test-resource",
  18. "id": "built_in:test-resource",
  19. "name": "test-resource",
  20. "type": "built_in"
  21. }]
  22. }

查询资源类型

API 定义:

  1. GET api/v3/resource_types/${type}

请求参数示例:

  1. GET api/v3/resource_types/built_in

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "description": "The built in resource type for debug purpose",
  5. "name": "built_in",
  6. "params": {},
  7. "provider": "emqx_rule_engine"
  8. }
  9. }

获取某种类型的资源

API 定义:

  1. GET api/v3/resource_types/${type}/resources

请求参数示例:

  1. GET api/v3/resource_types/built_in/resources

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "attrs": "undefined",
  5. "config": {
  6. "a": 1
  7. },
  8. "description": "test-resource",
  9. "id": "built_in:test-resource",
  10. "name": "test-resource",
  11. "type": "built_in"
  12. }]
  13. }

获取某种类型的动作

API 定义:

  1. GET api/v3/resource_types/${type}/actions

请求参数示例:

  1. GET api/v3/resource_types/built_in/actions

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "app": "emqx_rule_engine",
  5. "description": "Inspect the details of action params for debug purpose",
  6. "for": "$any",
  7. "name": "built_in:inspect_action",
  8. "params": {},
  9. "type": "built_in"
  10. }, {
  11. "app": "emqx_rule_engine",
  12. "description": "Republish a MQTT message to a another topic",
  13. "for": "message.publish",
  14. "name": "built_in:republish_action",
  15. "params": {
  16. "target_topic": {
  17. "description": "Repubilsh the message to which topic",
  18. "format": "topic",
  19. "required": true,
  20. "title": "To Which Topic",
  21. "type": "string"
  22. }
  23. },
  24. "type": "built_in"
  25. }]
  26. }

创建资源

API 定义:

  1. POST api/v3/resources

参数定义:

name

String, 资源名字

type

String, 资源类型

config

JSON Object, 资源配置

description

String,可选,规则描述

参数示例:

  1. {
  2. "name": "test-resource",
  3. "type": "built_in",
  4. "config": {
  5. "a": 1
  6. },
  7. "description": "test-resource"
  8. }

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "attrs": "undefined",
  5. "config": {
  6. "a": 1
  7. },
  8. "description": "test-resource",
  9. "id": "built_in:test-resource",
  10. "name": "test-resource",
  11. "type": "built_in"
  12. }
  13. }

获取资源列表

API 定义:

  1. GET api/v3/resources

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "attrs": "undefined",
  5. "config": {
  6. "url": "http://host-name/chats"
  7. },
  8. "description": "forward msgs to host-name/chats",
  9. "id": "web_hook:webhook1",
  10. "name": "webhook1",
  11. "type": "web_hook"
  12. }, {
  13. "attrs": "undefined",
  14. "config": {
  15. "a": 1
  16. },
  17. "description": "test-resource",
  18. "id": "built_in:test-resource",
  19. "name": "test-resource",
  20. "type": "built_in"
  21. }]
  22. }

查询资源

API 定义:

  1. GET api/v3/resources/:resource_id

请求参数示例:

  1. GET api/v3/resources/built_in:test-resource

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "attrs": "undefined",
  5. "config": {
  6. "a": 1
  7. },
  8. "description": "test-resource",
  9. "id": "built_in:test-resource",
  10. "name": "test-resource",
  11. "type": "built_in"
  12. }
  13. }

删除资源

API 定义:

  1. DELETE api/v3/resources/:resource_id

请求参数示例:

  1. DELETE api/v3/resources/built_in:test-resource

返回数据示例:

  1. {
  2. "code": 0
  3. }