guide.rst 27 KB

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