Command line interface

    Query the running status of EMQX Broker:

    mgmt command

    The mgmt command can query the application.

    List application

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

    mgmt insert <AppId> <Name>

    Add the HTTP API application:

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

    mgmt update <AppId> <status>

    Update the HTTP API application:

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

    mgmt lookup <AppId>

    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 <AppId>

    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 EMQX Broker description, version, start time
    broker statsStatistics of Connection, Session, Topic, Subscription, Route
    broker metricsQuery MQTT Packet and Message Statistics

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

    1. $ ./bin/emqx_ctl broker
    2. sysdescr : EMQX 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. channels.count : 0
    3. channels.max : 0
    4. connections.count : 0
    5. connections.max : 0
    6. resources.count : 0
    7. resources.max : 0
    8. retained.count : 3
    9. retained.max : 3
    10. routes.count : 0
    11. routes.max : 0
    12. sessions.count : 0
    13. sessions.max : 0
    14. suboptions.count : 0
    15. suboptions.max : 0
    16. subscribers.count : 0
    17. subscribers.max : 0
    18. subscriptions.count : 0
    19. subscriptions.max : 0
    20. subscriptions.shared.count : 0
    21. subscriptions.shared.max : 0
    22. topics.count : 0
    23. topics.max : 0

    broker metrics

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

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

    cluster command

    The cluster command is used to manage a cluster of multiple EMQX 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 can firstly start a two-node cluster on the local machine, which is called pseudo-distributed starting mode. Since we need to start two nodes on one machine, we must adjust the listening port of the other node to avoid the port conflicts.

    The basic process is to copy another emqx folder and name it emqx2. After that, we let all the listening ports of the original emqx to be added by an offset as the listening ports of the emqx2 node. For example, we can change the MQTT/TCP listening port from the default 1883 to 2883 as the MQTT/TCP listening port for emqx2. Please refer to regarding to the above operations and also refer to Configuration Instructions and 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 - 图2 (opens new window) client developed by the EMQX 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 EMQX 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:

    CommandsDescription
    acl cache-clean allClears acl cache on all nodes
    acl cache-clean node <Node>Clears acl cache on given node
    acl cache-clean <ClientId>Clears 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 EMQX 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 <ClientId>

    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 <ClientId>

    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 EMQX 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. t2/# -> emqx2@127.0.0.1
    2. t/+/x -> emqx2@127.0.0.1,emqx@127.0.0.1

    routes show <Topic>

    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

    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 <ClientId>

    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 <ClientId> <Topic> <QoS>

    Add subscription relationship manually:

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

    subscriptions del <ClientId> <Topic>

    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. EMQX 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=EMQX Authentication/ACL with HTTP API, active=false)
    4. Plugin(emqx_auth_jwt, description=EMQX Authentication with JWT, active=false)
    5. Plugin(emqx_auth_ldap, description=EMQX Authentication/ACL with LDAP, active=false)
    6. ...

    Plugin properties:

    plugins load <Plugin> {#load_plugin}

    Load plugin:

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

    plugins unload <Plugin>

    Unload plugin:

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

    Reload plugin:

    modules command

    Since v4.1 we have introduced the modules command to manage EMQX’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=EMQX Delayed Publish Module, active=false)
    3. Module(emqx_mod_topic_metrics, description=EMQX Topic Metrics Module, active=false)
    4. Module(emqx_mod_subscription, description=EMQX Subscription Module, active=false)
    5. Module(emqx_mod_acl_internal, description=EMQX Internal ACL Module, active=true)
    6. Module(emqx_mod_rewrite, description=EMQX Topic Rewrite Module, active=false)
    7. Module(emqx_mod_presence, description=EMQX Presence Module, active=true)

    modules load

    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 logger (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 Handlers currently installed
    log handlers set-level <HandlerId> <Level>Set the log level with the specified Handler

    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 <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 <Level>

    Set the primary log level:

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

    log handlers list

    View all Handlers 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 <HandlerId> <Level>

    Set the log level with the specified Handler:

    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 .

    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 <ClientId> <File> [ <Level> ]

    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 <ClientId>

    Stop client trace:

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

    trace start topic <Topic> <File> [ <Level> ]

    Start Topic trace:

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

    trace stop topic <Topic>

    Stop Topic trace:

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

    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")

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

    CommandDescription
    listeners# List listeners
    listeners stop <Identifier># Stop a listener
    listeners stop <Proto> <Port># Stop a listener
    listeners restart <Identifier># 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 <Identifier>

    Stop listener:

    1. $ ./bin/emqx_ctl listeners stop mqtt:tcp:external

    listeners restart <Identifier>

    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 EMQX 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 memory
    recon allocatedrecon_alloc:memory (allocated_types, current/max) (opens new window)
    recon bin_leak
    recon node_statsrecon:node_stats_print(10, 1000) (opens new window)
    recon remote_load Mod
    recon proc_count Attr Nrecon:proc_count(Attr, N) (opens new window)

    Visit 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 <Topic>

    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.

    admins add <Username> <Password> <Tags>

    Create admin account:

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

    admins passwd <Username> <Password>

    Reset admin password:

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

    admins del <Username>

    Delete admin account:

    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 EMQX Broker (called system built-in actions) or be written by EMQX 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

    • -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 EMQX Broker (called system built-in resource type) or be written by EMQX 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')

    Rule status and statistical indicators

    • 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

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

    EMQX 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
    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 clientid <Clientid>Lookup clientid acl detail
    acl show username <Username>Lookup username acl detail
    acl aad clientid <Clientid> <Topic> <Action> <Access>Add clientid acl
    acl add Username <Username> <Topic> <Action> <Access>Add username acl
    acl add _all <Topic> <Action> <Access>Add $all acl
    acl del clientid <Clientid> <Topic>Delete clientid acl
    acl del username <Username> <Topic>Delete username acl
    acl del _all <Topic>Delete $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

    • acl del _all <Topic>

      Delete $all acl

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

    The pem_cache command is used to clear the cache of all PEM certificates. For example, after some new trusted certificates are added to cacertfile or server certificate certfile renewal for SSL listeners, you can use this command to make the new certificate file take effect instead of restarting EMQX’s SSL listener.

    NOTE The updates of the cache do not affect currently established TLS connections.

    CommandDescription
    pem_cache cleanClears x509 certificate cache on all nodes
    Clears x509 certificate cache on given node

    TIP

    This command was introduced in v4.3.13. It was not supported in any version prior to this.