guide.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. .. _guide:
  2. ==========
  3. User Guide
  4. ==========
  5. --------------
  6. Authentication
  7. --------------
  8. The emqttd broker supports to authenticate MQTT clients with ClientID, Username/Password, IpAddress and even HTTP Cookies.
  9. The authentication is provided by a list of extended modules, or MySQL, PostgreSQL and Redis Plugins.
  10. Enable an authentication module in etc/emqttd.config:
  11. .. code-block:: erlang
  12. %% Authentication and Authorization
  13. {access, [
  14. %% Authetication. Anonymous Default
  15. {auth, [
  16. %% Authentication with username, password
  17. %{username, []},
  18. %% Authentication with clientid
  19. %{clientid, [{password, no}, {file, "etc/clients.config"}]},
  20. %% Authentication with LDAP
  21. % {ldap, [
  22. % {servers, ["localhost"]},
  23. % {port, 389},
  24. % {timeout, 30},
  25. % {user_dn, "uid=$u,ou=People,dc=example,dc=com"},
  26. % {ssl, fasle},
  27. % {sslopts, [
  28. % {"certfile", "ssl.crt"},
  29. % {"keyfile", "ssl.key"}]}
  30. % ]},
  31. %% Allow all
  32. {anonymous, []}
  33. ]},
  34. .. NOTE:: "%" comments the line.
  35. If we enable several modules at the same time, the authentication process::
  36. ---------------- ---------------- -------------
  37. Client --> | Username | -ignore-> | ClientID | -ignore-> | Anonymous |
  38. ---------------- ---------------- -------------
  39. | | |
  40. \|/ \|/ \|/
  41. allow | deny allow | deny allow | deny
  42. The authentication plugins developed by emqttd:
  43. +---------------------------+---------------------------+
  44. | Plugin | Description |
  45. +===========================+===========================+
  46. | `emqttd_plugin_mysql`_ | MySQL Auth/ACL Plugin |
  47. +---------------------------+---------------------------+
  48. | `emqttd_plugin_pgsql`_ | PostgreSQL Auth/ACL Plugin|
  49. +---------------------------+---------------------------+
  50. | `emqttd_plugin_redis`_ | Redis Auth/ACL Plugin |
  51. +---------------------------+---------------------------+
  52. .. NOTE:: If we load an authentication plugin, the authentication modules will be disabled.
  53. Username
  54. --------
  55. Authenticate MQTT client with Username/Password::
  56. {username, [{client1, "passwd1"}, {client1, "passwd2"}]},
  57. Two ways to add users:
  58. 1. Configure username and plain password directly::
  59. {username, [{client1, "passwd1"}, {client1, "passwd2"}]},
  60. 2. Add user by './bin/emqttd_ctl users' command::
  61. $ ./bin/emqttd_ctl users add <Username> <Password>
  62. ClientId
  63. --------
  64. .. code-block:: erlang
  65. {clientid, [{password, no}, {file, "etc/clients.config"}]},
  66. Configure ClientIDs in etc/clients.config::
  67. testclientid0
  68. testclientid1 127.0.0.1
  69. testclientid2 192.168.0.1/24
  70. LDAP
  71. ----
  72. .. code-block:: erlang
  73. {ldap, [
  74. {servers, ["localhost"]},
  75. {port, 389},
  76. {timeout, 30},
  77. {user_dn, "uid=$u,ou=People,dc=example,dc=com"},
  78. {ssl, fasle},
  79. {sslopts, [
  80. {"certfile", "ssl.crt"},
  81. {"keyfile", "ssl.key"}]}
  82. ]},
  83. Anonymous
  84. ---------
  85. Allow any client to connect to the broker::
  86. {anonymous, []}
  87. MySQL
  88. -----
  89. Authenticate against MySQL database. Support we create a mqtt_user table:
  90. .. code-block:: sql
  91. CREATE TABLE `mqtt_user` (
  92. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  93. `username` varchar(100) DEFAULT NULL,
  94. `password` varchar(100) DEFAULT NULL,
  95. `salt` varchar(20) DEFAULT NULL,
  96. `created` datetime DEFAULT NULL,
  97. PRIMARY KEY (`id`),
  98. UNIQUE KEY `mqtt_username` (`username`)
  99. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  100. Configure the 'authquery' and 'password_hash' in emqttd_plugin_mysql/etc/plugin.config:
  101. .. code-block:: erlang
  102. [
  103. {emqttd_plugin_mysql, [
  104. ...
  105. %% select password only
  106. {authquery, "select password from mqtt_user where username = '%u' limit 1"},
  107. %% hash algorithm: md5, sha, sha256, pbkdf2?
  108. {password_hash, sha256},
  109. ...
  110. ]}
  111. ].
  112. Load the plugin::
  113. ./bin/emqttd_ctl plugins load emqttd_plugin_mysql
  114. PostgreSQL
  115. ----------
  116. Authenticate against PostgreSQL database. Create a mqtt_user table:
  117. .. code-block:: sql
  118. CREATE TABLE mqtt_user (
  119. id SERIAL primary key,
  120. username character varying(100),
  121. password character varying(100),
  122. salt character varying(40)
  123. );
  124. Configure the 'authquery' and 'password_hash' in emqttd_plugin_pgsql/etc/plugin.config:
  125. .. code-block:: erlang
  126. [
  127. {emqttd_plugin_pgsql, [
  128. ...
  129. %% select password only
  130. {authquery, "select password from mqtt_user where username = '%u' limit 1"},
  131. %% hash algorithm: md5, sha, sha256, pbkdf2?
  132. {password_hash, sha256},
  133. ...
  134. ]}
  135. ].
  136. Load the plugin::
  137. ./bin/emqttd_ctl plugins load emqttd_plugin_pgsql
  138. Redis
  139. -----
  140. Authenticate against Redis. MQTT users could be stored in redis HASH, the key is "mqtt_user:<Username>".
  141. Configure 'authcmd' and 'password_hash' in emqttd_plugin_redis/etc/plugin.config:
  142. .. code-block:: erlang
  143. [
  144. {emqttd_plugin_redis, [
  145. ...
  146. %% HMGET mqtt_user:%u password
  147. {authcmd, ["HGET", "mqtt_user:%u", "password"]},
  148. %% Password hash algorithm: plain, md5, sha, sha256, pbkdf2?
  149. {password_hash, sha256},
  150. ...
  151. ]}
  152. ].
  153. Load the plugin::
  154. ./bin/emqttd_ctl plugins load emqttd_plugin_redis
  155. ---
  156. ACL
  157. ---
  158. The ACL of emqttd broker is responsbile for authorizing MQTT clients to publish/subscribe topics.
  159. The ACL rules define::
  160. Allow|Deny Who Publish|Subscribe Topics
  161. Access Control Module of emqttd broker will match the rules one by one::
  162. --------- --------- ---------
  163. Client -> | Rule1 | --nomatch--> | Rule2 | --nomatch--> | Rule3 | --> Default
  164. --------- --------- ---------
  165. | | |
  166. match match match
  167. \|/ \|/ \|/
  168. allow | deny allow | deny allow | deny
  169. Internal
  170. --------
  171. The default ACL of emqttd broker is implemented by an 'internal' module.
  172. Enable the 'internal' ACL module in etc/emqttd.config:
  173. .. code-block:: erlang
  174. {acl, [
  175. %% Internal ACL module
  176. {internal, [{file, "etc/acl.config"}, {nomatch, allow}]}
  177. ]}
  178. The ACL rules of 'internal' module are defined in 'etc/acl.config' file:
  179. .. code-block:: erlang
  180. %% Allow 'dashboard' to subscribe '$SYS/#'
  181. {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
  182. %% Allow clients from localhost to subscribe any topics
  183. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
  184. %% Deny clients to subscribe '$SYS#' and '#'
  185. {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
  186. %% Allow all by default
  187. {allow, all}.
  188. MySQL
  189. -----
  190. ACL against MySQL database. The mqtt_acl table and default data:
  191. .. code-block:: sql
  192. CREATE TABLE `mqtt_acl` (
  193. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  194. `allow` int(1) DEFAULT NULL COMMENT '0: deny, 1: allow',
  195. `ipaddr` varchar(60) DEFAULT NULL COMMENT 'IpAddress',
  196. `username` varchar(100) DEFAULT NULL COMMENT 'Username',
  197. `clientid` varchar(100) DEFAULT NULL COMMENT 'ClientId',
  198. `access` int(2) NOT NULL COMMENT '1: subscribe, 2: publish, 3: pubsub',
  199. `topic` varchar(100) NOT NULL DEFAULT '' COMMENT 'Topic Filter',
  200. PRIMARY KEY (`id`)
  201. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  202. INSERT INTO mqtt_acl (id, allow, ipaddr, username, clientid, access, topic)
  203. VALUES
  204. (1,1,NULL,'$all',NULL,2,'#'),
  205. (2,0,NULL,'$all',NULL,1,'$SYS/#'),
  206. (3,0,NULL,'$all',NULL,1,'eq #'),
  207. (5,1,'127.0.0.1',NULL,NULL,2,'$SYS/#'),
  208. (6,1,'127.0.0.1',NULL,NULL,2,'#'),
  209. (7,1,NULL,'dashboard',NULL,1,'$SYS/#');
  210. Configure 'aclquery' and 'acl_nomatch' in emqttd_plugin_mysql/etc/plugin.config:
  211. .. code-block:: erlang
  212. [
  213. {emqttd_plugin_mysql, [
  214. ...
  215. %% comment this query, the acl will be disabled
  216. {aclquery, "select allow, ipaddr, username, clientid, access, topic from mqtt_acl where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'"},
  217. %% If no rules matched, return...
  218. {acl_nomatch, allow}
  219. ]}
  220. ].
  221. PostgreSQL
  222. ----------
  223. ACL against PostgreSQL database. The mqtt_acl table and default data:
  224. .. code-block:: sql
  225. CREATE TABLE mqtt_acl (
  226. id SERIAL primary key,
  227. allow integer,
  228. ipaddr character varying(60),
  229. username character varying(100),
  230. clientid character varying(100),
  231. access integer,
  232. topic character varying(100)
  233. );
  234. INSERT INTO mqtt_acl (id, allow, ipaddr, username, clientid, access, topic)
  235. VALUES
  236. (1,1,NULL,'$all',NULL,2,'#'),
  237. (2,0,NULL,'$all',NULL,1,'$SYS/#'),
  238. (3,0,NULL,'$all',NULL,1,'eq #'),
  239. (5,1,'127.0.0.1',NULL,NULL,2,'$SYS/#'),
  240. (6,1,'127.0.0.1',NULL,NULL,2,'#'),
  241. (7,1,NULL,'dashboard',NULL,1,'$SYS/#');
  242. Configure 'aclquery' and 'acl_nomatch' in emqttd_plugin_pgsql/etc/plugin.config:
  243. .. code-block:: erlang
  244. [
  245. {emqttd_plugin_pgsql, [
  246. ...
  247. %% Comment this query, the acl will be disabled. Notice: don't edit this query!
  248. {aclquery, "select allow, ipaddr, username, clientid, access, topic from mqtt_acl
  249. where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'"},
  250. %% If no rules matched, return...
  251. {acl_nomatch, allow}
  252. ...
  253. ]}
  254. ].
  255. Redis
  256. -----
  257. ACL against Redis. We store ACL rules for each MQTT client in a Redis List by defualt. The key is "mqtt_acl:<Username>", the value is a list of "publish <Topic>", "subscribe <Topic>" or "pubsub <Topic>".
  258. Configure 'aclcmd' and 'acl_nomatch' in emqttd_plugin_redis/etc/plugin.config:
  259. .. code-block:: erlang
  260. [
  261. {emqttd_plugin_redis, [
  262. ...
  263. %% SMEMBERS mqtt_acl:%u
  264. {aclcmd, ["SMEMBERS", "mqtt_acl:%u"]},
  265. %% If no rules matched, return...
  266. {acl_nomatch, deny},
  267. ...
  268. ]}
  269. ].
  270. ----------------------
  271. MQTT Publish/Subscribe
  272. ----------------------
  273. MQTT is a an extremely lightweight publish/subscribe messaging protocol desgined for IoT, M2M and Mobile applications.
  274. .. image:: _static/images/pubsub_concept.png
  275. Install and start the emqttd broker, and then any MQTT client could connect to the broker, subscribe topics and publish messages.
  276. MQTT Client Libraries: https://github.com/mqtt/mqtt.github.io/wiki/libraries
  277. For example, we use mosquitto_sub/pub commands::
  278. mosquitto_sub -t topic -q 2
  279. mosquitto_pub -t topic -q 1 -m "Hello, MQTT!"
  280. MQTT V3.1.1 Protocol Specification: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
  281. MQTT Listener of emqttd broker is configured in etc/emqttd.config:
  282. .. code-block:: erlang
  283. {mqtt, 1883, [
  284. %% Size of acceptor pool
  285. {acceptors, 16},
  286. %% Maximum number of concurrent clients
  287. {max_clients, 512},
  288. %% Socket Access Control
  289. {access, [{allow, all}]},
  290. %% Connection Options
  291. {connopts, [
  292. %% Rate Limit. Format is 'burst, rate', Unit is KB/Sec
  293. %% {rate_limit, "100,10"} %% 100K burst, 10K rate
  294. ]},
  295. %% Socket Options
  296. {sockopts, [
  297. %Set buffer if hight thoughtput
  298. %{recbuf, 4096},
  299. %{sndbuf, 4096},
  300. %{buffer, 4096},
  301. %{nodelay, true},
  302. {backlog, 512}
  303. ]}
  304. ]},
  305. MQTT(SSL) Listener, Default Port is 8883:
  306. .. code-block:: erlang
  307. {mqtts, 8883, [
  308. %% Size of acceptor pool
  309. {acceptors, 4},
  310. %% Maximum number of concurrent clients
  311. {max_clients, 512},
  312. %% Socket Access Control
  313. {access, [{allow, all}]},
  314. %% SSL certificate and key files
  315. {ssl, [{certfile, "etc/ssl/ssl.crt"},
  316. {keyfile, "etc/ssl/ssl.key"}]},
  317. %% Socket Options
  318. {sockopts, [
  319. {backlog, 1024}
  320. %{buffer, 4096},
  321. ]}
  322. ]},
  323. ----------------
  324. HTTP Publish API
  325. ----------------
  326. The emqttd broker provides a HTTP API to help application servers publish messages to MQTT clients.
  327. HTTP API: POST http://host:8083/mqtt/publish
  328. Web servers such as PHP, Java, Python, NodeJS and Ruby on Rails could use HTTP POST to publish MQTT messages to the broker::
  329. 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
  330. Parameters of the HTTP API:
  331. +---------+----------------+
  332. | Name | Description |
  333. +=========+================+
  334. | client | clientid |
  335. +---------+----------------+
  336. | qos | QoS(0, 1, 2) |
  337. +---------+----------------+
  338. | retain | Retain(0, 1) |
  339. +---------+----------------+
  340. | topic | Topic |
  341. +---------+----------------+
  342. | message | Payload |
  343. +---------+----------------+
  344. .. NOTE:: The API uses HTTP Basic Authentication.
  345. -------------------
  346. MQTT Over WebSocket
  347. -------------------
  348. Web browsers could connect to the emqttd broker directly by MQTT Over WebSocket.
  349. +-------------------------+----------------------------+
  350. | WebSocket URI: | ws(s)://host:8083/mqtt |
  351. +-------------------------+----------------------------+
  352. | Sec-WebSocket-Protocol: | 'mqttv3.1' or 'mqttv3.1.1' |
  353. +-------------------------+----------------------------+
  354. The Dashboard plugin provides a test page for WebSocket::
  355. http://127.0.0.1:18083/websocket.html
  356. Listener of WebSocket and HTTP Publish API is configured in etc/emqttd.config:
  357. .. code-block:: erlang
  358. %% HTTP and WebSocket Listener
  359. {http, 8083, [
  360. %% Size of acceptor pool
  361. {acceptors, 4},
  362. %% Maximum number of concurrent clients
  363. {max_clients, 64},
  364. %% Socket Access Control
  365. {access, [{allow, all}]},
  366. %% Socket Options
  367. {sockopts, [
  368. {backlog, 1024}
  369. %{buffer, 4096},
  370. ]}
  371. ]}
  372. -----------
  373. $SYS Topics
  374. -----------
  375. The emqttd broker periodically publishes internal status, MQTT statistics, metrics and client online/offline status to $SYS/# topics.
  376. For emqttd broker is clustered, the $SYS topic path is started with::
  377. $SYS/brokers/${node}/
  378. '${node}' is the erlang node name of emqttd broker. For example::
  379. $SYS/brokers/emqttd@127.0.0.1/version
  380. $SYS/brokers/emqttd@host2/uptime
  381. .. NOTE:: The broker only allows clients from localhost to subscribe $SYS topics by default.
  382. Sys Interval of publishing $SYS messages, could be configured in etc/emqttd.config::
  383. {broker, [
  384. %% System interval of publishing broker $SYS messages
  385. {sys_interval, 60},
  386. Broker Version, Uptime and Description
  387. ---------------------------------------
  388. +--------------------------------+-----------------------+
  389. | Topic | Description |
  390. +================================+=======================+
  391. | $SYS/brokers | Broker nodes |
  392. +--------------------------------+-----------------------+
  393. | $SYS/brokers/${node}/version | Broker Version |
  394. +--------------------------------+-----------------------+
  395. | $SYS/brokers/${node}/uptime | Broker Uptime |
  396. +--------------------------------+-----------------------+
  397. | $SYS/brokers/${node}/datetime | Broker DateTime |
  398. +--------------------------------+-----------------------+
  399. | $SYS/brokers/${node}/sysdescr | Broker Description |
  400. +--------------------------------+-----------------------+
  401. Online/Offline Status of MQTT Client
  402. ------------------------------------
  403. The topic path started with: $SYS/brokers/${node}/clients/
  404. +--------------------------+--------------------------------------------+------------------------------------+
  405. | Topic | Payload(JSON) | Description |
  406. +==========================+============================================+====================================+
  407. | ${clientid}/connected | {ipaddress: "127.0.0.1", username: "test", | Publish when a client connected |
  408. | | session: false, version: 3, connack: 0, | |
  409. | | ts: 1432648482} | |
  410. +--------------------------+--------------------------------------------+------------------------------------+
  411. | ${clientid}/disconnected | {reason: "keepalive_timeout", | Publish when a client disconnected |
  412. | | ts: 1432749431} | |
  413. +--------------------------+--------------------------------------------+------------------------------------+
  414. Properties of 'connected' Payload::
  415. ipaddress: "127.0.0.1",
  416. username: "test",
  417. session: false,
  418. protocol: 3,
  419. connack: 0,
  420. ts: 1432648482
  421. Properties of 'disconnected' Payload::
  422. reason: normal,
  423. ts: 1432648486
  424. Broker Statistics
  425. -----------------
  426. Topic path started with: $SYS/brokers/${node}/stats/
  427. Clients
  428. .......
  429. +---------------------+---------------------------------------------+
  430. | Topic | Description |
  431. +---------------------+---------------------------------------------+
  432. | clients/count | Count of current connected clients |
  433. +---------------------+---------------------------------------------+
  434. | clients/max | Max number of cocurrent connected clients |
  435. +---------------------+---------------------------------------------+
  436. Sessions
  437. ........
  438. +---------------------+---------------------------------------------+
  439. | Topic | Description |
  440. +---------------------+---------------------------------------------+
  441. | sessions/count | Count of current sessions |
  442. +---------------------+---------------------------------------------+
  443. | sessions/max | Max number of sessions |
  444. +---------------------+---------------------------------------------+
  445. Subscriptions
  446. .............
  447. +---------------------+---------------------------------------------+
  448. | Topic | Description |
  449. +---------------------+---------------------------------------------+
  450. | subscriptions/count | Count of current subscriptions |
  451. +---------------------+---------------------------------------------+
  452. | subscriptions/max | Max number of subscriptions |
  453. +---------------------+---------------------------------------------+
  454. Topics
  455. ......
  456. +---------------------+---------------------------------------------+
  457. | Topic | Description |
  458. +---------------------+---------------------------------------------+
  459. | topics/count | Count of current topics |
  460. +---------------------+---------------------------------------------+
  461. | topics/max | Max number of topics |
  462. +---------------------+---------------------------------------------+
  463. Broker Metrics
  464. --------------
  465. Topic path started with: $SYS/brokers/${node}/metrics/
  466. Bytes Sent/Received
  467. ...................
  468. +---------------------+---------------------------------------------+
  469. | Topic | Description |
  470. +---------------------+---------------------------------------------+
  471. | bytes/received | MQTT Bytes Received since broker started |
  472. +---------------------+---------------------------------------------+
  473. | bytes/sent | MQTT Bytes Sent since the broker started |
  474. +---------------------+---------------------------------------------+
  475. Packets Sent/Received
  476. .....................
  477. +--------------------------+---------------------------------------------+
  478. | Topic | Description |
  479. +--------------------------+---------------------------------------------+
  480. | packets/received | MQTT Packets received |
  481. +--------------------------+---------------------------------------------+
  482. | packets/sent | MQTT Packets sent |
  483. +--------------------------+---------------------------------------------+
  484. | packets/connect | MQTT CONNECT Packet received |
  485. +--------------------------+---------------------------------------------+
  486. | packets/connack | MQTT CONNACK Packet sent |
  487. +--------------------------+---------------------------------------------+
  488. | packets/publish/received | MQTT PUBLISH packets received |
  489. +--------------------------+---------------------------------------------+
  490. | packets/publish/sent | MQTT PUBLISH packets sent |
  491. +--------------------------+---------------------------------------------+
  492. | packets/subscribe | MQTT SUBSCRIBE Packets received |
  493. +--------------------------+---------------------------------------------+
  494. | packets/suback | MQTT SUBACK packets sent |
  495. +--------------------------+---------------------------------------------+
  496. | packets/unsubscribe | MQTT UNSUBSCRIBE Packets received |
  497. +--------------------------+---------------------------------------------+
  498. | packets/unsuback | MQTT UNSUBACK Packets sent |
  499. +--------------------------+---------------------------------------------+
  500. | packets/pingreq | MQTT PINGREQ packets received |
  501. +--------------------------+---------------------------------------------+
  502. | packets/pingresp | MQTT PINGRESP Packets sent |
  503. +--------------------------+---------------------------------------------+
  504. | packets/disconnect | MQTT DISCONNECT Packets received |
  505. +--------------------------+---------------------------------------------+
  506. Messages Sent/Received
  507. ......................
  508. +--------------------------+---------------------------------------------+
  509. | Topic | Description |
  510. +--------------------------+---------------------------------------------+
  511. | messages/received | Messages Received |
  512. +--------------------------+---------------------------------------------+
  513. | messages/sent | Messages Sent |
  514. +--------------------------+---------------------------------------------+
  515. | messages/retained | Messages Retained |
  516. +--------------------------+---------------------------------------------+
  517. | messages/stored | TODO: Messages Stored |
  518. +--------------------------+---------------------------------------------+
  519. | messages/dropped | Messages Dropped |
  520. +--------------------------+---------------------------------------------+
  521. Broker Alarms
  522. -------------
  523. Topic path started with: $SYS/brokers/${node}/alarms/
  524. +------------------+------------------+
  525. | Topic | Description |
  526. +------------------+------------------+
  527. | ${alarmId}/alert | New Alarm |
  528. +------------------+------------------+
  529. | ${alarmId}/clear | Clear Alarm |
  530. +------------------+------------------+
  531. Broker Sysmon
  532. -------------
  533. Topic path started with: '$SYS/brokers/${node}/sysmon/'
  534. +------------------+--------------------+
  535. | Topic | Description |
  536. +------------------+--------------------+
  537. | long_gc | Long GC Warning |
  538. +------------------+--------------------+
  539. | long_schedule | Long Schedule |
  540. +------------------+--------------------+
  541. | large_heap | Large Heap Warning |
  542. +------------------+--------------------+
  543. | busy_port | Busy Port Warning |
  544. +------------------+--------------------+
  545. | busy_dist_port | Busy Dist Port |
  546. +------------------+--------------------+
  547. -----
  548. Trace
  549. -----
  550. The emqttd broker supports to trace MQTT packets received/sent from/to a client, or trace MQTT messages published to a topic.
  551. Trace a client::
  552. ./bin/emqttd_ctl trace client "clientid" "trace_clientid.log"
  553. Trace a topic::
  554. ./bin/emqttd_ctl trace topic "topic" "trace_topic.log"
  555. Lookup Traces::
  556. ./bin/emqttd_ctl trace list
  557. Stop a Trace::
  558. ./bin/emqttd_ctl trace client "clientid" off
  559. ./bin/emqttd_ctl trace topic "topic" off
  560. .. _emqttd_plugin_mysql: https://github.com/emqtt/emqttd_plugin_mysql
  561. .. _emqttd_plugin_pgsql: https://github.com/emqtt/emqttd_plugin_pgsql
  562. .. _emqttd_plugin_redis: https://github.com/emqtt/emqttd_plugin_redis