Collectd Plugin OpenWrt MQTT

Collected mentions adding the following code to configuration to collectd.conf:

<Plugin "mqtt">
   <Publish "name1">
     Host "localhost"
     Prefix "collectd"
     Retain true
   </Publish>
</Plugin>

will it start publishing MQTT topics?
https://collectd.org/wiki/index.php/Plugin:MQTT#Publish_Example

I have prepared basic configuration for HomeAssistant:

1 Like
LoadPlugin mqtt
<Plugin "mqtt">
  <Publish "OpenWRT">
    Host "192.168.0.1"
    Port "1883"
    User "user"
    Password "Password"
    ClientId "OpenWRT"
    Prefix "collectd"
    Retain true
  </Publish>
</Plugin>

this ip is HA ip? and this will go in /etc/collectd.conf ?

OK, I just went through this and it took me longer than anticipated to figure it out; hopefully you’ll find the following useful. Instead of adding the above configlet to /etc/collectd.conf on the OpenWRT router I created /etc/collectd/mqtt.conf and added it there. The reason being that on the version of OpenWRT & collectd on my router /etc/collectd.conf gets overwritten on each reboot. The Host ip address is the address of my local Home Assistant instance. On HA you’ll have to go into Settings -> People -> Users and create an account for OpenWRT MQTT to login to, then add the password in the configlet on OpenWRT. Restart the Mosquito broker on HA, followed by restarting collectd on the OpenWRT router (you can do this by logging into OpenWRT via ssh and issuing service collectd restart from the command line. You should see in the OpenWRT logfile that collectd-mqtt successfully connects to HA. You can then add sensors you are interested from: OpenWRT-collectd-MQTT-HA/configuration.yaml at 1c99b71a2f6337d18a9393caa84ef1bf06ed094f · lukdwo/OpenWRT-collectd-MQTT-HA · GitHub to your HA config and updating as needed. At first I was not seeing anything in HA but after some debugging in HA Settings -> Devices & Services -> Mosquitto broker -> Configure and setting listen to collectd/# I saw updates coming in. The main difference was that updates were coming in as collectd/<name of my OpenWRT router>. You should now have entities in HA that represent these senors and can use them in dashboards/automations.

Thanks for the details around this something small i am just missing.

Created the user and also saw i needed the mqtt config in the other folder.

Wed Mar 22 16:57:09 2023 daemon.err collectd[1772]: plugin_load: plugin “mqtt” successfully loaded.
Wed Mar 22 16:57:09 2023 daemon.err collectd[1772]: Initialization complete, entering read-loop.
Wed Mar 22 17:54:28 2023 daemon.err collectd[1772]: Sleeping only 2s because the next interval is 3399.211 seconds in the past!

This is where i am stuck now.

setting listen to collectd/# I saw updates coming in.

Left it like that for 2 hours no time changes and the listening stops …?

I am seeing the router name I created and everything created but still no data.

Could you point me in the right direction?

Do you have the collectd-uptime plugin installed/activated on your OpenWRT router?

I installed collectd, collectd-mod-mqtt. ssh into the router I do not see /etc/collectd folder. Do I need create this folder manually? I did not reboot the router after installing these 2 packages.

Since I had many issues regarding collectd on openwrt, not sure if you solved this but here is for anyone who’s struggling with configuration:

  • install mqtt broker on home assistant (mosquitto)
  • install luci-app-statistics on openwrt (it will install collectd, some additional mods and it will provide option to select where your collectd config files will be (for those who don’t see it in /etc folder))
  • install collectd-mod-mqtt
  • change collectd main folder to /etc/collectd in luci-app-statistics setup menu
  • create new folder conf.d in /etc/collectd/ folder
  • finally create your conf file in /etc/collectd/conf.d/ folder (i.e. mqtt.conf).
    Merge this guide with the main guide and you’ll be good to go.
    Here is what I got at the end:
1 Like

hey undeene,
Thanks for the write. luci-app-statistics was probably what I missed. I may just tried again, but I noticed the memory jumped about 10% higher when I tried with the first attempt. It was sitting at about 82%.

Hi and sorry for replying to such an old thread.

This configuration is a great addition to Home Assistant but I struggled as much as you to configure it.

Therefore I’ve re-written the documentation and now you can find a full step by step guide GitHub - lukdwo/OpenWRT-collectd-MQTT-HA: OpenWRT Collectd to MQTT with Homeassistant Template

This thread contained some good tips so I wanted to thank you because it’s the one I got when searching how to install this integration!

2 Likes

some changes are required after installing packages on openwrt, you have to restart the device bcz of changes in menu.

I did not have to restart OpenWRT, but I restarted collectd. The new instructions are quite detailed!

1 Like

I get this error when I try to statistics > graphs

and this is my collected config.

and MQTT device

and mqtt conf file is located here

/etc/collectd/conf.d

Something is wrong in your OpenWRT setup: you should be able to see Graphs by simply installing luci-app-statistics

fixed the stats graph issue, but I don’t understand this line
Connect to your OpenWRT router via SSH, create a new folder called conf.d in /etc/collectd/

there is collectd.conf file in /etc/ directory but no collected folder.

content of that file

BaseDir "/etc/collectd"
Include "/etc/collectd/conf.d/*.conf"
PIDFile "/var/run/collectd.pid"
PluginDir "/usr/lib/collectd"
TypesDB "/usr/share/collectd/types.db"
Interval 30
ReadThreads 2

LoadPlugin cpu
<Plugin cpu>
	ValuesPercentage true
	ReportByCpu true
	ReportByState true
</Plugin>

LoadPlugin interface
<Plugin interface>
	IgnoreSelected false
	Interface "br-lan"
</Plugin>

LoadPlugin iwinfo

LoadPlugin load

LoadPlugin memory
<Plugin memory>
	ValuesPercentage false
	ValuesAbsolute true
</Plugin>

LoadPlugin rrdtool
<Plugin rrdtool>
	DataDir "/tmp/rrd"
	RRARows 288
	RRASingle true
	RRATimespan 7200
	RRATimespan 86400
	RRATimespan 604800
	RRATimespan 2678400
	RRATimespan 31622400
</Plugin>


Have you installed collectd-mod-mqtt as well?

I don’t understand why these folders are missing in your setup, they’re even referenced in the config as you see.

Try re-installing the custom packages for this guide.

Can you please share how you get the “Connected” and “Up” states from OpenWrt?