PLC rate monitoring with collectd

I have two APs, one acting as the main router while the other is a dumb AP. The APs are connected to each other using powerline adapters (TP-LINK TL-PA8010P). I wanted to monitor the data rate of the powerline connection and make it available through LuCI. I've picked collectd and here is my solution so far:

SSH into the router and install the necessary packages:

opkg update
opkg install luci-app-statistics open-plc-utils-plcrate sudo collectd-mod-exec

Create a command for reading the plcrate output and converting it into the format expected by the collectd Exec plugin (this will work for single PLC connections only):

cat >/usr/bin/stat-exec-plc << EOF
INTERVALINT=\$(printf %.0f \$INTERVAL)

while true; do
  plcrate=\$(sudo plcrate -i br-lan)
  rxval=\$(echo \$plcrate | sed -n -e 's/^.* RX //p' | cut -f0 -d ' ' )
  txval=\$(echo \$plcrate | sed -n -e 's/^.* TX //p' | cut -f0 -d ' ' )
  echo "PUTVAL \"\$COLLECTD_HOSTNAME/exec-plc/bitrate-rx\" interval=\$INTERVALINT N:\$rxval"
  echo "PUTVAL \"\$COLLECTD_HOSTNAME/exec-plc/bitrate-tx\" interval=\$INTERVALINT N:\$txval"
  sleep "\$INTERVALINT"

chmod 755 /usr/bin/stat-exec-plc

plcrate requires elevated privileges but this script will run as nobody, hence the sudo in the above script. Create a sudoers file to allow the sudo call and to suppress log entries:

cat >/etc/sudoers.d/plcrate-nobody << EOF
Cmnd_Alias PLCRATESCRIPT = /usr/bin/plcrate
Defaults!PLCRATESCRIPT !syslog

Enable the Exec plugin through luci (Statistics / Setup, General plugins tab) and configure it to execute: /usr/bin/stat-exec-plc (as nobody).

Create a definitions file for visualizing the collected data:

cat >/www/luci-static/resources/statistics/rrdtool/definitions/exec.js << EOF
'use strict';'require baseclass';return baseclass.extend({title:_('PLC rate'),rrdargs:function(graph,host,plugin,plugin_instance,dtype){if(plugin_instance=='plc'){return{title:"%H: PLC (coded PHY) rate",vlabel:"Mbit/s",y_min:"0",number_format:"%5.1lf%sMbit/s",data:{instances:{bitrate:["rx","tx"]},options:{bitrate_rx:{title:"RX Rate",overlay:true,noarea:true,color:"00ff00"},bitrate_tx:{title:"TX Rate",overlay:true,noarea:true,color:"ff0000"},}}};}}});

Restart collectd and uhttpd:

rm -rf /tmp/luci*
/etc/init.d/uhttpd restart
/etc/init.d/luci_statistics restart

Comments/suggestions are welcome!