管理监控API (REST API)

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

URL 地址

REST API 访问 URL 地址:

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

Basic 认证

REST API 采用 HTTP Basic 认证(Authentication):

  1. curl -v --basic -u <user>:<passwd> -k http://localhost:8080/api/v2/nodes/emq@127.0.0.1/clients

集群与节点

获取全部节点的基本信息

API 定义:

  1. GET api/v2/management/nodes

请求示例:

  1. GET api/v2/management/nodes

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "name": "emq@127.0.0.1",
  6. "version": "2.3.10",
  7. "sysdescr": "Erlang MQTT Broker",
  8. "uptime": "3 minutes, 32 seconds",
  9. "datetime": "2018-06-29 09:03:52",
  10. "otp_release": "R20/9.3.3",
  11. "node_status": "Running"
  12. }
  13. ]
  14. }

获取指定节点的基本信息

API 定义:

  1. GET api/v2/management/nodes/{node_name}

请求示例:

  1. GET api/v2/management/nodes/emq@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "version": "2.3.10",
  5. "sysdescr": "Erlang MQTT Broker",
  6. "uptime": "5 minutes, 12 seconds",
  7. "datetime": "2018-06-29 09:05:32",
  8. "otp_release": "R20/9.3.3",
  9. "node_status": "Running"
  10. }
  11. }

获取全部节点的监控数据

API 定义:

  1. GET api/v2/monitoring/nodes

请求示例:

  1. GET api/v2/monitoring/nodes

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "name": "emq@127.0.0.1",
  6. "otp_release": "R20/9.3.3",
  7. "memory_total": "72.94M",
  8. "memory_used": "50.55M",
  9. "process_available": 262144,
  10. "process_used": 324,
  11. "max_fds": 7168,
  12. "clients": 0,
  13. "node_status": "Running",
  14. "load1": "1.65",
  15. "load5": "1.93",
  16. "load15": "2.01"
  17. }
  18. ]
  19. }

获取指定节点的监控数据

API 定义:

  1. GET api/v2/monitoring/nodes/{node_name}

请求示例:

  1. GET api/v2/monitoring/nodes/emq@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "name": "emq@127.0.0.1",
  5. "otp_release": "R20/9.3.3",
  6. "memory_total": "73.69M",
  7. "memory_used": "50.12M",
  8. "process_available": 262144,
  9. "process_used": 324,
  10. "max_fds": 7168,
  11. "clients": 0,
  12. "node_status": "Running",
  13. "load1": "1.88",
  14. "load5": "1.99",
  15. "load15": "2.02"
  16. }
  17. }

客户端连接(Clients)

获取指定节点的客户端连接列表

API 定义:

  1. GET api/v2/nodes/{node_name}/clients

请求参数:

  1. curr_page={page_no}&page_size={page_size}

请求示例:

  1. api/v2/nodes/emq@127.0.0.1/clients?curr_page=1&page_size=20

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "current_page": 1,
  5. "page_size": 20,
  6. "total_num": 1,
  7. "total_page": 1,
  8. "objects": [
  9. {
  10. "client_id": "mqttjs_722b4d845f",
  11. "username": "undefined",
  12. "ipaddress": "127.0.0.1",
  13. "port": 58459,
  14. "clean_sess": true,
  15. "proto_ver": 4,
  16. "keepalive": 60,
  17. "connected_at": "2018-06-29 09:15:25"
  18. }
  19. ]
  20. }
  21. }

获取节点指定客户端连接的信息

API 定义:

  1. GET api/v2/nodes/{node_name}/clients/{clientid}

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/clients/mqttjs_722b4d845f

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "objects": [
  5. {
  6. "client_id": "mqttjs_722b4d845f",
  7. "username": "undefined",
  8. "ipaddress": "127.0.0.1",
  9. "port": 58459,
  10. "clean_sess": true,
  11. "proto_ver": 4,
  12. "keepalive": 60,
  13. "connected_at": "2018-06-29 09:15:25"
  14. }
  15. ]
  16. }
  17. }

获取集群内指定客户端的信息

API 定义:

  1. GET api/v2/clients/{clientid}

请求示例:

  1. GET api/v2/clients/mqttjs_722b4d845f

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "objects": [
  5. {
  6. "client_id": "mqttjs_722b4d845f",
  7. "username": "undefined",
  8. "ipaddress": "127.0.0.1",
  9. "port": 58459,
  10. "clean_sess": true,
  11. "proto_ver": 4,
  12. "keepalive": 60,
  13. "connected_at": "2018-06-29 09:15:25"
  14. }
  15. ]
  16. }
  17. }

断开集群内指定客户端连接

API定义:

  1. DELETE api/v2/clients/{clientid}

请求示例:

  1. DELETE api/v2/clients/mqttjs_722b4d845f

返回数据:

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

清除集群内指定客户端的ACL缓存

API定义:

  1. PUT api/v2/clients/{clientid}/clean_acl_cache

请求参数:

  1. {
  2. "topic": "test"
  3. }

请求示例:

  1. PUT api/v2/clients/mqttjs_722b4d845f/clean_acl_cache
  2. 请求的 json 参数:
  3. {
  4. "topic": "test"
  5. }

返回数据:

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

会话(Sessions)

获取指定节点的会话列表

API 定义:

  1. GET api/v2/nodes/{node_name}/sessions

请求参数:

  1. curr_page={page_no}&page_size={page_size}

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/sessions?curr_page=1&page_size=20

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "current_page": 1,
  5. "page_size": 20,
  6. "total_num": 1,
  7. "total_page": 1,
  8. "objects": [
  9. {
  10. "client_id": "mqttjs_722b4d845f",
  11. "clean_sess": true,
  12. "subscriptions": 0,
  13. "max_inflight": 32,
  14. "inflight_len": 0,
  15. "mqueue_len": 0,
  16. "mqueue_dropped": 0,
  17. "awaiting_rel_len": 0,
  18. "deliver_msg": 0,
  19. "enqueue_msg": 0,
  20. "created_at": "2018-06-29 10:05:13"
  21. }
  22. ]
  23. }
  24. }

获取节点上指定客户端的会话信息

API 定义:

  1. GET api/v2/nodes/{node_name}/sessions/{clientid}

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/sessions/mqttjs_722b4d845f

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "objects": [
  5. {
  6. "client_id": "mqttjs_722b4d845f",
  7. "clean_sess": true,
  8. "subscriptions": 0,
  9. "max_inflight": 32,
  10. "inflight_len": 0,
  11. "mqueue_len": 0,
  12. "mqueue_dropped": 0,
  13. "awaiting_rel_len": 0,
  14. "deliver_msg": 0,
  15. "enqueue_msg": 0,
  16. "created_at": "2018-06-29 10:05:13"
  17. }
  18. ]
  19. }
  20. }

获取集群内指定客户端的会话信息

API 定义:

  1. GET api/v2/sessions/{clientid}

请求示例:

  1. GET api/v2/sessions/mqttjs_722b4d845f

返回数据:

订阅(Subscriptions)

获取某个节点上的订阅列表

API 定义:

  1. GET api/v2/nodes/{node_name}/subscriptions

请求参数:

  1. curr_page={page_no}&page_size={page_size}

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/subscriptions?curr_page=1&page_size=20

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "current_page": 1,
  5. "page_size": 20,
  6. "total_num": 1,
  7. "total_page": 1,
  8. "objects": [
  9. {
  10. "client_id": "mqttjs_722b4d845f",
  11. "topic": "/World",
  12. "qos": 0
  13. }
  14. ]
  15. }
  16. }

获取节点上指定客户端的订阅信息

API 定义:

  1. GET api/v2/nodes/{node_name}/subscriptions/{clientid}

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/subscriptions/mqttjs_722b4d845f

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "objects": [
  5. {
  6. "client_id": "mqttjs_722b4d845f",
  7. "topic": "/World",
  8. "qos": 0
  9. }
  10. ]
  11. }
  12. }

获取集群内指定客户端的订阅信息

API 定义:

  1. GET api/v2/subscriptions/{clientid}

请求示例:

  1. GET api/v2/subscriptions/mqttjs_722b4d845f

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "objects": [
  5. {
  6. "client_id": "mqttjs_722b4d845f",
  7. "topic": "/World",
  8. "qos": 0
  9. }
  10. ]
  11. }
  12. }

路由(Routes)

获取集群路由表

API 定义:

  1. GET api/v2/routes

请求参数:

  1. curr_page={page_no}&page_size={page_size}

请求示例:

  1. GET api/v2/routes?curr_page=1&page_size=20

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "current_page": 1,
  5. "page_size": 20,
  6. "total_num": 1,
  7. "total_page": 1,
  8. "objects": [
  9. {
  10. "topic": "/World",
  11. "node": "emq@127.0.0.1"
  12. }
  13. ]
  14. }
  15. }

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

API 定义:

  1. GET api/v2/routes/{topic}

请求示例:

  1. GET api/v2/routes//World

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "objects": [
  5. {
  6. "topic": "/World",
  7. "node": "emq@127.0.0.1"
  8. }
  9. ]
  10. }
  11. }

发布/订阅

发布消息

API 定义:

  1. POST api/v2/mqtt/publish

请求参数:

  1. {
  2. "topic" : "/World",
  3. "payload": "hello",
  4. "qos": 0,
  5. "retain" : false,
  6. "client_id": "mqttjs_722b4d845f"
  7. }

注解

topic 参数必填,其他参数可选。payload 默认值空字符串,qos 默认为 0,retain 默认为 false,client_id 默认为 ‘http’。

请求示例:

  1. POST api/v2/mqtt/publish
  2. 请求参数 json:
  3. {
  4. "topic" : "/World",
  5. "payload": "hello",
  6. "qos": 0,
  7. "retain" : false,
  8. "client_id": "mqttjs_722b4d845f"
  9. }

返回数据:

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

创建订阅

API 定义:

  1. POST api/v2/mqtt/subscribe

请求参数:

  1. {
  2. "topic" : "/World",
  3. "qos" : 0,
  4. "client_id": "mqttjs_722b4d845f"
  5. }

请求示例:

  1. POST api/v2/mqtt/subscribe
  2. 请求参数 json:
  3. {
  4. "topic" : "/World",
  5. "qos": 0,
  6. "client_id": "mqttjs_722b4d845f"
  7. }

返回数据:

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

取消订阅

API 定义:

  1. POST api/v2/mqtt/unsubscribe

请求参数:

  1. {
  2. "topic" : "/World",
  3. "client_id": "mqttjs_722b4d845f"
  4. }

请求示例:

  1. POST api/v2/mqtt/unsubscribe
  2. 请求参数 json:
  3. {
  4. "topic" : "/World",
  5. "client_id": "mqttjs_722b4d845f"
  6. }

返回数据:

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

插件(Plugins)

获取节点的插件列表

API 定义:

  1. GET api/v2/nodes/{node_name}/plugins

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/plugins

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "name": "emq_auth_clientid",
  6. "version": "2.3.10",
  7. "description": "Authentication with ClientId/Password",
  8. "active": false
  9. },
  10. {
  11. "name": "emq_auth_http",
  12. "version": "2.3.10",
  13. "description": "Authentication/ACL with HTTP API",
  14. "active": false
  15. },
  16. {
  17. "name": "emq_auth_jwt",
  18. "version": "2.3.10",
  19. "description": "Authentication with JWT",
  20. "active": false
  21. },
  22. {
  23. "name": "emq_auth_ldap",
  24. "version": "2.3.10",
  25. "description": "Authentication/ACL with LDAP",
  26. "active": false
  27. },
  28. {
  29. "name": "emq_auth_mongo",
  30. "version": "2.3.10",
  31. "description": "Authentication/ACL with MongoDB",
  32. "active": false
  33. },
  34. {
  35. "name": "emq_auth_mysql",
  36. "version": "2.3.10",
  37. "description": "Authentication/ACL with MySQL",
  38. "active": false
  39. },
  40. {
  41. "name": "emq_auth_pgsql",
  42. "version": "2.3.10",
  43. "description": "Authentication/ACL with PostgreSQL",
  44. "active": false
  45. },
  46. {
  47. "name": "emq_auth_redis",
  48. "version": "2.3.10",
  49. "description": "Authentication/ACL with Redis",
  50. "active": false
  51. },
  52. {
  53. "name": "emq_auth_username",
  54. "version": "2.3.10",
  55. "description": "Authentication with Username/Password",
  56. "active": false
  57. },
  58. {
  59. "name": "emq_coap",
  60. "version": "2.3.10",
  61. "description": "CoAP Gateway",
  62. "active": false
  63. },
  64. {
  65. "name": "emq_dashboard",
  66. "version": "2.3.10",
  67. "description": "EMQ Web Dashboard",
  68. "active": true
  69. },
  70. {
  71. "name": "emq_lua_hook",
  72. "version": "2.3.10",
  73. "description": "EMQ Hooks in lua",
  74. "active": false
  75. },
  76. {
  77. "name": "emq_modules",
  78. "version": "2.3.10",
  79. "description": "EMQ Modules",
  80. "active": true
  81. },
  82. {
  83. "name": "emq_plugin_template",
  84. "version": "2.3.10",
  85. "description": "EMQ Plugin Template",
  86. "active": false
  87. },
  88. {
  89. "name": "emq_recon",
  90. "version": "2.3.10",
  91. "description": "Recon Plugin",
  92. "active": true
  93. },
  94. {
  95. "name": "emq_reloader",
  96. "version": "2.3.10",
  97. "description": "Reloader Plugin",
  98. "active": false
  99. },
  100. {
  101. "name": "emq_retainer",
  102. "version": "2.3.10",
  103. "description": "EMQ Retainer",
  104. "active": true
  105. },
  106. {
  107. "name": "emq_sn",
  108. "version": "2.3.10",
  109. "description": "MQTT-SN Gateway",
  110. "active": false
  111. },
  112. {
  113. "name": "emq_stomp",
  114. "version": "2.3.10",
  115. "description": "Stomp Protocol Plugin",
  116. "active": false
  117. },
  118. {
  119. "name": "emq_web_hook",
  120. "version": "2.3.10",
  121. "description": "EMQ Webhook Plugin",
  122. "active": false
  123. }
  124. ]
  125. }

开启/关闭节点的指定插件

API 定义:

  1. PUT /api/v2/nodes/{node_name}/plugins/{name}

请求参数:

  1. {"active": true | false}

请求示例:

  1. PUT api/v2/nodes/emq@127.0.0.1/plugins/emq_recon
  2. json请求参数:
  3. {
  4. "active": true
  5. }

返回数据:

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

监听器(Listeners)

获取集群节点的监听器列表

API 定义:

  1. GET api/v2/monitoring/listeners

返回数据:

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

获取指定节点的监听器列表

API 定义:

  1. GET api/v2/monitoring/listeners/{node_name}

请求示例:

  1. GET api/v2/monitoring/listeners/emq@127.0.0.1

返回数据:

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

收发报文统计

获取全部节点的收发报文统计

API 定义:

  1. GET api/v2/monitoring/metrics/

返回数据:

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

获取指定节点的收发报文统计

API 定义:

  1. GET api/v2/monitoring/metrics/{node_name}

请求示例:

  1. GET api/v2/monitoring/metrics/emq@127.0.0.1

返回数据:

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

连接会话统计

获取全部节点的连接会话统计

API 定义:

  1. GET api/v2/monitoring/stats

请求示例:

  1. GET api/v2/monitoring/stats

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "emq@127.0.0.1": {
  6. "clients/count": 0,
  7. "clients/max": 0,
  8. "retained/count": 3,
  9. "retained/max": 3,
  10. "routes/count": 0,
  11. "routes/max": 0,
  12. "sessions/count": 0,
  13. "sessions/max": 0,
  14. "subscribers/count": 0,
  15. "subscribers/max": 0,
  16. "subscriptions/count": 0,
  17. "subscriptions/max": 0,
  18. "topics/count": 0,
  19. "topics/max": 0
  20. }
  21. }
  22. ]
  23. }

获取指定节点的连接会话统计

API 定义:

  1. GET api/v2/monitoring/stats/{node_name}

请求示例:

  1. GET api/v2/monitoring/stats/emq@127.0.0.1

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "clients/count": 0,
  5. "clients/max": 0,
  6. "retained/count": 3,
  7. "retained/max": 3,
  8. "routes/count": 0,
  9. "routes/max": 0,
  10. "sessions/count": 0,
  11. "sessions/max": 0,
  12. "subscribers/count": 0,
  13. "subscribers/max": 0,
  14. "subscriptions/count": 0,
  15. "subscriptions/max": 0,
  16. "topics/count": 0,
  17. "topics/max": 0
  18. }
  19. }

热配置

获取全部节点的可修改配置项

API定义:

  1. GET api/v2/configs

请求示例:

  1. GET api/v2/configs

返回数据:

  1. {
  2. "code": 0,
  3. "result": {
  4. "emq@127.0.0.1": [
  5. {
  6. "key": "log.console.level",
  7. "value": "error",
  8. "datatpye": "enum",
  9. "app": "emqttd"
  10. },
  11. {
  12. "key": "mqtt.acl_file",
  13. "value": "etc/acl.conf",
  14. "datatpye": "string",
  15. "app": "emqttd"
  16. },
  17. {
  18. "key": "mqtt.acl_nomatch",
  19. "value": "allow",
  20. "datatpye": "enum",
  21. "app": "emqttd"
  22. },
  23. {
  24. "key": "mqtt.allow_anonymous",
  25. "value": "true",
  26. "datatpye": "enum",
  27. "app": "emqttd"
  28. },
  29. {
  30. "key": "mqtt.broker.sys_interval",
  31. "value": "60",
  32. "datatpye": "integer",
  33. "app": "emqttd"
  34. },
  35. {
  36. "key": "mqtt.cache_acl",
  37. "value": "true",
  38. "datatpye": "enum",
  39. "app": "emqttd"
  40. }
  41. ]
  42. }
  43. }

获取指定节点的可修改配置项

API定义:

  1. GET api/v2/nodes/{node_name}/configs

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/configs

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "key": "log.console.level",
  6. "value": "error",
  7. "datatpye": "enum",
  8. "app": "emqttd"
  9. },
  10. {
  11. "key": "mqtt.acl_file",
  12. "value": "etc/acl.conf",
  13. "datatpye": "string",
  14. "app": "emqttd"
  15. },
  16. {
  17. "key": "mqtt.acl_nomatch",
  18. "value": "allow",
  19. "datatpye": "enum",
  20. "app": "emqttd"
  21. },
  22. {
  23. "key": "mqtt.allow_anonymous",
  24. "value": "true",
  25. "datatpye": "enum",
  26. "app": "emqttd"
  27. },
  28. {
  29. "key": "mqtt.broker.sys_interval",
  30. "value": "60",
  31. "datatpye": "integer",
  32. "app": "emqttd"
  33. },
  34. {
  35. "key": "mqtt.cache_acl",
  36. "value": "true",
  37. "datatpye": "enum",
  38. "app": "emqttd"
  39. }
  40. ]
  41. }

修改全部节点的配置项

API定义:

  1. PUT /api/v2/configs/{app_name}

请求参数:

  1. {
  2. "key" : "mqtt.allow_anonymous",
  3. "value" : "false"
  4. }

请求示例:

  1. PUT /api/v2/configs/emqttd

返回数据:

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

修改指定节点的配置项

API定义:

  1. PUT /api/v2/nodes/{node_name}/configs/{app_name}

请求参数:

  1. {
  2. "key" : "mqtt.allow_anonymous",
  3. "value" : "false"
  4. }

请求示例:

  1. PUT /api/v2/nodes/emq@127.0.0.1/configs/emqttd

返回数据:

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

获取指定节点的指定插件的配置项

API定义:

  1. GET api/v2/nodes/{node_name}/plugin_configs/{plugin_name}

请求示例:

  1. GET api/v2/nodes/emq@127.0.0.1/plugin_configs/emq_auth_http

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "key": "auth.http.auth_req",
  6. "value": "http://127.0.0.1:8080/mqtt/auth",
  7. "desc": "",
  8. "required": true
  9. },
  10. {
  11. "key": "auth.http.auth_req.method",
  12. "value": "post",
  13. "desc": "",
  14. "required": true
  15. },
  16. {
  17. "key": "auth.http.auth_req.params",
  18. "value": "clientid=%c,username=%u,password=%P",
  19. "desc": "",
  20. "required": true
  21. },
  22. {
  23. "key": "auth.http.super_req",
  24. "value": "http://127.0.0.1:8080/mqtt/superuser",
  25. "desc": "",
  26. "required": true
  27. },
  28. {
  29. "key": "auth.http.super_req.method",
  30. "value": "post",
  31. "desc": "",
  32. "required": true
  33. },
  34. {
  35. "key": "auth.http.super_req.params",
  36. "value": "clientid=%c,username=%u",
  37. "desc": "",
  38. "required": true
  39. },
  40. {
  41. "key": "auth.http.acl_req",
  42. "value": "http://127.0.0.1:8080/mqtt/acl",
  43. "desc": "",
  44. "required": true
  45. },
  46. {
  47. "key": "auth.http.acl_req.method",
  48. "value": "get",
  49. "desc": "",
  50. "required": true
  51. },
  52. {
  53. "key": "auth.http.acl_req.params",
  54. "value": "access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t",
  55. "desc": "",
  56. "required": true
  57. }
  58. ]
  59. }

修改指定节点的指定插件的配置项

API定义:

  1. PUT api/v2/nodes/{node_name}/plugin_configs/{plugin_name}

请求参数:

  1. {
  2. "auth.http.auth_req.method": "get",
  3. "auth.http.auth_req": "http://127.0.0.1:8080/mqtt/auth",
  4. "auth.http.auth_req.params": "clientid=%c,username=%u,password=%P",
  5. "auth.http.acl_req.method": "get",
  6. "auth.http.acl_req": "http://127.0.0.1:8080/mqtt/acl",
  7. "auth.http.acl_req.params": "access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t",
  8. "auth.http.super_req.method": "post",
  9. "auth.http.super_req.params": "clientid=%c,username=%u",
  10. "auth.http.super_req": "http://127.0.0.1:8080/mqtt/superuser"
  11. }

请求示例:

  1. PUT api/v2/nodes/emq@127.0.0.1/plugin_configs/emq_auth_http

返回数据:

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

用户管理

获取管理用户列表

API定义:

  1. GET api/v2/users

请求示例:

  1. GET api/v2/users

返回数据:

  1. {
  2. "code": 0,
  3. "result": [
  4. {
  5. "username": "admin",
  6. "tags": "administrator"
  7. }
  8. ]
  9. }

添加管理用户

API定义:

  1. POST api/v2/users

请求参数:

  1. {
  2. "username": "test_user",
  3. "password": "password",
  4. "tags": "user"
  5. }

请求示例:

  1. POST api/v2/users

返回数据:

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

修改管理用户信息

API定义:

  1. PUT api/v2/users/{username}

请求参数:

  1. {
  2. "tags": "admin"
  3. }

请求示例:

  1. PUT api/v2/users/test_user

返回数据:

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

删除管理用户

API定义:

  1. DELETE api/v2/users/{username}

请求参数:

请求示例:

  1. DELETE api/v2/users/test_user

返回数据:

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

认证管理用户

API定义:

  1. POST api/v2/auth

请求参数:

  1. {
  2. "username": "test_user",
  3. "password": "password"
  4. }

请求示例:

  1. POST api/v2/auth

返回数据:

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

修改管理用户密码

API定义:

  1. PUT api/v2/change_pwd/{username}

请求参数:

  1. {
  2. "new_pwd": "newpassword",
  3. "old_pwd": "password"
  4. }

请求示例:

  1. PUT api/v2/change_pwd/test_user

返回数据:

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

返回错误码

错误码

备注

0

成功

101

badrpc

102

未知错误

103

用户名密码错误

104

用户名密码不能为空

105

删除的用户不存在

106

admin用户不能删除

107

请求参数缺失

108

请求参数类型错误

109

请求参数不是json类型

110

插件已经加载,不能重复加载

111

插件已经卸载,不能重复卸载

112

用户不在线

113

用户已经存在

114

旧密码错误