oweitman / openwrt-collectd-plc

This is a statistics-plugin for powerlan devices (also called "Power line communication" (plc),powerlan, dLan, HomePlug).
7 stars 2 forks source link

No graph generated on OpenWRT 19.07, but data is being collected #1

Open gstammw opened 4 years ago

gstammw commented 4 years ago

I installed the plugin according to your manual and can see in the system log that the amprate-command is being triggered every 30 seconds, so the "exec"-plugin seems to work. Unfortunately I do not see a graph for the exec-Plugin or anything that can be linked to PLC, when I click Statistisc, Graph (on https://192.168.1.1/cgi-bin/luci/admin/statistics/graph). One can only see "Processor, Interfaces, Wireless, System Load, Memory". What's necessary to get the graph generated and shown in LUCI?

oweitman commented 4 years ago

hi, i didnt use this script for almost 2 years and cant retest with an actual version of openwrt. as i remember, can you check if a seperate rrd database-file ist created for each device? i didnt remeber in wich directory. can you check if the value types are correctly added in the files types.db? can you execute the shellscript plc_exec.sh as a root user directly from the commandline of the openwrt shell. can you please post one line of the exec command? After executing can you recheck if the database files is created?

gstammw commented 4 years ago

Thanks for your reply. I checked the rrd-files and there is no rrd-database being generated for the exec-plugin, although the plugin runs:

ls /tmp/rrd/TL-WPA8630p/ -l
drwxr-xr-x    2 root     root            60 May 23 16:39 cpu
drwxr-xr-x    2 root     root           120 May 23 16:35 interface-br-lan
drwxr-xr-x    2 root     root           140 May 23 16:39 iwinfo-wlan0
drwxr-xr-x    2 root     root           140 May 23 16:39 iwinfo-wlan1
drwxr-xr-x    2 root     root            60 May 23 16:35 load
drwxr-xr-x    2 root     root           160 May 23 16:35 memory

The collectd.conf looks like this:

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

LoadPlugin iwinfo
<Plugin iwinfo>
        IgnoreSelected false
</Plugin>

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

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

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

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

LoadPlugin exec
<Plugin exec>
        Exec "plc:plc" "/usr/lib/collectd/plc_exec.sh" "br-lan"
</Plugin>

LoadPlugin load

As one can see, the plugin calls the script /usr/lib/collectd/plc_exec.sh on a regular basis:

logread
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "iwinfo" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "memory" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "cpu" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "rrdtool" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: rrdtool plugin: RRASingle = true: creating only AVERAGE RRAs
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "interface" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "exec" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: plugin_load: plugin "load" successfully loaded.
Mon May 25 20:19:10 2020 daemon.err collectd[682]: Initialization complete, entering read-loop.
Mon May 25 20:19:11 2020 authpriv.notice sudo:      plc : TTY=unknown ; PWD=/tmp/run/collectd ; USER=root ; COMMAND=/usr/bin/amprate -i br-lan all
Mon May 25 20:19:42 2020 authpriv.notice sudo:      plc : TTY=unknown ; PWD=/tmp/run/collectd ; USER=root ; COMMAND=/usr/bin/amprate -i br-lan all
Mon May 25 20:20:12 2020 authpriv.notice sudo:      plc : TTY=unknown ; PWD=/tmp/run/collectd ; USER=root ; COMMAND=/usr/bin/amprate -i br-lan all
Mon May 25 20:20:42 2020 authpriv.notice sudo:      plc : TTY=unknown ; PWD=/tmp/run/collectd ; USER=root ; COMMAND=/usr/bin/amprate -i br-lan all

A process of collectd and the script is running:

  682 root      4564 SN   /usr/sbin/collectd -C /tmp/collectd.conf -f
  701 plc       1212 SN   /bin/sh /usr/lib/collectd/plc_exec.sh br-lan

The (manual) output amprate provides is:

/usr/bin/amprate -i br-lan all
br-lan 98:DE:D0:XX:XX:XX 18:A6:F7:9B:93:CF TX 563 mbps Alternate
br-lan 98:DE:D0:XX:XX:XX 18:A6:F7:9B:93:CF RX 500 mbps Alternate

Maybe the problem is with the last lines of the plc_exec.sh-script:

      #write data to collectd
        echo "PUTVAL \"$COLLECTD_HOSTNAME/exec-plc/plc_${typ}-${src}_${dst}\" interval=$INTERVAL $EPOCH:$speed"

I do not see a directory called "exec-pl" in /tmp/rrd/TL-WPA8630p (TL-WPA8630p is my router's hostname).

When I run the script on command line, it looks like this: root@TL-WPA8630p:/usr/lib/collectd# /usr/lib/collectd/plc_exec.sh br-lan (It hangs till forever and does not provide any output.

oweitman commented 4 years ago

ok, the problem is, that the script didnt produce an output. The line with the PUTVAL is not a shell command. the PUTVAL is send vai stdoutput to the collectd server and this process recognize the data.

i think the problem is in the following line. the script only makes an output if the first mac is lesser than the second mac. can you re-check the output ot the amprate tool if there is allways double results for each connection (src->dst and dst->src) you can also change in the line below the lesser than (<) to a greater than (>) sign

#filter connections
      #'amprate all' returns between 2 devices double results (src -> dst and dst->src)
      #we only take these connections where the src-mac is lesser than the dst-max
      if [[ "$(echo $src $dst| awk '{ print ($1 < $2) ? "true" : "false" }')" == "true" ]]

for testing you can start the shell-script directly from command line. the output should be like.

PUTVAL "/exec-plc/plc_TX-B93CF_XXXXX" interval=30 1590507429:563

the output is based of your sample data. br-lan 98:DE:D0:XX:XX:XX 18:A6:F7:9B:93:CF TX 563 mbps Alternate

gstammw commented 4 years ago

Thanks for your reply. Changing the lesser than sign (<) to a greater than (>) sign resulted in a working output ;-)

Here with some shell outputs:

root@TL-WPA8630p:/usr/lib/collectd# ./plc_exec_with-console-output-and-greater-than.sh
Interface: br-lan
BASEDIR: .
HOSTNAME: TL-WPA8630p
begin loop.
PUTVAL "TL-WPA8630p/exec-plc/plc_TX-D7102_B93CF" interval=30 1591087263:09
speed: 09
src: D7102
dst: B93CF
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_RX-D7102_B93CF" interval=30 1591087263:09
speed: 09
src: D7102
dst: B93CF
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_TX-D7102_3B502" interval=30 1591087263:09
speed: 09
src: D7102
dst: 3B502
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_RX-D7102_3B502" interval=30 1591087263:09
speed: 09
src: D7102
dst: 3B502
looping...
begin loop.
PUTVAL "TL-WPA8630p/exec-plc/plc_TX-D7102_B93CF" interval=30 1591087267:09
speed: 09
src: D7102
dst: B93CF
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_RX-D7102_B93CF" interval=30 1591087267:09
speed: 09
src: D7102
dst: B93CF
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_TX-D7102_3B502" interval=30 1591087267:09
speed: 09
src: D7102
dst: 3B502
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_RX-D7102_3B502" interval=30 1591087267:09
speed: 09
src: D7102
dst: 3B502
looping...
begin loop.
PUTVAL "TL-WPA8630p/exec-plc/plc_TX-D7102_B93CF" interval=30 1591087271:09
speed: 09
src: D7102
dst: B93CF
looping...
PUTVAL "TL-WPA8630p/exec-plc/plc_RX-D7102_B93CF" interval=30 1591087272:09

Now data for RRD-graphs is being collected:

/tmp/rrd/TL-WPA8630p/exec-plc# ls -lah
drwxr-xr-x    2 root     root          80 Jun  2 10:43 .
drwxr-xr-x    9 root     root         180 Jun  2 10:43 ..
-rw-r--r--    1 root     root        6.9K Jun  2 10:56 plc_RX-D7102_3B502.rrd
-rw-r--r--    1 root     root        6.9K Jun  2 10:56 plc_TX-D7102_3B502.rrd

But unfortunately no rrd-graph is being generated:

 ls /tmp/rrdimg/TL-WPA8630p/
cpu               interface-br-lan  iwinfo-wlan0      iwinfo-wlan1      load              memory

Unfortunately there is no link to view the graph in LUCI/the webinterface. If I manually change the end of the url to "exec" it doesn't help either. grafik

How can I view the graph?

oweitman commented 4 years ago

ok, i have to create a test environment on a spare router.