guide.rst 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. .. _guide:
  2. ==========
  3. User Guide
  4. ==========
  5. ------------------------
  6. Pluggable Authentication
  7. ------------------------
  8. ----------
  9. MQTT Basic
  10. ----------
  11. Publish/Subscribe
  12. -----------------
  13. Understanding QoS
  14. -----------------
  15. Retained Message
  16. ----------------
  17. Will Message
  18. ------------
  19. ----------------
  20. HTTP Publish API
  21. ----------------
  22. emqttd support HTTP API to publish message from your application server to MQTT clients. For example::
  23. curl -v --basic -u user:passwd -d "qos=1&retain=0&topic=/a/b/c&message=hello from http..." -k http://localhost:8083/mqtt/publish
  24. HTTP API URL
  25. ------------
  26. HTTP POST http://host:8083/mqtt/publish
  27. HTTP Parameters
  28. ---------------
  29. Name | Description
  30. --------|---------------
  31. client | ClientId
  32. qos | QoS(0, 1, 2)
  33. retain | Retain(0, 1)
  34. topic | Topic
  35. message | Message
  36. -------------------
  37. MQTT Over WebSocket
  38. -------------------
  39. ## Overview
  40. emqttd 0.7.0 release support MQTT over WebSocket(SSL).
  41. ## URI
  42. ```
  43. ws(s)://host:8083/mqtt
  44. ```
  45. ## Sec-WebSocket-Protocol
  46. 'mqttv3.1', 'mqttv3.1.1'
  47. -----------------------
  48. Trace Topic or Client
  49. -----------------------
  50. ## Overview
  51. emqttd could trace packets received/sent from/to specific client, or trace publish/subscribe to specific topic.
  52. emqttd use lager:trace_file api and write trace log to file.
  53. ## Trace Commands
  54. ### Trace client
  55. ```
  56. ./bin/emqttd_ctl trace client "ClientId" "trace_clientid.log"
  57. ```
  58. ### Trace topic
  59. ```
  60. ./bin/emqttd_ctl trace topic "Topic" "trace_topic.log"
  61. ```
  62. ### Stop Trace
  63. ```
  64. ./bin/emqttd_ctl trace client "ClientId" off
  65. ./bin/emqttd_ctl trace topic "Topic" off
  66. ```
  67. ### Lookup Traces
  68. ```
  69. ./bin/emqttd_ctl trace list
  70. ```
  71. -------------------
  72. $SYS Topics
  73. -------------------
  74. NOTICE: This is the design of 0.9.0 release
  75. ## Overview
  76. For emqttd is clustered, $SYS Topics of broker is started with:
  77. ```
  78. $SYS/brokers/${node}
  79. ```
  80. ${node} is erlang node of clustered brokers. For example:
  81. ```
  82. $SYS/brokers/emqttd@host1/version
  83. $SYS/brokers/emqttd@host2/version
  84. ```
  85. ## Broker $SYS Topics
  86. Topic | Description
  87. -------------------------------|------------
  88. $SYS/brokers | Broker nodes
  89. $SYS/brokers/${node}/version | Broker Version
  90. $SYS/brokers/${node}/uptime | Broker Uptime
  91. $SYS/brokers/${node}/datetime | Broker DateTime
  92. $SYS/brokers/${node}/sysdescr | Broker Description
  93.  
  94. ## Client $SYS Topics
  95. Start with: $SYS/brokers/${node}/clients/
  96. Topic | Payload(json) | Description
  97. ----------------------|---------------------|---------------
  98. ${clientid}/connected | {ipaddress: "127.0.0.1", username: "test", session: false, version: 3, connack: 0, ts: 1432648482} | Publish when client connected
  99. ${clientid}/disconnected | {reason: "normal" | "keepalive_timeout" | "conn_closed"}
  100. Parameters of 'connected' Payload:
  101. ```
  102. ipaddress: "127.0.0.1",
  103. username: "test",
  104. session: false,
  105. protocol: 3,
  106. connack: 0,
  107. ts: 1432648482
  108. ```
  109. Parameters of 'disconnected' Payload:
  110. ```
  111. reason: normal,
  112. ts: 1432648486
  113. ```
  114. ## Statistics $SYS Topics
  115. Start with '$SYS/brokers/${node}/stats/'
  116. ### Client Stats
  117. Topic | Description
  118. -------------------------------------|------------
  119. clients/count | count of current connected clients
  120. clients/max | max connected clients in the same time
  121. ### Session Stats
  122. Topic | Description
  123. -----------------|------------
  124. sessions/count | count of current sessions
  125. sessions/max | max number of sessions
  126. ### Subscriber Stats
  127. Topic | Description
  128. ------------------|------------
  129. subscriptions/count | count of current subscriptions
  130. subscriptions/max | max number of subscriptions
  131. ### Topic Stats
  132. Topic | Description
  133. ------------------|------------
  134. topics/count | count of current topics
  135. topics/max | max number of topics
  136. ### Queue Stats
  137. Topic | Description
  138. ------------------|------------
  139. queues/count | count of current queues
  140. queues/max | max number of queues
  141. ## Metrics $SYS Topics
  142. Start with '$SYS/brokers/${node}/metrics/'
  143. ### Bytes sent and received
  144. Topic | Description
  145. ------------------------------------|------------
  146. bytes/received | MQTT Bytes Received since broker started
  147. bytes/sent | MQTT Bytes Sent since the broker started
  148. ### Packets sent and received
  149. Topic | Description
  150. -------------------------|------------
  151. packets/received | MQTT Packets received
  152. packets/sent | MQTT Packets sent
  153. packets/connect | MQTT CONNECT Packet received
  154. packets/connack | MQTT CONNACK Packet sent
  155. packets/publish/received | MQTT PUBLISH packets received
  156. packets/publish/sent | MQTT PUBLISH packets sent
  157. packets/subscribe | MQTT SUBSCRIBE Packets received
  158. packets/suback | MQTT SUBACK packets sent
  159. packets/unsubscribe | MQTT UNSUBSCRIBE Packets received
  160. packets/unsuback | MQTT UNSUBACK Packets sent
  161. packets/pingreq | MQTT PINGREQ packets received
  162. packets/pingresp | MQTT PINGRESP Packets sent
  163. packets/disconnect | MQTT DISCONNECT Packets received
  164. ### Messages sent and received
  165. Topic | Description
  166. ---------------------------------------|-------------------
  167. messages/received | Messages Received
  168. messages/sent | Messages Sent
  169. messages/retained | Messages Retained
  170. messages/stored | TODO: Messages Stored
  171. messages/dropped | Messages Dropped
  172. ## Alarm Topics
  173. Start with '$SYS/brokers/${node}/alarms/'
  174. Topic | Description
  175. -----------------|-------------------
  176. ${alarmId}/alert | New Alarm
  177. ${alarmId}/clear | Clear Alarm
  178. ## Log
  179. '$SYS/brokers/${node}/logs/${severity}'
  180. Severity | Description
  181. -----------|-------------------
  182. debug | Debug Log
  183. info | Info Log
  184. notice | Notice Log
  185. warning | Warning Log
  186. error | Error Log
  187. critical | Critical Log
  188. ## Sysmon
  189. Start with '$SYS/brokers/${node}/sysmon/'
  190. Topic | Description
  191. -----------------|-------------------
  192. long_gc | Long GC Warning
  193. long_schedule | Long Schedule
  194. large_heap | Large Heap Warning
  195. busy_port | Busy Port Warning
  196. busy_dist_port | Busy Dist Port
  197. ## Log
  198. '$SYS/brokers/${node}/log/${severity}'
  199. Severity | Description
  200. ------------|-------------------
  201. debug | Debug
  202. info | Info Log
  203. notice | Notice Log
  204. warning | Warning Log
  205. error | Error Log
  206. critical | Critical Log
  207. alert | Alert Log
  208. ## VM Load Topics
  209. Start with '$SYS/brokers/${node}/vm/'
  210. Topic | Description
  211. -----------------|-------------------
  212. memory/* | TODO
  213. cpu/* | TODO
  214. processes/* | TODO
  215. ## Sys Interval
  216. sys_interval: 1 minute default