Command line interface

EMQ X Broker provides the management command line of ./bin/emqx_ctl for users to manage, configure and query EMQ X Broker.

status command

Query the running status of EMQ X Broker:

  1. $ ./bin/emqx_ctl status
  2. Node 'emqx@127.0.0.1' is started
  3. emqx v4.0.0 is running

mgmt command

The mgmt command can query the application.

CommandDescription
mgmt listList application
mgmt insert <AppId> <Name>Add an application that can access to the HTTP API
mgmt update <AppId> <status>Update applications that can access to the HTTP API
mgmt lookup <AppId>Get application details that can access to the HTTP API
mgmt delete <AppId>Remove applications that can access to the HTTP API

mgmt list

List application

  1. $ ./bin/emqx_ctl mgmt list
  2. app_id: 901abdba8eb8c, secret: MjgzMzQ5MjM1MzUzMTc4MjgyMjE3NzU4ODcwMDg0NjQ4OTG, name: hello, desc: , status: true, expired: undefined

mgmt insert

Add the HTTP API application:

  1. $ ./bin/emqx_ctl mgmt insert dbcb6e023370b world
  2. AppSecret: MjgzMzQ5MjYyMTY3ODk4MjA5NzMwODExODMxMDM1NDk0NDA

mgmt update

Update the HTTP API application:

  1. $ ./bin/emqx_ctl mgmt update dbcb6e023370b stop
  2. update successfully.

mgmt lookup

Get application details of the HTTP API:

  1. $ ./bin/emqx_ctl mgmt lookup dbcb6e023370b
  2. app_id: dbcb6e023370b
  3. secret: MjgzMzQ5MjYyMTY3ODk4MjA5NzMwODExODMxMDM1NDk0NDA
  4. name: world
  5. desc: Application user
  6. status: stop
  7. expired: undefined

mgmt delete

Remove the HTTP API application:

  1. $ ./bin/emqx_ctl mgmt delete dbcb6e023370b
  2. ok

broker command

The broker command queries basic server information, startup time, statistics data and performance data.

CommandDescription
brokerQuery EMQ X Broker description, version, start time
broker statsStatistics of Connection, Session, Topic, Subscription, Route
broker metricsQuery MQTT Packet and Message Statistics

Query basic information of EMQ X Broker, including version, startup time, etc .:

  1. $ ./bin/emqx_ctl broker
  2. sysdescr : EMQ X Broker
  3. version : 4.0.0
  4. uptime : 4 minutes, 52 seconds
  5. datetime : 2020-02-21 09:39:58

broker stats

Query statistics of connections, topics, subscriptions, routes between server and client :

  1. $ ./bin/emqx_ctl broker stats
  2. actions.count : 5
  3. actions.max : 5
  4. channels.count : 0
  5. channels.max : 0
  6. connections.count : 0
  7. connections.max : 0
  8. resources.count : 0
  9. resources.max : 0
  10. retained.count : 3
  11. retained.max : 3
  12. routes.count : 0
  13. routes.max : 0
  14. rules.count : 0
  15. rules.max : 0
  16. sessions.count : 0
  17. sessions.max : 0
  18. suboptions.count : 0
  19. suboptions.max : 0
  20. subscribers.count : 0
  21. subscribers.max : 0
  22. subscriptions.count : 0
  23. subscriptions.max : 0
  24. subscriptions.shared.count : 0
  25. subscriptions.shared.max : 0
  26. topics.count : 0
  27. topics.max : 0

broker metrics

Query server traffic (Bytes), MQTT Packets, messages sending and receiving statistics:

  1. $ ./bin/emqx_ctl broker metrics
  2. actions.success : 0
  3. bytes.received : 0
  4. bytes.sent : 0
  5. client.auth.anonymous : 0
  6. client.authenticate : 0
  7. client.check_acl : 0
  8. client.connack : 0
  9. client.connect : 0
  10. client.connected : 0
  11. client.disconnected : 0
  12. client.subscribe : 0
  13. client.unsubscribe : 0
  14. delivery.dropped : 0
  15. delivery.dropped.expired : 0
  16. delivery.dropped.no_local : 0
  17. delivery.dropped.qos0_msg : 0
  18. delivery.dropped.queue_full : 0
  19. delivery.dropped.too_large : 0
  20. messages.acked : 0
  21. messages.delayed : 0
  22. messages.delivered : 0
  23. messages.dropped : 0
  24. messages.dropped.expired : 0
  25. messages.dropped.no_subscriber: 0
  26. messages.forward : 0
  27. messages.publish : 0
  28. messages.qos0.received : 0
  29. messages.qos0.sent : 0
  30. messages.qos1.received : 0
  31. messages.qos1.sent : 0
  32. messages.qos2.received : 0
  33. messages.qos2.sent : 0
  34. messages.received : 0
  35. messages.retained : 3
  36. messages.sent : 0
  37. packets.auth.received : 0
  38. packets.auth.sent : 0
  39. packets.connack.auth_error : 0
  40. packets.connack.error : 0
  41. packets.connack.sent : 0
  42. packets.connect.received : 0
  43. packets.disconnect.received : 0
  44. packets.disconnect.sent : 0
  45. packets.pingreq.received : 0
  46. packets.pingresp.sent : 0
  47. packets.puback.inuse : 0
  48. packets.puback.missed : 0
  49. packets.puback.received : 0
  50. packets.puback.sent : 0
  51. packets.pubcomp.inuse : 0
  52. packets.pubcomp.missed : 0
  53. packets.pubcomp.received : 0
  54. packets.pubcomp.sent : 0
  55. packets.publish.auth_error : 0
  56. packets.publish.dropped : 0
  57. packets.publish.error : 0
  58. packets.publish.received : 0
  59. packets.publish.sent : 0
  60. packets.pubrec.inuse : 0
  61. packets.pubrec.missed : 0
  62. packets.pubrec.received : 0
  63. packets.pubrec.sent : 0
  64. packets.pubrel.missed : 0
  65. packets.pubrel.received : 0
  66. packets.pubrel.sent : 0
  67. packets.received : 0
  68. packets.sent : 0
  69. packets.suback.sent : 0
  70. packets.subscribe.auth_error : 0
  71. packets.subscribe.error : 0
  72. packets.subscribe.received : 0
  73. packets.unsuback.sent : 0
  74. packets.unsubscribe.error : 0
  75. packets.unsubscribe.received : 0
  76. rules.matched : 0
  77. session.created : 0
  78. session.discarded : 0
  79. session.resumed : 0
  80. session.takeovered : 0
  81. session.terminated : 0

cluster command

The cluster command is used to manage a cluster of multiple EMQ X Broker nodes (processes):

CommandDescription
cluster join <Node>Join the cluster
`cluster leaveLeave the cluster
cluster force-leave <Node>Remove nodes from the cluster
cluster statusQuery cluster status

Example:

To demonstrate the cluster command in a better way, we first start two nodes on the local machine and create a cluster. To avoid port conflicts, we have adjusted the listening port of the emqx2 node. For example, the MQTT/TCP listening port was changed from the default 1883 to 2883. Please refer to Configuration Instructions and Configuration Items for details.

Start emqx1 :

  1. $ cd emqx1 && ./bin/emqx start

Start emqx2 :

  1. $ cd emqx2 && ./bin/emqx start

Use cluster join <Node> to combine two nodes into one cluster:

  1. $ cd emqx2 && ./bin/emqx_ctl cluster join emqx1@127.0.0.1
  2. Join the cluster successfully.
  3. Cluster status: [{running_nodes,['emqx1@127.0.0.1','emqx2@127.0.0.1']}]

Query the cluster status in any node directory:

  1. $ ./bin/emqx_ctl cluster status
  2. Cluster status: [{running_nodes,['emqx2@127.0.0.1','emqx1@127.0.0.1']}]

Cluster message routing test: The MQTT command line tool uses the emqttCLI - 图1 (opens new window) client developed by the EMQ X team.

  1. # emqx1 node (port 1883) subscribed topic x
  2. $ ./bin/emqtt sub -t x -q 1 -p 1883
  3. Client emqtt-a7de8fffbe2fbeb2fadb sent CONNECT
  4. Client emqtt-a7de8fffbe2fbeb2fadb subscribed to x
  5. # Published message to emqx2 node (port 2883)
  6. $ ./bin/emqtt pub -t x -q 1 -p 2883 --payload hello
  7. Client emqtt-0898fa447676e17479a5 sent CONNECT
  8. Client emqtt-0898fa447676e17479a5 sent PUBLISH (Q1, R0, D0, Topic=x, Payload=...(5 bytes))
  9. Client emqtt-0898fa447676e17479a5 sent DISCONNECT
  10. # received a message by emqx1 node (port 1883)
  11. $ ./bin/emqtt sub -t x -q 1 -p 1883
  12. hello

emqx2 nodes leave the cluster:

  1. $ cd emqx2 && ./bin/emqx_ctl cluster leave

emqx2 node is forced to leave the cluster, and you need to perform operations on nodes other than the target node under the cluster:

  1. $ cd emqx1 && ./bin/emqx_ctl cluster force-leave emqx2@127.0.0.1

It is Noted that EMQ X Broker does not support joining a node that is already in a cluster to another cluster. That is because this will cause the data of the two clusters to be inconsistent. However, it supports nodes that have joined the cluster to join another cluster after leaving the cluster.

acl command

Since v4.1 the command modules has been introduced and we reload the ACLs using the following command:

  1. $ ./bin/emqx_ctl modules reload emqx_mod_acl_internal
  2. Module emqx_mod_acl_internal reloaded successfully.

Prior to v4.1, still use:

  1. $ ./bin/emqx_ctl acl reload
  2. ok

acl cache-clean

After v4.3, the command to clean up the ACL cache has been introduced:

CommadsDescription
acl cache-clean allClears acl cache on all nodes
acl cache-clean nodeClears acl cache on given node
acl cache-cleanClears acl cache for given client

clients command

The clients command can query the connected MQTT clients.

CommandDescription
clients listList all client connections
clients show <ClientId>Query the client with the specified ClientId
clients kick <ClientId>Kick out the client with the specified ClientId, and the connection and session will be terminated together.

clients list

List all client connections:

  1. $ ./bin/emqx_ctl clients list
  2. Client (mosqsub/43832-airlee.lo, username=test1, peername=127.0.0.1:62135, clean_start=true, keepalive=60, session_expiry_interval=0, subscriptions=0, inflight=0, awaiting_rel=0, delivered_msgs=0, enqueued_msgs=0, dropped_msgs=0, connected=true, created_at=1582249657, connected_at=1582249657)
  3. Client (mosqsub/44011-airlee.lo, username=test2, peername=127.0.0.1:64961, clean_start=true, keepalive=60, session_expiry_interval=0, subscriptions=0, inflight=0, awaiting_rel=0, delivered_msgs=0, enqueued_msgs=0, dropped_msgs=0, connected=true, created_at=1582249657, connected_at=1582249657, disconnected_at=1582249702)
  4. ...

Return the properties of the Client object:

NameDescription
usernameUsername
peernameClient IP and port
clean_startMQTT Clean Start
keepaliveMQTT KeepAlive
session_expiry_intervalSession expiration interval
subscriptionsCurrent subscriptions
inflightTotal number of QoS 1 and QoS 2 messages currently being issued
awaiting_relNumber of QoS2 messages waiting for the client to send PUBREL
delivered_msgsNumber of messages forwarded by EMQ X Broker to this client (including retransmissions)
enqueued_msgsCurrent length of message queue
dropped_msgsNumber of messages dropped after the message queue reached the maximum length
connectedWhether online
created_atSession creation timestamp
connected_atClient connection timestamp
disconnected_atClient disconnection timestamp (appears only if the disconnection also retains the session)

clients show

Query the client with the specified ClientId:

  1. $ ./bin/emqx_ctl clients show "mosqsub/43832-airlee.lo"
  2. Client (mosqsub/43832-airlee.lo, username=test1, peername=127.0.0.1:62747, clean_start=false, keepalive=60, session_expiry_interval=7200, subscriptions=0, inflight=0, awaiting_rel=0, delivered_msgs=0, enqueued_msgs=0, dropped_msgs=0, connected=true, created_at=1576479557, connected_at=1576479557)

clients kick

Kick out the client with the specified ClientId:

  1. $ ./bin/emqx_ctl clients kick "clientid"
  2. ok

routes command

The routes command is used to query routing information.

In EMQ X Broker, route refers to the mapping of topics to nodes, which is used to route messages between multiple nodes.

CommandDescription
routes listList all routes
routes show <Topic>Query the route of the specified topic

routes list

List all routes:

  1. $ ./bin/emqx_ctl routes list
  2. t2/# -> emqx2@127.0.0.1
  3. t/+/x -> emqx2@127.0.0.1,emqx@127.0.0.1

routes show

Query the route with the specified topic:

  1. $ ./bin/emqx_ctl routes show t/+/x
  2. t/+/x -> emqx2@127.0.0.1,emqx@127.0.0.1

subscriptions command

The subscriptions command queries the subscription table of the message server.

CommandDescription
subscriptions listList all subscriptions
subscriptions show <ClientId>Query the subscription of the specified ClientId client
subscriptions add <ClientId> <Topic> <QoS>Add static subscriptions manually
subscriptions del <ClientId> <Topic>Delete static subscriptions manually

subscriptions list

List all subscriptions:

  1. $ ./bin/emqx_ctl subscriptions list
  2. mosqsub/91042-airlee.lo -> t/y:1
  3. mosqsub/90475-airlee.lo -> t/+/x:2

subscriptions show

Query certain client’s subscription:

  1. $ ./bin/emqx_ctl subscriptions show 'mosqsub/90475-airlee.lo'
  2. mosqsub/90475-airlee.lo -> t/+/x:2

subscriptions add

Add subscription relationship manually:

  1. $ ./bin/emqx_ctl subscriptions add 'mosqsub/90475-airlee.lo' '/world' 1
  2. ok

subscriptions del

Delete subscription relationship manually:

  1. $ ./bin/emqx_ctl subscriptions del 'mosqsub/90475-airlee.lo' '/world'
  2. ok

plugins command

The plugins command is used to load, unload, and query plugin applications. EMQ X Broker extends authentication and customization through plugins. The plugin configuration is located in the directory of etc/plugins/ .

CommandDescription
plugins listList all plugins
plugins load <Plugin>Load plugins
plugins unload <Plugin>Unload plugins
plugins reload <Plugin>Reload plugins

When the configuration file changesand it needs to take effect immediately, you can execute the emqx_ctl reload <Plugin \> command, even if the plugin is not running when the configuration is modified. You should use this command instead of emqx_ctl load <Plugin\> . Because emqx_ctl load <Plugin \> does not compile the new configuration file.

plugins list

List all plugins:

  1. $ ./bin/emqx_ctl plugins list
  2. ...
  3. Plugin(emqx_auth_http, description=EMQ X Authentication/ACL with HTTP API, active=false)
  4. Plugin(emqx_auth_jwt, description=EMQ X Authentication with JWT, active=false)
  5. Plugin(emqx_auth_ldap, description=EMQ X Authentication/ACL with LDAP, active=false)
  6. ...

Plugin properties:

NameDescription
versionPlugin version
descriptionPlugin description
activeWhether loaded

plugins load{#load_plugin}

Load plugin:

  1. $ ./bin/emqx_ctl plugins load emqx_lua_hook
  2. Plugin emqx_lua_hook loaded successfully.

plugins unload

Unload plugin:

  1. $ ./bin/emqx_ctl plugins unload emqx_lua_hook
  2. Plugin emqx_lua_hook unloaded successfully.

plugins reload

Reload plugin:

  1. $ ./bin/emqx_ctl plugins reload emqx_lua_hook
  2. Plugin emqx_lua_hook reloaded successfully.

modules command

Since v4.1 we have introduced the modules command to manage EMQ X’s built-in modules at runtime.

CommandDescription
modules listList all modules
modules load <Module>Load a module
modules unload <Module>Unload a module
modules reload <Module>Reload a module

modules list

Lists all built-in modules, including those that have not been started:

  1. $ ./bin/emqx_ctl modules list
  2. Module(emqx_mod_delayed, description=EMQ X Delayed Publish Module, active=false)
  3. Module(emqx_mod_topic_metrics, description=EMQ X Topic Metrics Module, active=false)
  4. Module(emqx_mod_subscription, description=EMQ X Subscription Module, active=false)
  5. Module(emqx_mod_acl_internal, description=EMQ X Internal ACL Module, active=true)
  6. Module(emqx_mod_rewrite, description=EMQ X Topic Rewrite Module, active=false)
  7. Module(emqx_mod_presence, description=EMQ X Presence Module, active=true)

modules load

Load a module:

  1. $ ./bin/emqx_ctl modules load emqx_mod_delayed
  2. Module emqx_mod_delayed loaded successfully.

modules unload

Unload a module:

  1. $ ./bin/emqx_ctl modules unload emqx_mod_delayed
  2. Module emqx_mod_delayed unloaded successfully.

modules reload

Reload a module:

  1. $ ./bin/emqx_ctl modules reload emqx_mod_acl_internal
  2. Module emqx_mod_acl_internal reloaded successfully.

vm command

The vm command is used to query information of Erlang virtual machine load, memory, process, and IO.

CommandDescription
vmEquivalent to vm all
vm allQuery all VM information
vm loadQuery VM load
vm memoryQuery VM memory
vm processQuery the number of VM Erlang processes
vm ioQuery maximum file handle of VM io
vm portsQuery the port of a VM

vm all

Query all VM information, including load, memory, number of Erlang processes, etc .:

  1. $ ./bin/emqx_ctl vm all
  2. cpu/load1 : 4.22
  3. cpu/load5 : 3.29
  4. cpu/load15 : 3.16
  5. memory/total : 99995208
  6. memory/processes : 38998248
  7. memory/processes_used : 38938520
  8. memory/system : 60996960
  9. memory/atom : 1189073
  10. memory/atom_used : 1173808
  11. memory/binary : 100336
  12. memory/code : 25439961
  13. memory/ets : 7161128
  14. process/limit : 2097152
  15. process/count : 315
  16. io/max_fds : 10240
  17. io/active_fds : 0
  18. ports/count : 18
  19. ports/limit : 1048576

vm load

Query VM load:

  1. $ ./bin/emqx_ctl vm load
  2. cpu/load1 : 2.21
  3. cpu/load5 : 2.60
  4. cpu/load15 : 2.36

vm memory

Query VM memory:

  1. $ ./bin/emqx_ctl vm memory
  2. memory/total : 23967736
  3. memory/processes : 3594216
  4. memory/processes_used : 3593112
  5. memory/system : 20373520
  6. memory/atom : 512601
  7. memory/atom_used : 491955
  8. memory/binary : 51432
  9. memory/code : 13401565
  10. memory/ets : 1082848

vm process

Query the number of Erlang processes and their limits:

  1. $ ./bin/emqx_ctl vm process
  2. process/limit : 2097152
  3. process/count : 314

vm io

Query the number of file descriptors and their limits:

  1. $ ./bin/emqx_ctl vm io
  2. io/max_fds : 10240
  3. io/active_fds : 0

vm ports

Query the number of occupied ports and their limits:

  1. $ ./bin/emqx_ctl vm ports
  2. ports/count : 18
  3. ports/limit : 1048576

mnesia command

Query the mnesia database system status.

log command

The log command is used to set the log level. Visit Documentation of loggerCLI - 图2 (opens new window) for more information in detail.

CommandDescription
log set-level <Level>Set the primary log level and all Handlers log levels
log primary-levelCheck the primary log level
log primary-lelvel <Level>Set the primary log level
log handlers listView all Hanlders currently installed
log handlers set-level <HandlerId> <Level>Set the log level with the specified Hanlder

The levels of the logs from low to high are: debug | info | notice | warning | error | critical | alert | emergency. The lower the log level, the more logs the system outputs, and the more system resources it consumes. To improve system performance, the default primary log level is error.

log set-level

Set the primary log level and all Handlers log levels

  1. $ ./bin/emqx_ctl log set-level debug
  2. debug

log primary-level

View the primary log level:

  1. $ ./bin/emqx_ctl log primary-level
  2. debug

log primary-level

Set the primary log level:

  1. $ ./bin/emqx_ctl log primary-level info
  2. info

log handlers list

View all Hanlders currently installed:

  1. $ ./bin/emqx_ctl log handlers list
  2. LogHandler (id=emqx_logger_handler, level=debug, destination=unknown)
  3. LogHandler (id=file, level=debug, destination=log/emqx.log)
  4. LogHandler (id=default, level=debug, destination=console)

log handlers set-level

Set the log level with the specified Hanlder:

  1. $ ./bin/emqx_ctl log handlers set-level emqx_logger_handler error
  2. error

trace command

The trace command is used to trace a client or topic, and print log information to a file. For details, see Log and Trace.

CommandDescription
trace listList all started traces
trace start client <ClientId> <File> [<Level>]Start client trace and store logs of specified level to a file
trace stop client <ClientId>Stop Client trace
trace start topic <Topic> <File> [<Level>]Start Topic trace and store logs of specified level to a file
trace stop topic <Topic>Stop Topic trace

trace start client[]

Start client trace:

  1. $ ./bin/emqx_ctl log primary-level debug
  2. debug
  3. $ ./bin/emqx_ctl trace start client clientid log/clientid_trace.log
  4. trace clientid clientid successfully
  5. $ ./bin/emqx_ctl trace start client clientid2 log/clientid2_trace.log error
  6. trace clientid clientid2 successfully

trace stop client

Stop client trace:

  1. $ ./bin/emqx_ctl trace stop client clientid
  2. stop tracing clientid clientid successfully

trace start topic[]

Start Topic trace:

  1. $ ./bin/emqx_ctl log primary-level debug
  2. debug
  3. $ ./bin/emqx_ctl trace start topic topic log/topic_trace.log
  4. trace topic topic successfully
  5. $ ./bin/emqx_ctl trace start topic topic2 log/topic2_trace.log error
  6. trace topic topic2 successfully

trace stop topic

Stop Topic trace:

  1. $ ./bin/emqx_ctl trace topic topic off
  2. stop tracing topic topic successfully

trace list

List all started traces:

  1. $ ./bin/emqx_ctl trace list
  2. Trace (clientid=clientid2, level=error, destination="log/clientid2_trace.log")
  3. Trace (topic=topic2, level=error, destination="log/topic2_trace.log")

listeners

The listeners command is used to query the active TCP service listeners.

CommandDescription
listeners# List listeners
listeners stop# Stop a listener
listeners stop# Stop a listener
listeners restart# Restart a listener

listeners list

Query the active TCP service listeners

  1. $ ./bin/emqx_ctl listeners
  2. mqtt:ssl:external
  3. listen_on : 0.0.0.0:8883
  4. acceptors : 16
  5. max_conns : 102400
  6. current_conn : 0
  7. shutdown_count : []
  8. mqtt:tcp:external
  9. listen_on : 0.0.0.0:1883
  10. acceptors : 8
  11. max_conns : 1024000
  12. current_conn : 0
  13. shutdown_count : []
  14. mqtt:tcp:internal
  15. listen_on : 127.0.0.1:11883
  16. acceptors : 4
  17. max_conns : 1024000
  18. current_conn : 0
  19. shutdown_count : []
  20. http:dashboard
  21. listen_on : 0.0.0.0:18083
  22. acceptors : 4
  23. max_conns : 512
  24. current_conn : 0
  25. shutdown_count : []
  26. http:management
  27. listen_on : 0.0.0.0:8081
  28. acceptors : 2
  29. max_conns : 512
  30. current_conn : 0
  31. shutdown_count : []
  32. mqtt:ws:external
  33. listen_on : 0.0.0.0:8083
  34. acceptors : 4
  35. max_conns : 102400
  36. current_conn : 0
  37. shutdown_count : []
  38. mqtt:wss:external
  39. listen_on : 0.0.0.0:8084
  40. acceptors : 4
  41. max_conns : 16
  42. current_conn : 0
  43. shutdown_count : []

listener parameter description:

NameDescription
acceptorsTCP Acceptor pool
max_connsMaximum allowed connections
current_connsCurrent connections
shutdown_countStatistics of connection shutdown reasons

listeners stop

Stop listener:

  1. $ ./bin/emqx_ctl listeners stop mqtt:tcp:external
  2. Stop listener mqtt:tcp:external successfully.

listeners restart

listeners restart

  1. $ ./bin/emqx_ctl listeners restart http:dashboard
  2. Stop http:dashboard listener on 0.0.0.0:18083 successfully.
  3. Start http:dashboard listener on 0.0.0.0:18083 successfully.

recon command

The recon command of EMQ X Broker is based on the Erlang Recon library, which is used to help DevOps staff to diagnose problems in the production node, and ordinary users do not need to care. The recon command will consume some performance, so, please use it with caution.

CommandDescription
recon memoryrecon_alloc:memory/2CLI - 图3 (opens new window)
recon allocatedrecon_alloc:memory (allocated_types, current/max)CLI - 图4 (opens new window)
recon bin_leakrecon:bin_leak (100)CLI - 图5 (opens new window)
recon node_statsrecon:node_stats_print(10, 1000)CLI - 图6 (opens new window)
recon remote_load Modrecon:remote_load (Mod)CLI - 图7 (opens new window)
recon proc_count Attr Nrecon:proc_count(Attr, N)CLI - 图8 (opens new window)

Visit Documentation for reconCLI - 图9 (opens new window) for more information.

retainer command

CommandDescription
retainer infoShow the number of retained messages
retainer topicsDisplay all topics of currently stored retained messages
retainer cleanClean all retained messages
retainer clean <Topic>Clean retained messages with the specified topic

retainer info

Show the number of retained messages:

  1. $ ./bin/emqx_ctl retainer info
  2. retained/total: 3

retainer topics

Show all topics of currently stored retained messages:

  1. $ ./bin/emqx_ctl retainer topics
  2. $SYS/brokers/emqx@127.0.0.1/version
  3. $SYS/brokers/emqx@127.0.0.1/sysdescr
  4. $SYS/brokers

retainer clean

Clear all retained messages:

  1. $ ./bin/emqx_ctl retainer clean
  2. Cleaned 3 retained messages

retainer clean

Clear the retained messages with the specified topic:

  1. $ ./bin/emqx_ctl retainer clean topic
  2. Cleaned 1 retained messages

admins command

It is used to create and delete administrator’s accounts and reset the administrator’s password.

CommandDescription
admins add <Username> <Password> <Tags>Create admin account
admins passwd <Username> <Password>Reset admin password
admins del <Username>Delete admin account

admins add

Create admin account:

  1. $ ./bin/emqx_ctl admins add root public test
  2. ok

admins passwd

Reset admin password:

  1. $ ./bin/emqx_ctl admins passwd root private
  2. ok

admins del

Delete admin account:

  1. $ ./bin/emqx_ctl admins del root
  2. ok

Rule engine command

rules command

CommandDescription
rules listList all rules
rules show <RuleId>Show a rule
rules create <sql> <actions> [-d [<descr>]]Create a rule
rules delete <RuleId>Delete a rule

rules create

Create a new rule with the following parameter:

  • <sql>: rule SQL
  • <actions>: Action list in JSON format
  • -d <descr>: Optional, rule description

Example

  1. ## Create a test rule to simply print the content of all messages sent to the 't / a' topic
  2. $ ./bin/emqx_ctl rules create \
  3. 'select * from "t/a"' \
  4. '[{"name":"inspect", "params": {"a": 1}}]' \
  5. -d 'Rule for debug'
  6. Rule rule:9a6a725d created

The above example creates a rule with the ID rule:9a6a725d. There is only one action in the action list with the name inspect, and the action parameters are {" a ": 1}.

rules list

List all current rules:

  1. $ ./bin/emqx_ctl rules list
  2. rule(id='rule:9a6a725d', for='['t/a']', rawsql='select * from "t/a"', actions=[{"metrics":...,"name":"inspect","params":...}], metrics=..., enabled='true', description='Rule for debug')

rules show

Query rules:

  1. ## Query rule with RuleID 'rule:9a6a725d'
  2. $ ./bin/emqx_ctl rules show 'rule:9a6a725d'
  3. rule(id='rule:9a6a725d', for='['t/a']', rawsql='select * from "t/a"', actions=[{"metrics":...,"name":"inspect","params":...}], metrics=..., enabled='true', description='Rule for debug')

rules delete

Delete rule:

  1. ## Delete rule with RuleID 'rule:9a6a725d'
  2. $ ./bin/emqx_ctl rules delete 'rule:9a6a725d'
  3. ok

rule-actions command

CommandDescription
rule-actions listList actions
rule-actions show <ActionId>Show a rule action

TIP

Actions can be built-in by EMQ X Broker (called system built-in actions) or be written by EMQ X Broker plugins, but cannot be added or removed through the CLI/API.

rule-actions show

Query action:

  1. ## Query action named 'inspect'
  2. $ ./bin/emqx_ctl rule-actions show 'inspect'
  3. action(name='inspect', app='emqx_rule_engine', types=[], title ='Inspect (debug)', description='Inspect the details of action params for debug purpose')

rule-actions list

List eligible actions:

  1. ## List all current actions
  2. $ ./bin/emqx_ctl rule-actions list
  3. action(name='data_to_rabbit', app='emqx_bridge_rabbit', types=[bridge_rabbit], title ='Data bridge to RabbitMQ', description='Store Data to Kafka')
  4. action(name='data_to_timescaledb', app='emqx_backend_pgsql', types=[timescaledb], title ='Data to TimescaleDB', description='Store data to TimescaleDB')
  5. ...

resources command

CommandDescription
resources create <type> [-c [<config>]] [-d [<descr>]]Create a resource
resources list [-t <ResourceType>]List resources
resources show <ResourceId>Show a resource
resources delete <ResourceId>Delete a resource

resources create

Create a new resource with the following parameters:

  • type: resource type

  • -c config: Configuration in JSON format

  • -d descr: Optional, description of the resource

    $ ./bin/emqx_ctl resources create ‘web_hook’ -c ‘{“url”: “http://host-name/chats"}‘ -d ‘forward msgs to host-name/chats’

    Resource resource:a7a38187 created

resources list

List all current resources:

  1. $ ./bin/emqx_ctl resources list
  2. resource(id='resource:a7a38187', type='web_hook', config=#{<<"url">> => <<"http://host-name/chats">>}, status=#{is_alive => false}, description='forward msgs to host-name/chats')

List resources of a certain type:

  1. $ ./bin/emqx_ctl resources list --type='web_hook'
  2. resource(id='resource:a7a38187', type='web_hook', config=#{<<"url">> => <<"http://host-name/chats">>}, status=#{is_alive => false}, description='forward msgs to host-name/chats')

resources show

Query resource:

  1. $ ./bin/emqx_ctl resources show 'resource:a7a38187'
  2. resource(id='resource:a7a38187', type='web_hook', config=#{<<"url">> => <<"http://host-name/chats">>}, status=#{is_alive => false}, description='forward msgs to host-name/chats')

resources delete

Delete resource:

  1. $ ./bin/emqx_ctl resources delete 'resource:a7a38187'
  2. ok

resource-types command

CommandDescription
resource-types listList all resource-types
resource-types show <Type>Show a resource-type

TIP

Resource type can be built-in by EMQ X Broker (called system built-in resource type) or be written by EMQ X Broker plugins, but cannot be added or removed through the CLI/API

resource-types list

List all current resource types:

  1. ./bin/emqx_ctl resource-types list
  2. resource_type(name='backend_mongo_rs', provider='emqx_backend_mongo', title ='MongoDB Replica Set Mode', description='MongoDB Replica Set Mode')
  3. resource_type(name='backend_cassa', provider='emqx_backend_cassa', title ='Cassandra', description='Cassandra Database')
  4. ...

resource-types show

Query resource type:

  1. $ ./bin/emqx_ctl resource-types show backend_mysql
  2. resource_type(name='backend_mysql', provider='emqx_backend_mysql', title ='MySQL', description='MySQL Database')

Status, statistical indicators and alerts related to the rules engine

Rule status and statistical indicators

image

  • Hits: number of rule hits (match succeed for rule SQL),
  • Hit Speed: Speed of rule hits (times/second)
  • Maximum hit speed: Peak value of hit speed (times/second)
  • 5 minute average speed: Average hit speed in 5 minutes (times/second)

Action status and statistical indicators

image

  • Success: Number of successful actions
  • Failure: Number of failed actions

Resource status and alerts

image

  • Available: Resources available
  • Unavailable: resources unavailable (e.g. database connection shutdown)

EMQ X Internal DB Auth/ACL

This command will only take effect when the emqx_auth_mnesia plug-in is turned on

clientid command

CommandDescription
clientid listList clientid auth rules
clientid add <ClientID> <Password>Add clientid auth rule
clientid update <ClientID> <Password>Update clientid auth rule
clientid del <ClientID> <Password>Delete clientid auth rule

clientid list

List clientid auth rules

  1. ./bin/emqx_ctl clientid list
  2. emqx

clientid add <ClientID> <Password>

Add clientid auth rule

  1. ./bin/emqx_ctl clientid add emqx public
  2. ok

clientid update <ClientID> <Password>

Update clientid auth rule

  1. ./bin/emqx_ctl clientid update emqx new_password
  2. ok

clientid del <ClientID> <Password>

Delete clientid auth rule

  1. ./bin/emqx_ctl clientid del emqx new_password
  2. ok

user command

CommandDescription
user listList username auth rules
user add <Username> <Password>Add username auth rule
user update <Username> <Password>Update username auth rule
user del <Username> <Password>Delete username auth rule

user list

List username auth rules

  1. ./bin/emqx_ctl user list
  2. emqx

user add <Username> <Password>

Add username auth rule

  1. ./bin/emqx_ctl user add emqx public
  2. ok

user update <Username> <Password>

Update username auth rule

  1. ./bin/emqx_ctl user update emqx new_password
  2. ok

user del <Username> <Password>

Delete username auth rule

  1. ./bin/emqx_ctl user del emqx new_password
  2. ok

acl command

CommandDescription
acl list clientidList clientid acls
acl list usernameList username acls
acl list _allList $all acls
acl show clientidLookup clientid acl detail
acl show usernameLookup username acl detail
acl aad clientidAdd clientid acl
acl add UsernameAdd username acl
acl add _allAdd $all acl
acl del clientidDelete clientid acl
acl del usernameDelete username acl
acl del _allDelete $all acl

acl list

  • acl list clientid

    List clientid acls

    1. ./bin/emqx_ctl acl list clientid
    2. Acl(clientid = <<"emqx_clientid">> topic = <<"Topic/A">> action = pub access = allow)
  • acl list username

    List username acls

    1. ./bin/emqx_ctl acl list username
    2. Acl(username = <<"emqx_username">> topic = <<"Topic/B">> action = sub access = deny)
  • acl list _all

    List $all acls

    1. ./bin/emqx_ctl acl list _all
    2. Acl($all topic = <<"Topic/C">> action = pubsub access = allow)

acl show

  • acl show clientid <Clientid>

    Lookup clientid acl detail

    1. ./bin/emqx_ctl acl show clientid emqx_clientid
    2. Acl(clientid = <<"emqx_clientid">> topic = <<"Topic/A">> action = pub access = allow)
  • acl show username <Username>

    Lookup username acl detail

    1. ./bin/emqx_ctl acl show username emqx_username
    2. Acl(username = <<"emqx_username">> topic = <<"Topic/B">> action = sub access = deny)

acl add

  • acl aad clientid <Clientid> <Topic> <Action> <Access>

    Add clientid acl

    1. ./bin/emqx_ctl acl add clientid emqx_clientid Topic/A pub allow
    2. ok
  • acl aad username <Username> <Topic> <Action> <Access>

    Add username acl

    1. ./bin/emqx_ctl acl add username emqx_username Topic/B sub deny
    2. ok
  • acl aad _all <Topic> <Action> <Access>

    Add $all acl

    1. ./bin/emqx_ctl acl add _all Topic/C pubsub allow
    2. ok

acl del

  • acl del clientid <Clientid> <Topic>

    Delete clientid acl

    1. ./bin/emqx_ctl acl del clientid emqx_clientid Topic/A
    2. ok
  • acl del username <Username> <Topic>

    Delete username acl

    1. ./bin/emqx_ctl acl del clientid emqx_username Topic/B
    2. ok
  • acl del _all <Topic>

    Delete $all acl

    1. ./bin/emqx_ctl acl del _all Topic/C
    2. ok