commands.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. .. _commands::
  2. ========
  3. Commands
  4. ========
  5. The './bin/emqttd_ctl' command line could be used to query and administrate emqttd broker.
  6. .. WARNING:: Cannot work on Windows
  7. .. _command_status::
  8. ------
  9. status
  10. ------
  11. Show running status of the broker::
  12. $ ./bin/emqttd_ctl status
  13. Node 'emqttd@127.0.0.1' is started
  14. emqttd 0.16.0 is running
  15. .. _command_broker::
  16. ------
  17. broker
  18. ------
  19. Query basic information, statistics and metrics of the broker.
  20. +----------------+-------------------------------------------------+
  21. | broker | Show version, description, uptime of the broker |
  22. +----------------+-------------------------------------------------+
  23. | broker pubsub | Show status of the core pubsub process |
  24. +----------------+-------------------------------------------------+
  25. | broker stats | Show statistics of client, session, topic, |
  26. | | subscription and route of the broker |
  27. +----------------+-------------------------------------------------+
  28. | broker metrics | Show metrics of MQTT bytes, packets, messages |
  29. | | sent/received. |
  30. +----------------+-------------------------------------------------+
  31. Query version, description and uptime of the broker::
  32. $ ./bin/emqttd_ctl broker
  33. sysdescr : Erlang MQTT Broker
  34. version : 0.15.0
  35. uptime : 1 hours, 25 minutes, 24 seconds
  36. datetime : 2016-01-16 13:17:32
  37. broker stats
  38. ------------
  39. Query statistics of MQTT Client, Session, Topic, Subscription and Route::
  40. $ ./bin/emqttd_ctl broker stats
  41. clients/count : 1
  42. clients/max : 1
  43. queues/count : 0
  44. queues/max : 0
  45. retained/count : 2
  46. retained/max : 2
  47. routes/count : 2
  48. routes/reverse : 2
  49. sessions/count : 0
  50. sessions/max : 0
  51. subscriptions/count : 1
  52. subscriptions/max : 1
  53. topics/count : 54
  54. topics/max : 54
  55. broker metrics
  56. --------------
  57. Query metrics of Bytes, MQTT Packets and Messages(sent/received)::
  58. $ ./bin/emqttd_ctl broker metrics
  59. bytes/received : 297
  60. bytes/sent : 40
  61. messages/dropped : 348
  62. messages/qos0/received : 0
  63. messages/qos0/sent : 0
  64. messages/qos1/received : 0
  65. messages/qos1/sent : 0
  66. messages/qos2/received : 0
  67. messages/qos2/sent : 0
  68. messages/received : 0
  69. messages/retained : 2
  70. messages/sent : 0
  71. packets/connack : 5
  72. packets/connect : 5
  73. packets/disconnect : 0
  74. packets/pingreq : 0
  75. packets/pingresp : 0
  76. packets/puback/received : 0
  77. packets/puback/sent : 0
  78. packets/pubcomp/received: 0
  79. packets/pubcomp/sent : 0
  80. packets/publish/received: 0
  81. packets/publish/sent : 0
  82. packets/pubrec/received : 0
  83. packets/pubrec/sent : 0
  84. packets/pubrel/received : 0
  85. packets/pubrel/sent : 0
  86. packets/received : 9
  87. packets/sent : 9
  88. packets/suback : 4
  89. packets/subscribe : 4
  90. packets/unsuback : 0
  91. packets/unsubscribe : 0
  92. .. _command_cluster::
  93. -------
  94. cluster
  95. -------
  96. Cluster two or more emqttd brokers.
  97. +-----------------------+--------------------------------+
  98. | cluster join <Node> | Join the cluster |
  99. +-----------------------+--------------------------------+
  100. | cluster leave | Leave the cluster |
  101. +-----------------------+--------------------------------+
  102. | cluster remove <Node> | Remove a node from the cluster |
  103. +-----------------------+--------------------------------+
  104. | cluster status | Query cluster status and nodes |
  105. +-----------------------+--------------------------------+
  106. Suppose we create two emqttd nodes on localhost and cluster them:
  107. +-----------+---------------------+-------------+
  108. | Folder | Node | MQTT Port |
  109. +-----------+---------------------+-------------+
  110. | emqttd1 | emqttd1@127.0.0.1 | 1883 |
  111. +-----------+---------------------+-------------+
  112. | emqttd2 | emqttd2@127.0.0.1 | 2883 |
  113. +-----------+---------------------+-------------+
  114. Start emqttd1 node::
  115. cd emqttd1 && ./bin/emqttd start
  116. Start emqttd2 node::
  117. cd emqttd2 && ./bin/emqttd start
  118. Under emqttd2 folder::
  119. $ ./bin/emqttd_ctl cluster join emqttd1@127.0.0.1
  120. Join the cluster successfully.
  121. Cluster status: [{running_nodes,['emqttd1@127.0.0.1','emqttd2@127.0.0.1']}]
  122. Query cluster status::
  123. $ ./bin/emqttd_ctl cluster status
  124. Cluster status: [{running_nodes,['emqttd2@127.0.0.1','emqttd1@127.0.0.1']}]
  125. Message Route between nodes::
  126. # Subscribe topic 'x' on emqttd1 node
  127. mosquitto_sub -t x -q 1 -p 1883
  128. # Publish to topic 'x' on emqttd2 node
  129. mosquitto_pub -t x -q 1 -p 2883 -m hello
  130. emqttd2 leaves the cluster::
  131. cd emqttd2 && ./bin/emqttd_ctl cluster leave
  132. Or remove emqttd2 from the cluster on emqttd1 node::
  133. cd emqttd1 && ./bin/emqttd_ctl cluster remove emqttd2@127.0.0.1
  134. .. _command_clients::
  135. -------
  136. clients
  137. -------
  138. Query MQTT clients connected to the broker:
  139. +-------------------------+----------------------------------+
  140. | clients list | List all MQTT clients |
  141. +-------------------------+----------------------------------+
  142. | clients show <ClientId> | Show a MQTT Client |
  143. +-------------------------+----------------------------------+
  144. | clients kick <ClientId> | Kick out a MQTT client |
  145. +-------------------------+----------------------------------+
  146. clients lists
  147. -------------
  148. Query All MQTT clients connected to the broker::
  149. $ ./bin/emqttd_ctl clients list
  150. Client(mosqsub/43832-airlee.lo, clean_sess=true, username=test, peername=127.0.0.1:64896, connected_at=1452929113)
  151. Client(mosqsub/44011-airlee.lo, clean_sess=true, username=test, peername=127.0.0.1:64961, connected_at=1452929275)
  152. ...
  153. Properties of the Client:
  154. +--------------+---------------------------------------------------+
  155. | clean_sess | Clean Session Flag |
  156. +--------------+---------------------------------------------------+
  157. | username | Username of the client |
  158. +--------------+---------------------------------------------------+
  159. | peername | Peername of the TCP connection |
  160. +--------------+---------------------------------------------------+
  161. | connected_at | The timestamp when client connected to the broker |
  162. +--------------+---------------------------------------------------+
  163. clients show <ClientId>
  164. -----------------------
  165. Show a specific MQTT Client::
  166. ./bin/emqttd_ctl clients show "mosqsub/43832-airlee.lo"
  167. Client(mosqsub/43832-airlee.lo, clean_sess=true, username=test, peername=127.0.0.1:64896, connected_at=1452929113)
  168. clients kick <ClientId>
  169. -----------------------
  170. Kick out a MQTT Client::
  171. ./bin/emqttd_ctl clients kick "clientid"
  172. .. _command_sessions::
  173. --------
  174. sessions
  175. --------
  176. Query all MQTT sessions. The broker will create a session for each MQTT client. Persistent Session if clean_session flag is true, transient session otherwise.
  177. +--------------------------+-------------------------------+
  178. | sessions list | List all Sessions |
  179. +--------------------------+-------------------------------+
  180. | sessions list persistent | Query all persistent Sessions |
  181. +--------------------------+-------------------------------+
  182. | sessions list transient | Query all transient Sessions |
  183. +--------------------------+-------------------------------+
  184. | sessions show <ClientId> | Show a session |
  185. +--------------------------+-------------------------------+
  186. sessions list
  187. -------------
  188. Query all sessions::
  189. $ ./bin/emqttd_ctl sessions list
  190. Session(clientid, clean_sess=false, max_inflight=100, inflight_queue=0, message_queue=0, message_dropped=0, awaiting_rel=0, awaiting_ack=0, awaiting_comp=0, created_at=1452935508)
  191. Session(mosqsub/44101-airlee.lo, clean_sess=true, max_inflight=100, inflight_queue=0, message_queue=0, message_dropped=0, awaiting_rel=0, awaiting_ack=0, awaiting_comp=0, created_at=1452935401)
  192. Properties of Session:
  193. TODO:??
  194. +-------------------+----------------------------------------------------------------+
  195. | clean_sess | clean sess flag. false: persistent, true: transient |
  196. +-------------------+----------------------------------------------------------------+
  197. | max_inflight | Inflight window (Max number of messages delivering) |
  198. +-------------------+----------------------------------------------------------------+
  199. | inflight_queue | Inflight Queue Size |
  200. +-------------------+----------------------------------------------------------------+
  201. | message_queue | Message Queue Size |
  202. +-------------------+----------------------------------------------------------------+
  203. | message_dropped | Number of Messages Dropped for queue is full |
  204. +-------------------+----------------------------------------------------------------+
  205. | awaiting_rel | The number of QoS2 messages received and waiting for PUBREL |
  206. +-------------------+----------------------------------------------------------------+
  207. | awaiting_ack | The number of QoS1/2 messages delivered and waiting for PUBACK |
  208. +-------------------+----------------------------------------------------------------+
  209. | awaiting_comp | The number of QoS2 messages delivered and waiting for PUBCOMP |
  210. +-------------------+----------------------------------------------------------------+
  211. | created_at | Timestamp when the session is created |
  212. +-------------------+----------------------------------------------------------------+
  213. sessions list persistent
  214. ------------------------
  215. Query all persistent sessions::
  216. $ ./bin/emqttd_ctl sessions list persistent
  217. Session(clientid, clean_sess=false, max_inflight=100, inflight_queue=0, message_queue=0, message_dropped=0, awaiting_rel=0, awaiting_ack=0, awaiting_comp=0, created_at=1452935508)
  218. sessions list transient
  219. -----------------------
  220. Query all transient sessions::
  221. $ ./bin/emqttd_ctl sessions list transient
  222. Session(mosqsub/44101-airlee.lo, clean_sess=true, max_inflight=100, inflight_queue=0, message_queue=0, message_dropped=0, awaiting_rel=0, awaiting_ack=0, awaiting_comp=0, created_at=1452935401)
  223. sessions show <ClientId>
  224. ------------------------
  225. Show a session::
  226. $ ./bin/emqttd_ctl sessions show clientid
  227. Session(clientid, clean_sess=false, max_inflight=100, inflight_queue=0, message_queue=0, message_dropped=0, awaiting_rel=0, awaiting_ack=0, awaiting_comp=0, created_at=1452935508)
  228. .. _command_topics::
  229. ------
  230. topics
  231. ------
  232. Query topic table of the broker.
  233. topics list
  234. -----------
  235. Query all the topics::
  236. $ ./bin/emqttd_ctl topics list
  237. topic1: ['emqttd2@127.0.0.1']
  238. topic2: ['emqttd1@127.0.0.1','emqttd2@127.0.0.1']
  239. topics show <Topic>
  240. -------------------
  241. Show a topic::
  242. $ ./bin/emqttd_ctl topics show topic2
  243. topic2: ['emqttd1@127.0.0.1','emqttd2@127.0.0.1']
  244. The result will show which nodes the topic is on.
  245. .. _command_subscriptions::
  246. -------------
  247. subscriptions
  248. -------------
  249. Query the subscription table of the broker:
  250. +--------------------------------------------+--------------------------------------+
  251. | subscriptions list | List all subscriptions |
  252. +--------------------------------------------+--------------------------------------+
  253. | subscriptions show <ClientId> | Show a subscription |
  254. +--------------------------------------------+--------------------------------------+
  255. | subscriptions add <ClientId> <Topic> <Qos> | Add a static subscription manually |
  256. +--------------------------------------------+--------------------------------------+
  257. | subscriptions del <ClientId> <Topic> | Remove a static subscription manually|
  258. +--------------------------------------------+--------------------------------------+
  259. subscriptions list
  260. ------------------
  261. Query all subscriptions::
  262. $ ./bin/emqttd_ctl subscriptions list
  263. mosqsub/45744-airlee.lo: [{<<"y">>,0},{<<"x">>,0}]
  264. subscriptions show <ClientId>
  265. -----------------------------
  266. Show the subscriptions of a MQTT client::
  267. $ ./bin/emqttd_ctl subscriptions show clientid
  268. clientid: [{<<"x">>,1},{<<"topic2">>,1},{<<"topic3">>,1}]
  269. subscriptions add <ClientId> <Topic> <QoS>
  270. ------------------------------------------
  271. Add a static subscription manually::
  272. $ ./bin/emqttd_ctl subscriptions add clientid new_topic 1
  273. ok
  274. subscriptions del <ClientId> <Topic>
  275. ------------------------------------
  276. Remove a static subscription manually::
  277. $ ./bin/emqttd_ctl subscriptions del clientid new_topic
  278. ok
  279. .. _command_plugins::
  280. -------
  281. plugins
  282. -------
  283. List, load or unload plugins of emqttd broker.
  284. +---------------------------+-------------------------+
  285. | plugins list | List all plugins |
  286. +---------------------------+-------------------------+
  287. | plugins load <Plugin> | Load Plugin |
  288. +---------------------------+-------------------------+
  289. | plugins unload <Plugin> | Unload (Plugin) |
  290. +---------------------------+-------------------------+
  291. plugins list
  292. ------------
  293. List all plugins::
  294. $ ./bin/emqttd_ctl plugins list
  295. Plugin(emqttd_dashboard, version=0.16.0, description=emqttd web dashboard, active=true)
  296. Plugin(emqttd_plugin_mysql, version=0.16.0, description=emqttd Authentication/ACL with MySQL, active=false)
  297. Plugin(emqttd_plugin_pgsql, version=0.16.0, description=emqttd PostgreSQL Plugin, active=false)
  298. Plugin(emqttd_plugin_redis, version=0.16.0, description=emqttd Redis Plugin, active=false)
  299. Plugin(emqttd_plugin_template, version=0.16.0, description=emqttd plugin template, active=false)
  300. Plugin(emqttd_recon, version=0.16.0, description=emqttd recon plugin, active=false)
  301. Plugin(emqttd_stomp, version=0.16.0, description=Stomp Protocol Plugin for emqttd broker, active=false)
  302. Properties of a plugin:
  303. +-------------+--------------------------+
  304. | version | Plugin Version |
  305. +-------------+--------------------------+
  306. | description | Plugin Description |
  307. +-------------+--------------------------+
  308. | active | If the plugin is Loaded |
  309. +-------------+--------------------------+
  310. load <Plugin>
  311. -------------
  312. Load a Plugin::
  313. $ ./bin/emqttd_ctl plugins load emqttd_recon
  314. Start apps: [recon,emqttd_recon]
  315. Plugin emqttd_recon loaded successfully.
  316. unload <Plugin>
  317. ---------------
  318. Unload a Plugin::
  319. $ ./bin/emqttd_ctl plugins unload emqttd_recon
  320. Plugin emqttd_recon unloaded successfully.
  321. .. _command_bridges::
  322. -------
  323. bridges
  324. -------
  325. Bridge two or more emqttd brokers::
  326. --------- ---------
  327. Publisher --> | node1 | --Bridge Forward--> | node2 | --> Subscriber
  328. --------- ---------
  329. commands for bridge:
  330. +----------------------------------------+------------------------------+
  331. | bridges list | List all bridges |
  332. +----------------------------------------+------------------------------+
  333. | bridges options | Show bridge options |
  334. +----------------------------------------+------------------------------+
  335. | bridges start <Node> <Topic> | Create a bridge |
  336. +----------------------------------------+------------------------------+
  337. | bridges start <Node> <Topic> <Options> | Create a bridge with options |
  338. +----------------------------------------+------------------------------+
  339. | bridges stop <Node> <Topic> | Delete a bridge |
  340. +----------------------------------------+------------------------------+
  341. Suppose we create a bridge between emqttd1 and emqttd2 on localhost:
  342. +---------+---------------------+-----------+
  343. | Name | Node | MQTT Port |
  344. +---------+---------------------+-----------+
  345. | emqttd1 | emqttd1@127.0.0.1 | 1883 |
  346. +---------+---------------------+-----------+
  347. | emqttd2 | emqttd2@127.0.0.1 | 2883 |
  348. +---------+---------------------+-----------+
  349. The bridge will forward all the the 'sensor/#' messages from emqttd1 to emqttd2::
  350. $ ./bin/emqttd_ctl bridges start emqttd2@127.0.0.1 sensor/#
  351. bridge is started.
  352. $ ./bin/emqttd_ctl bridges list
  353. bridge: emqttd1@127.0.0.1--sensor/#-->emqttd2@127.0.0.1
  354. The the 'emqttd1--sensor/#-->emqttd2' bridge::
  355. #emqttd2 node
  356. mosquitto_sub -t sensor/# -p 2883 -d
  357. #emqttd1节点上
  358. mosquitto_pub -t sensor/1/temperature -m "37.5" -d
  359. bridges options
  360. ---------------
  361. Show bridge options::
  362. $ ./bin/emqttd_ctl bridges options
  363. Options:
  364. qos = 0 | 1 | 2
  365. prefix = string
  366. suffix = string
  367. queue = integer
  368. Example:
  369. qos=2,prefix=abc/,suffix=/yxz,queue=1000
  370. bridges stop <Node> <Topic>
  371. ---------------------------
  372. Delete the emqttd1--sensor/#-->emqttd2 bridge::
  373. $ ./bin/emqttd_ctl bridges stop emqttd2@127.0.0.1 sensor/#
  374. bridge is stopped.
  375. .. _command_vm::
  376. --
  377. vm
  378. --
  379. Query the load, cpu, memory, processes and IO information of the Erlang VM.
  380. +-------------+-----------------------------------+
  381. | vm all | Query all |
  382. +-------------+-----------------------------------+
  383. | vm load | Query VM Load |
  384. +-------------+-----------------------------------+
  385. | vm memory | Query Memory Usage |
  386. +-------------+-----------------------------------+
  387. | vm process | Query Number of Erlang Processes |
  388. +-------------+-----------------------------------+
  389. | vm io | Query Max Fds of VM |
  390. +-------------+-----------------------------------+
  391. vm load
  392. -------
  393. Query load::
  394. $ ./bin/emqttd_ctl vm load
  395. cpu/load1 : 2.21
  396. cpu/load5 : 2.60
  397. cpu/load15 : 2.36
  398. vm memory
  399. ---------
  400. Query memory::
  401. $ ./bin/emqttd_ctl vm memory
  402. memory/total : 23967736
  403. memory/processes : 3594216
  404. memory/processes_used : 3593112
  405. memory/system : 20373520
  406. memory/atom : 512601
  407. memory/atom_used : 491955
  408. memory/binary : 51432
  409. memory/code : 13401565
  410. memory/ets : 1082848
  411. vm process
  412. ----------
  413. Query number of erlang processes::
  414. $ ./bin/emqttd_ctl vm process
  415. process/limit : 8192
  416. process/count : 221
  417. vm io
  418. -----
  419. Query max, active file descriptors of IO::
  420. $ ./bin/emqttd_ctl vm io
  421. io/max_fds : 2560
  422. io/active_fds : 1
  423. .. _command_trace::
  424. -----
  425. trace
  426. -----
  427. Trace MQTT packets, messages(sent/received) by ClientId or Topic.
  428. +-----------------------------------+-----------------------------------+
  429. | trace list | List all the traces |
  430. +-----------------------------------+-----------------------------------+
  431. | trace client <ClientId> <LogFile> | Trace a client |
  432. +-----------------------------------+-----------------------------------+
  433. | trace client <ClientId> off | Stop tracing the client |
  434. +-----------------------------------+-----------------------------------+
  435. | trace topic <Topic> <LogFile> | Trace a topic |
  436. +-----------------------------------+-----------------------------------+
  437. | trace topic <Topic> off | Stop tracing the topic |
  438. +-----------------------------------+-----------------------------------+
  439. trace client <ClientId> <LogFile>
  440. ---------------------------------
  441. Start to trace a client::
  442. $ ./bin/emqttd_ctl trace client clientid log/clientid_trace.log
  443. trace client clientid successfully.
  444. trace client <ClientId> off
  445. ---------------------------
  446. Stop tracing the client::
  447. $ ./bin/emqttd_ctl trace client clientid off
  448. stop tracing client clientid successfully.
  449. trace topic <Topic> <LogFile>
  450. -----------------------------
  451. Start to trace a topic::
  452. $ ./bin/emqttd_ctl trace topic topic log/topic_trace.log
  453. trace topic topic successfully.
  454. trace topic <Topic> off
  455. -----------------------
  456. Stop tracing the topic::
  457. $ ./bin/emqttd_ctl trace topic topic off
  458. stop tracing topic topic successfully.
  459. trace list
  460. ----------
  461. List all traces::
  462. $ ./bin/emqttd_ctl trace list
  463. trace client clientid -> log/clientid_trace.log
  464. trace topic topic -> log/topic_trace.log
  465. .. _command_listeners::
  466. ---------
  467. listeners
  468. ---------
  469. Show all the TCP listeners::
  470. $ ./bin/emqttd_ctl listeners
  471. listener on http:8083
  472. acceptors : 4
  473. max_clients : 64
  474. current_clients : 0
  475. shutdown_count : []
  476. listener on mqtts:8883
  477. acceptors : 4
  478. max_clients : 512
  479. current_clients : 0
  480. shutdown_count : []
  481. listener on mqtt:1883
  482. acceptors : 16
  483. max_clients : 8192
  484. current_clients : 1
  485. shutdown_count : [{closed,1}]
  486. listener on http:18083
  487. acceptors : 4
  488. max_clients : 512
  489. current_clients : 0
  490. shutdown_count : []
  491. listener parameters:
  492. +-----------------+--------------------------------------+
  493. | acceptors | TCP Acceptor Pool |
  494. +-----------------+--------------------------------------+
  495. | max_clients | Max number of clients |
  496. +-----------------+--------------------------------------+
  497. | current_clients | Count of current clients |
  498. +-----------------+--------------------------------------+
  499. | shutdown_count | Statistics of client shutdown reason |
  500. +-----------------+---------------------------------------+
  501. .. _command_mnesia::
  502. ------
  503. mnesia
  504. ------
  505. Show system_info of mnesia database.