commands.rst 21 KB

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