管理命令 (Commands)

EMQ X 消息服务器提供了 ./bin/emqx_ctl 的管理命令行。

status 命令

查询 EMQ X 消息服务器运行状态:

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

mgmt 命令

mgmt 命令查询应用程序。

mgmt list

列出应用程序列表

mgmt insert <AppId> <Name>

添加 REST API 的应用程序

mgmt update <AppId> <status>

更新 REST API 的应用程序

mgmt lookup <AppId>

获取 REST API 的应用程序详情

mgmt delete <AppId>

删除 REST API 的应用程序

mgmt list

列出应用程序列表:

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

mgmt insert <AppId> <Name>

添加REST API的应用程序:

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

mgmt update <AppId> <status>

更新 REST API 的应用程序:

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

mgmt lookup <AppId>

获取 REST 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>

删除REST API的应用程序:

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

broker 命令

broker 命令查询服务器基本信息,启动时间,统计数据与性能数据。

broker

查询 EMQ X 消息服务器描述、版本、启动时间

broker stats

查询连接(Connection)、会话(Session)、主题(Topic)、 订阅(Subscription)、路由(Route)统计信息

broker metrics

查询 MQTT 报文(Packet)、消息(Message)收发统计

查询 EMQ X 消息服务器基本信息包括版本、启动时间等:

  1. $ ./bin/emqx_ctl broker
  2. sysdescr : EMQ X Broker
  3. version : v3.1.0
  4. uptime : 25 seconds
  5. datetime : 2019-04-29 10:42:10

broker stats

查询服务器客户端连接(Connections)、会话(Sessions)、主题(Topics)、订阅(Subscriptions)、路由(Routes)统计:

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

broker metrics

查询服务器流量(Bytes)、MQTT报文(Packets)、消息(Messages)收发统计:

  1. $ ./bin/emqx_ctl broker metrics
  2. bytes/received : 0
  3. bytes/sent : 0
  4. messages/dropped : 0
  5. messages/expired : 0
  6. messages/forward : 0
  7. messages/qos0/received : 0
  8. messages/qos0/sent : 0
  9. messages/qos1/received : 0
  10. messages/qos1/sent : 0
  11. messages/qos2/dropped : 0
  12. messages/qos2/expired : 0
  13. messages/qos2/received : 0
  14. messages/qos2/sent : 0
  15. messages/received : 0
  16. messages/retained : 3
  17. messages/sent : 0
  18. packets/auth : 0
  19. packets/connack : 0
  20. packets/connect : 0
  21. packets/disconnect/recei: 0
  22. packets/disconnect/sent : 0
  23. packets/pingreq : 0
  24. packets/pingresp : 0
  25. packets/puback/missed : 0
  26. packets/puback/received : 0
  27. packets/puback/sent : 0
  28. packets/pubcomp/missed : 0
  29. packets/pubcomp/received: 0
  30. packets/pubcomp/sent : 0
  31. packets/publish/received: 0
  32. packets/publish/sent : 0
  33. packets/pubrec/missed : 0
  34. packets/pubrec/received : 0
  35. packets/pubrec/sent : 0
  36. packets/pubrel/missed : 0
  37. packets/pubrel/received : 0
  38. packets/pubrel/sent : 0
  39. packets/received : 0
  40. packets/sent : 0
  41. packets/suback : 0
  42. packets/subscribe : 0
  43. packets/unsuback : 0
  44. packets/unsubscribe : 0

cluster 命令

cluster 命令集群多个 EMQ X 消息服务器节点(进程):

cluster join <Node>

加入集群

cluster leave

离开集群

cluster force-leave <Node>

从集群删除节点

cluster status

查询集群状态

cluster 命令集群本机两个 EMQ X 节点示例:

目录

节点名

MQTT 端口

emqx1

emqx1@127.0.0.1

1883

emqx2

emqx2@127.0.0.1

2883

启动 emqx1

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

启动 emqx2

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

emqx2 节点与 emqx1 集群,emqx2 目录下:

  1. $ ./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']}]

任意节点目录下查询集群状态:

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

集群消息路由测试:

  1. # emqx1节点上订阅x
  2. $ mosquitto_sub -t x -q 1 -p 1883
  3. # emqx2节点上向x发布消息
  4. $ mosquitto_pub -t x -q 1 -p 2883 -m hello

emqx2 节点离开集群:

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

emqx1 节点下删除 emqx2:

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

acl 命令

重新加载 acl 配置文件:

  1. $ ./bin/emqx_ctl acl reload

clients 命令

clients 命令查询连接的 MQTT 客户端。

clients list

查询全部客户端连接

clients show <ClientId>

根据 ClientId 查询客户端

clients kick <ClientId>

根据 ClientId 踢出客户端

clients list

查询全部客户端连接:

  1. $ ./bin/emqx_ctl clients list
  2. Connection(mosqsub/43832-airlee.lo, clean_start=true, username=test, peername=127.0.0.1:64896, connected_at=1452929113)
  3. Connection(mosqsub/44011-airlee.lo, clean_start=true, username=test, peername=127.0.0.1:64961, connected_at=1452929275)
  4. ...

返回 Client 对象的属性:

clean_start

清除会话标记

username

用户名

peername

对端 TCP 地址

connected_at

客户端连接时间

clients show <ClientId>

根据 ClientId 查询客户端:

  1. $ ./bin/emqx_ctl clients show "mosqsub/43832-airlee.lo"
  2. Connection(mosqsub/43832-airlee.lo, clean_sess=true, username=test, peername=127.0.0.1:64896, connected_at=1452929113)

clients kick <ClientId>

根据 ClientId 踢出客户端:

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

sessions 命令

sessions 命令查询 MQTT 连接会话。 EMQ X 消息服务器会为每个连接创建会话,clean_session 标记 true,创建临时(transient)会话;clean_session 标记为 false,创建持久会话(persistent)。

sessions list

查询全部会话

sessions show <ClientId>

根据 ClientID 查询会话

sessions list

查询全部会话:

  1. $ ./bin/emqx_ctl sessions list
  2. Session(clientid, clean_start=true, expiry_interval=0, subscriptions_count=0, max_inflight=32, inflight=0, mqueue_len=0, mqueue_dropped=0, awaiting_rel=0, deliver_msg=0, enqueue_msg=0, created_at=1553760799)
  3. Session(mosqsub/44101-airlee.lo, clean_start=true, expiry_interval=0, subscriptions_count=0, max_inflight=32, inflight=0, mqueue_len=0, mqueue_dropped=0, awaiting_rel=0, deliver_msg=0, enqueue_msg=0, created_at=1553760314)

返回 Session 对象属性:

clean_start

建立连接时是否清理相关的会话

expiry_interval

会话过期间隔

subscriptions_count

当前订阅数量

max_inflight

飞行窗口(最大允许同时下发消息数)

inflight

当前正在下发的消息数

mqueue_len

当前缓存消息数

mqueue_dropped

会话丢掉的消息数

awaiting_rel

等待客户端发送 PUBREL 的 QoS2 消息数

deliver_msg

转发的消息数(包含重传)

enqueue_msg

缓存过的消息数

created_at

会话创建时间戳

sessions show <ClientId>

根据 ClientId 查询会话:

  1. $ ./bin/emqx_ctl sessions show clientid
  2. Session(clientid, clean_start=true, expiry_interval=0, subscriptions_count=0, max_inflight=32, inflight=0, mqueue_len=0, mqueue_dropped=0, awaiting_rel=0, deliver_msg=0, enqueue_msg=0, created_at=1553760799)

routes 命令

routes 命令查询路由表。

routes list

查询全部路由

routes show <Topic>

根据 Topic 查询路由

routes list

查询全部路由:

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

根据 Topic 查询一条路由:

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

subscriptions 命令

subscriptions 命令查询消息服务器的订阅(Subscription)表。

subscriptions list

查询全部订阅

subscriptions show <ClientId>

查询某个 ClientId 的订阅

subscriptions add <ClientId> <Topic> <QoS>

手动添加静态订阅

subscriptions del <ClientId> <Topic>

手动删除静态订阅

subscriptions list

查询全部订阅:

  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>

查询某个 Client 的订阅:

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

subscriptions add <ClientId> <Topic> <QoS>

手动添加订阅关系:

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

subscriptions del <ClientId> <Topic>

手动删除订阅关系:

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

plugins 命令

plugins 命令用于加载、卸载、查询插件应用。 EMQ X 消息服务器通过插件扩展认证、定制功能,插件置于 plugins/ 目录下。

plugins list

列出全部插件(Plugin)

plugins load <Plugin>

加载插件(Plugin)

plugins unload <Plugin>

卸载插件(Plugin)

plugins reload <Plugin>

重载插件(Plugin)

注解

当修改完成某插件的配置文件时,若需要立即生效则需要执行 reload 命令。因为 unload/load 命令不会编译新的配置文件

plugins list

列出全部插件:

  1. $ ./bin/emqx_ctl plugins list
  2. Plugin(emqx_auth_clientid, version=v3.1.0, description=EMQ X Authentication with ClientId/Password, active=false)
  3. Plugin(emqx_auth_http, version=v3.1.0, description=EMQ X Authentication/ACL with HTTP API, active=false)
  4. Plugin(emqx_auth_jwt, version=v3.1.0, description=EMQ X Authentication with JWT, active=false)
  5. Plugin(emqx_auth_ldap, version=v3.1.0, description=EMQ X Authentication/ACL with LDAP, active=false)
  6. Plugin(emqx_auth_mongo, version=v3.1.0, description=EMQ X Authentication/ACL with MongoDB, active=false)
  7. Plugin(emqx_auth_mysql, version=v3.1.0, description=EMQ X Authentication/ACL with MySQL, active=false)
  8. Plugin(emqx_auth_pgsql, version=v3.1.0, description=EMQ X Authentication/ACL with PostgreSQL, active=false)
  9. Plugin(emqx_auth_redis, version=v3.1.0, description=EMQ X Authentication/ACL with Redis, active=false)
  10. Plugin(emqx_auth_username, version=v3.1.0, description=EMQ X Authentication with Username and Password, active=false)
  11. Plugin(emqx_coap, version=v3.1.0, description=EMQ X CoAP Gateway, active=false)
  12. Plugin(emqx_dashboard, version=v3.1.0, description=EMQ X Web Dashboard, active=true)
  13. Plugin(emqx_delayed_publish, version=v3.1.0, description=EMQ X Delayed Publish, active=false)
  14. Plugin(emqx_lua_hook, version=v3.1.0, description=EMQ X Lua Hooks, active=false)
  15. Plugin(emqx_lwm2m, version=v3.1.0, description=EMQ X LwM2M Gateway, active=false)
  16. Plugin(emqx_management, version=v3.1.0, description=EMQ X Management API and CLI, active=true)
  17. Plugin(emqx_plugin_template, version=v3.1.0, description=EMQ X Plugin Template, active=false)
  18. Plugin(emqx_psk_file, version=v3.1.0, description=EMQX PSK Plugin from File, active=false)
  19. Plugin(emqx_recon, version=v3.1.0, description=EMQ X Recon Plugin, active=true)
  20. Plugin(emqx_reloader, version=v3.1.0, description=EMQ X Reloader Plugin, active=false)
  21. Plugin(emqx_retainer, version=v3.1.0, description=EMQ X Retainer, active=true)
  22. Plugin(emqx_rule_engine, version=v3.1.0, description=EMQ X Rule Engine, active=true)
  23. Plugin(emqx_sn, version=v3.1.0, description=EMQ X MQTT SN Plugin, active=false)
  24. Plugin(emqx_statsd, version=v3.1.0, description=Statsd for EMQ X, active=false)
  25. Plugin(emqx_stomp, version=v3.1.0, description=EMQ X Stomp Protocol Plugin, active=false)
  26. Plugin(emqx_web_hook, version=v3.1.0, description=EMQ X Webhook Plugin, active=false)

插件属性:

version

插件版本

description

插件描述

active

是否已加载

plugins load <Plugin>

加载插件:

  1. $ ./bin/emqx_ctl plugins load emqx_lua_hook
  2. Start apps: [emqx_lua_hook]
  3. Plugin emqx_lua_hook loaded successfully.

plugins unload <Plugin>

卸载插件:

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

plugins reload <Plugin>

重载插件:

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

bridges 命令

bridges 命令用于在多台 EMQ X 服务器节点间创建桥接:

  1. --------- ---------
  2. Publisher --> | node1 | --Bridge Forward--> | node2 | --> Subscriber
  3. --------- ---------

bridges list

查询全部桥接

bridges start <Name>

开启一个桥接

bridges stop <Name>

停止一个桥接

bridges forwards <Name>

列出指定 bridge 的转发主题

bridges add-forward <Name> <Topic>

向指定 bridge 添加转发主题

bridges del-forward <Name> <Topic>

从指定 bridge 删除转发主题

bridges subscriptions <Name>

列出指定 bridge 的订阅主题

bridges add-subscription <Name> <Topic> <QoS>

向指定 bridge 添加订阅主题

bridges del-subscription <Name> <Topic>

从指定 bridge 删除订阅主题

关于 bridges 的配置项在 emqx/emqx.config文件内。

bridges list

查询全部桥接:

  1. $ ./bin/emqx_ctl bridges list
  2. name: emqx status: Stopped

bridges start <Name>

开启一个桥接:

  1. $ ./bin/emqx_ctl bridges start emqx
  2. Start bridge successfully.

bridges stop <Name>

停止一个桥接:

  1. $ ./bin/emqx_ctl bridges stop emqx
  2. Stop bridge successfully.

bridges forwards <Name>

列出指定 bridge 的转发主题:

  1. $ ./bin/emqx_ctl bridges forwards emqx
  2. topic: sensor/#

bridges add-forward <Name> <Topic>

向指定 bridge 添加转发主题:

  1. $ ./bin/emqx_ctl bridges add-forward emqx device_status/#
  2. Add-forward topic successfully.

bridges del-forward <Name> <Topic>

从指定 bridge 删除转发主题:

  1. $ ./bin/emqx_ctl bridges del-forward emqx device_status/#
  2. Del-forward topic successfully.

bridges add-subscription <Name> <Topic> <QoS>

向指定 bridge 添加订阅主题:

  1. $ ./bin/emqx_ctl bridges add-subscription emqx cmd/topic 1
  2. Add-subscription topic successfully.

bridges subscriptions <Name>

列出指定 bridge 的订阅:

  1. $ ./bin/emqx_ctl bridges subscriptions emqx
  2. topic: cmd/topic, qos: 1

bridges del-subscription <Name> <Topic>

从指定 bridge 删除订阅主题:

  1. $ ./bin/emqx_ctl bridges del-subscription emqx cmd/topic
  2. Del-subscription topic successfully.

vm 命令

vm 命令用于查询 Erlang 虚拟机负载、内存、进程、IO 信息。

vm

等同于 vm all

vm all

查询 VM 全部信息

vm load

查询 VM 负载

vm memory

查询 VM 内存

vm process

查询 VM Erlang 进程数量

vm io

查询 VM io 最大文件句柄

vm ports

查询 VM 的端口

vm all

查询 VM 全部信息,包括负载、内存、Erlang 进程数量等:

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

vm load

查询 VM 负载:

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

vm memory

查询 VM 内存:

  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

查询 Erlang 进程数量:

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

vm io

查询 IO 最大句柄数:

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

vm ports

查询 VM 的端口:

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

mnesia 命令

查询 mnesia 数据库系统状态。

log 命令

log 命令用于设置日志等级。访问 Documentation of logger 以获取详细信息

log set-level <Level>

设置主日志等级和所有 Handlers 日志等级

log primary-level

查看主日志等级

log primary-lelvel <Level>

设置主日志等级

log handlers list

查看当前安装的所有 Hanlders

log handlers set-level <HandlerId> <Level>

设置指定 Hanlder 的日志等级

log set-level <Level>

设置主日志等级和所有 Handlers 日志等级:

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

log primary-level

查看主日志等级:

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

log primary-level <Level>

设置主日志等级:

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

log handlers list

查看当前安装的所有 Hanlders:

  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>

设置指定 Hanlder 的日志等级:

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

trace 命令

trace 命令用于追踪某个客户端或 Topic,打印日志信息到文件。

trace list

查询全部开启的追踪

trace start client <ClientId> <File> [<Level>]

开启 Client 追踪,存储指定等级的日志到文件

trace stop client <ClientId>

关闭 Client 追踪

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

开启 Topic 追踪,存储指定等级的日志到文件

trace stop topic <Topic>

关闭 Topic 追踪

注解

使用 trace 之前,需要将主日志等级(primary logger level) 设置成足够低的值。为提高系统运行性能,默认的主日志等级是 error。

trace start client <ClientId> <File> [<Level>]

开启 Client 追踪:

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

trace stop client <ClientId>

关闭 Client 追踪:

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

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

开启 Topic 追踪:

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

关闭 Topic 追踪:

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

trace list

查询全部开启的追踪:

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

listeners

listeners 命令用于查询开启的 TCP 服务监听器

listeners

查询开启的 TCP 服务监听器

listeners stop <Proto> <Port>

停止监听端口

listeners list

查询开启的 TCP 服务监听器:

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

listener 参数说明:

acceptors

TCP Acceptor 池

max_conns

最大允许连接数

current_conns

当前连接数

shutdown_count

Socket 关闭原因统计

listeners stop <Proto> <Port>

停止监听端口:

  1. $ ./bin/emqx_ctl listeners stop mqtt:tcp 0.0.0.0:1883
  2. Stop mqtt:tcp listener on 0.0.0.0:1883 successfully.

规则引擎(rule engine) 命令

rules 命令

rules list

List all rules

rules show <RuleId>

Show a rule

rules create <name> <hook> <sql> <actions> [-d [<descr>]]

Create a rule

rules delete <RuleId>

Delete a rule

rules create

创建一个新的规则:

  1. ## 创建一个测试规则,简单打印所有发送到 't/a' 主题的消息内容
  2. $ ./bin/emqx_ctl rules create \
  3. 'test1' \
  4. 'message.publish' \
  5. 'select * from "t/a"' \
  6. '[{"name":"built_in:inspect_action", "params": {"a": 1}}]' \
  7. -d 'Rule for debug'
  8. Rule test1:1556242324634254201 created

注解

一个规则由系统生成的规则 ID 标识,所以如果用相同的名字重复添加规则,会生成多个 ID 不同的规则。

rules list

列出当前所有的规则:

  1. $ ./bin/emqx_ctl rules list
  2. rule(id='test1:1556242324634254201', name='test1', for='message.publish', rawsql='select * from "t/a"', actions=[{"name":"built_in:inspect_action","params":{"a":1}}], enabled='true', description='Rule for debug')

rules show

查询规则:

  1. ## 查询 RuleID 为 'test1:1556242324634254201' 的规则
  2. $ ./bin/emqx_ctl rules show 'test1:1556242324634254201'
  3. rule(id='test1:1556242324634254201', name='test1', for='message.publish', rawsql='select * from "t/a"', actions=[{"name":"built_in:inspect_action","params":{"a":1}}], enabled='true', description='Rule for debug')

rules delete

删除规则:

  1. ## 删除 RuleID 为 'test1:1556242324634254201' 的规则
  2. $ ./bin/emqx_ctl rules delete 'test1:1556242324634254201'
  3. ok

rule-actions 命令

rule-actions list [-t [<type>]] [-k [<hook>]]

List all actions

rule-actions show <ActionId>

Show a rule action

注解

动作可以由 emqx 内置(称为系统内置动作),或者由 emqx 插件编写,但不能通过 CLI/API 添加或删除。

rule-actions show

查询动作:

  1. ## 查询名为 'built_in:inspect_action' 动作
  2. $ ./bin/emqx_ctl rule-actions show 'built_in:inspect_action'
  3. action(name='built_in:inspect_action', app='emqx_rule_engine', for='$any', type='built_in', params=#{}, description='Inspect the details of action params for debug purpose')

rule-actions list

列出符合条件的动作:

  1. ## 列出当前所有的动作
  2. $ ./bin/emqx_ctl rule-actions list
  3. action(name='built_in:republish_action', app='emqx_rule_engine', for='message.publish', type='built_in', params=#{target_topic => #{description => <<"Repubilsh the message to which topic">>,format => topic,required => true,title => <<"To Which Topic">>,type => string}}, description='Republish a MQTT message to a another topic')
  4. action(name='web_hook:event_action', app='emqx_web_hook', for='$events', type='web_hook', params=#{'$resource' => #{description => <<"Bind a resource to this action">>,required => true,title => <<"Resource ID">>,type => string},template => #{description => <<"The payload template to be filled with variables before sending messages">>,required => false,schema => #{},title => <<"Payload Template">>,type => object}}, description='Forward Events to Web Server')
  5. action(name='web_hook:publish_action', app='emqx_web_hook', for='message.publish', type='web_hook', params=#{'$resource' => #{description => <<"Bind a resource to this action">>,required => true,title => <<"Resource ID">>,type => string}}, description='Forward Messages to Web Server')
  6. action(name='built_in:inspect_action', app='emqx_rule_engine', for='$any', type='built_in', params=#{}, description='Inspect the details of action params for debug purpose')
  7. ## 列出所有资源类型为 web_hook 的动作
  8. $ ./bin/emqx_ctl rule-actions list -t web_hook
  9. action(name='web_hook:event_action', app='emqx_web_hook', for='$events', type='web_hook', params=#{'$resource' => #{description => <<"Bind a resource to this action">>,required => true,title => <<"Resource ID">>,type => string},template => #{description => <<"The payload template to be filled with variables before sending messages">>,required => false,schema => #{},title => <<"Payload Template">>,type => object}}, description='Forward Events to Web Server')
  10. action(name='web_hook:publish_action', app='emqx_web_hook', for='message.publish', type='web_hook', params=#{'$resource' => #{description => <<"Bind a resource to this action">>,required => true,title => <<"Resource ID">>,type => string}}, description='Forward Messages to Web Server')
  11. ## 列出所有 Hook 类型匹配 'client.connected' 的动作
  12. $ ./bin/emqx_ctl rule-actions list -k 'client.connected'
  13. action(name='built_in:inspect_action', app='emqx_rule_engine', for='$any', type='built_in', params=#{}, description='Inspect the details of action params for debug purpose')

resources 命令

emqx_ctl resources create <name> <type> [-c [<config>]] [-d [<descr>]]

Create a resource

resources list [-t <ResourceType>]

List all resources

resources show <ResourceId>

Show a resource

resources delete <ResourceId>

Delete a resource

resources create

创建一个新的资源:

  1. $ ./bin/emqx_ctl resources create 'webhook1' 'web_hook' -c '{"url": "http://host-name/chats"}' -d 'forward msgs to host-name/chats'
  2. Resource web_hook:webhook1 created

resources list

列出当前所有的资源:

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

resources list by type

列出当前所有的资源:

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

resources show

查询资源:

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

resources delete

删除资源:

  1. $ ./bin/emqx_ctl resources delete 'web_hook:webhook1'
  2. ok

resource-types 命令

resource-types list

List all resource-types

resource-types show <Type>

Show a resource-type

注解

资源类型可以由 emqx 内置(称为系统内置资源类型),或者由 emqx 插件编写,但不能通过 CLI/API 添加或删除。

resource-types list

列出当前所有的资源类型:

  1. ./bin/emqx_ctl resource-types list
  2. resource_type(name='built_in', provider='emqx_rule_engine', params=#{}, on_create={emqx_rule_actions,on_resource_create}, description='The built in resource type for debug purpose')
  3. resource_type(name='web_hook', provider='emqx_web_hook', params=#{headers => #{default => #{},description => <<"Request Header">>,schema => #{},title => <<"Request Header">>,type => object},method => #{default => <<"POST">>,description => <<"Request Method">>,enum => [<<"PUT">>,<<"POST">>],title => <<"Request Method">>,type => string},url => #{description => <<"Request URL">>,format => url,required => true,title => <<"Request URL">>,type => string}}, on_create={emqx_web_hook_actions,on_resource_create}, description='WebHook Resource')

resource-types show

查询资源类型:

  1. $ ./bin/emqx_ctl resource-types show built_in
  2. resource_type(name='built_in', provider='emqx_rule_engine', params=#{}, on_create={emqx_rule_actions,on_resource_create}, description='The built in resource type for debug purpose')

recon 命令

recon memory

recon_alloc:memory/2

recon allocated

recon_alloc:memory(allocated_types, current/max)

recon bin_leak

recon:bin_leak(100)

recon node_stats

recon:node_stats(10, 1000)

recon remote_load Mod

recon:remote_load(Mod)

访问 Documentation for recon 以获取详细信息。

recon memory

recon_alloc:memory/2:

  1. $ ./bin/emqx_ctl recon memory
  2. usage/current : 0.810331960305788
  3. usage/max : 0.7992495929358717
  4. used/current : 84922296
  5. used/max : 122519208
  6. allocated/current : 104345600
  7. allocated/max : 153292800
  8. unused/current : 19631520
  9. unused/max : 30773592

recon allocated

recon_alloc:memory(allocated_types, current/max):

  1. $ ./bin/emqx_ctl recon allocated
  2. binary_alloc/current: 425984
  3. driver_alloc/current: 425984
  4. eheap_alloc/current : 4063232
  5. ets_alloc/current : 3833856
  6. fix_alloc/current : 1474560
  7. ll_alloc/current : 90439680
  8. sl_alloc/current : 163840
  9. std_alloc/current : 2260992
  10. temp_alloc/current : 655360
  11. binary_alloc/max : 4907008
  12. driver_alloc/max : 425984
  13. eheap_alloc/max : 25538560
  14. ets_alloc/max : 5931008
  15. fix_alloc/max : 1736704
  16. ll_alloc/max : 90439680
  17. sl_alloc/max : 20348928
  18. std_alloc/max : 2260992
  19. temp_alloc/max : 1703936

recon bin_leak

recon:bin_leak(100):

  1. $ ./bin/emqx_ctl recon bin_leak
  2. {<10623.1352.0>,-3,
  3. [cowboy_clock,
  4. {current_function,{gen_server,loop,7}},
  5. {initial_call,{proc_lib,init_p,5}}]}
  6. {<10623.3865.0>,0,
  7. [{current_function,{recon_lib,proc_attrs,2}},
  8. {initial_call,{erlang,apply,2}}]}
  9. {<10623.3863.0>,0,
  10. [{current_function,{dist_util,con_loop,2}},
  11. {initial_call,{inet_tcp_dist,do_accept,7}}]}
  12. ...

recon node_stats

recon:node_stats(10, 1000):

  1. $ ./bin/emqx_ctl recon node_stats
  2. {[{process_count,302},
  3. {run_queue,0},
  4. {memory_total,88925536},
  5. {memory_procs,27999296},
  6. {memory_atoms,1182843},
  7. {memory_bin,24536},
  8. {memory_ets,7163216}],
  9. [{bytes_in,62},
  10. {bytes_out,458},
  11. {gc_count,4},
  12. {gc_words_reclaimed,3803},
  13. {reductions,3036},
  14. {scheduler_usage,[{1,9.473889959272245e-4},
  15. {2,5.085983030767205e-5},
  16. {3,5.3851477624711046e-5},
  17. {4,7.579021269127057e-5},
  18. {5,0.0},
  19. {6,0.0},
  20. {7,0.0},
  21. {8,0.0}]}]}
  22. ...

recon remote_load Mod

recon:remote_load(Mod):

  1. $ ./bin/emqx_ctl recon remote_load

retainer 命令

retainer info

显示保留消息的数量

retainer topics

显示保留消息的所有主题

retainer clean

清除所有保留的消息

retainer info

显示保留消息的数量:

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

retainer topics

显示保留消息的所有主题:

  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

清除所有保留的消息:

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

admins 命令

Dashboard 插件会自动注册 admins 命令,用于创建、删除管理员账号,重置管理员密码。

admins add <Username> <Password> <Tags>

创建 admin 账号

admins passwd <Username> <Password>

重置 admin 密码

admins del <Username>

删除 admin 账号

admins add <Username> <Password> <Tags>

创建 admin 账户:

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

admins passwd <Username> <Password>

重置 admin 账户密码:

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

admins del <Username>

删除 admin 账户:

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