将mqtt度量发布到statsd的脚本
mqtt-statsd的Python项目详细描述
顾名思义,这是一个将mqtt度量发布到statsd的脚本。是的 最初设计用于处理mosquito中$sys/主题的度量 代理,但是框架足够通用,可以使用任何mqtt主题。
安装
mqtt_statsd可通过pypi获得,因此您只需运行:
pip install -U mqtt_statsd
在系统上获取mqtt_statsd。如果需要使用 mqtt_statsd您可以克隆repo并使用以下命令在本地安装它:
git clone https://github.com/mtreinish/mqtt_statsd.git && pip install -e mqtt_statsd
它将以可编辑模式在您的python环境中安装mqtt_statsd 地方发展。
配置mqtt_statsd
在运行mqtt_statsd之前,必须创建一个yaml配置文件来告诉 mqtt_statsd如何连接到mqtt代理和statsd。以及 要订阅的mqtt主题以及如何用它获得的数据填充statsd 从mqtt主题。例如:
statsd: hostname: localhost # port is optional, the default is shown port: 8125 # prefix is optional, the default is shown prefix: mosquitto.stats mqtt: hostname: localhost # port is optional, the default is shown port: 1883 # keepalive is optional, the default is shown keepalive: 60 # username is optional, there is no default username: foo # password is optional, there is no default. If username isn't set this # is ignored password: PASS # qos is optional, the default is shown qos: 0 # websocket is optional, it defaults to False websocket: True topics: # You can specify as many topics as you want, and mqtt_statsd will # listen to all of them - $SYS/broker/messages/publish/sent: statsd_topic: publish_messages_sent # statsd_type is optional, the default is shown. Valid options are # gague, counter, and timer statsd_type: gauge - $SYS/broker/clients/connected: statsd_topic: connected_clients
运行mqtt_statsd
在安装和配置mqtt_statsd并运行它之后 直截了当。只要调用mqtt_statsd,它就需要一个强制参数, yaml配置文件的路径。例如:
mqtt_statsd my_config_file.yaml