thkukuk / fritzbox-monitoring

Scripts around and for containers to monitor a Fritzbox
2 stars 2 forks source link

Graphs not updating #4

Open thebang2 opened 9 months ago

thebang2 commented 9 months ago

Hey, I have set up a Docker container with the following parameters:

version: '3.8'
services:
  fritzbox-bandwidth-monitor:
    image: thkukuk/fritzbox-bandwidth-monitor
    container_name: fritzbox-bandwidth-monitor
    ports:
      - "2080:80"
    volumes:
      - /home/root/fritzbox-bandwidth-monitor:/data
      - /home/root/fritzbox-bandwidth-monitor:/srv/www/htdocs
    environment:
      - TZ=Europe/Berlin
      - DEBUG=1
      - FRITZBOX_NR=6490
      - FRITZBOX=192.168.200.1
      - MAX_DOWNLOAD_BYTES=32500000
      - MAX_UPLOAD_BYTES=7500000
      - POLL_INTERVAL=30

After starting, graphs are not updating, max upload and download are not recognized.

System: | FRITZ!Box 6490
IP Address: | 192.168.200.1
Description: | DSL
Max Download Speed: | 16000 kbit/s
Max Upload Speed: | 1024 kbit/s

The log says following:

Setting container timezone to: Europe/Berlin
+ export 'PATH=/usr/sbin:/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
+ export 'LANG=C'
+ POLL_INTERVAL=30
+ MAX_DOWNLOAD_BYTES=32500000
+ MAX_UPLOAD_BYTES=7500000
+ FRITZBOX_NR=6490
+ FRITZBOX=192.168.200.1
+ RUN_WEBSERVER=1
+ setup_timezone
+ '[' -n Europe/Berlin ]
+ TZ_FILE=/usr/share/zoneinfo/Europe/Berlin
+ '[' -f /usr/share/zoneinfo/Europe/Berlin ]
+ echo 'Setting container timezone to: Europe/Berlin'
+ ln -snf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
+ init_trap
+ trap stop_nginx TERM INT EXIT
+ '[' '!' -f /etc/mrtg.cfg ]
+ sed -e 's|7490|6490|g' -e 's|^MaxBytes1\[fritzbox\]:.*|MaxBytes1\[fritzbox\]: 32500000|g' -e 's|^MaxBytes2\[fritzbox\]:.*|MaxBytes2\[fritzbox\]: 7500000|g' -e 's|192.168.178.1 (fritzbox.home.lan)|192.168.200.1|g' /fritzbox-bandwidth-monitor/mrtg.cfg
+ '[' '!' -f /etc/upnp2mrtg.cfg ]
+ echo 'HOST="192.168.200.1"'
+ echo 'NETCAT="nc"'
+ test -d /srv/www/htdocs
+ '[' 1 '=' 1 ]
+ nginx
+ true
+ date -Iseconds
+ DATE=2024-01-27T21:18:59+01:00
+ echo '2024-01-27T21:18:59+01:00 Fetch new data'
+ /usr/bin/mrtg /etc/mrtg.cfg
2024-01-27T21:18:59+01:00 Fetch new data
+ sleep 30

Used hardware: FRITZ!Box 6490 Cable FRITZ!OS: 7.57

Any idea what `I´m doing wrong?

iShark5060 commented 2 months ago

the reason for the top of the page not updating is, that the corresponding fields in the mrtg.cfg are not updated:

bash-5.2# cat mrtg.cfg
######################################################################
# System: FRITZ!Box 7490
# Description: AVM FRITZ!Box 7490
######################################################################
WorkDir: /srv/www/htdocs
Target[fritzbox]: `/fritzbox-bandwidth-monitor/upnp2mrtg.sh`
Title[fritzbox]: Traffic Analysis for FRITZ!Box 7490

# DSL light (384 kbit / 64 kbit)
#MaxBytes1[fritzbox]: 48000
#MaxBytes2[fritzbox]: 8000

# DSL 1024 (1024 kbit / 128 kbit)
#MaxBytes1[fritzbox]: 128000
#MaxBytes2[fritzbox]: 16000

# DSL 2048 (2048 kbit / 192 kbit)
#MaxBytes1[fritzbox]: 256000
#MaxBytes2[fritzbox]: 24000

# DSL 6016 (6016 kbit / 576 kbit)
#MaxBytes1[fritzbox]: 752000
#MaxBytes2[fritzbox]: 72000

# DSL 16000 (16000 kbit / 1024 kbit)
#MaxBytes1[fritzbox]: 2000000
#MaxBytes2[fritzbox]: 128000

MaxBytes1[fritzbox]: 512000
MaxBytes2[fritzbox]: 384000

PageTop[fritzbox]: <h1>Traffic Analysis for FRITZ!Box 7490</h1>
  <div id="sysdetails">
    <table>
      <tr>
        <td>System:</td>
        <td>FRITZ!Box 7490</td>
      </tr>
      <tr>
        <td>IP Address:</td>
        <td>192.168.178.1 (fritzbox.home.lan)</td>
      </tr>
      <tr>
        <td>Description:</td>
        <td>DSL</td>
      </tr>
      <tr>
        <td>Max Download Speed:</td>
        <td>16000 kbit/s</td>
      </tr>
      <tr>
        <td>Max Upload Speed:</td>
        <td>1024 kbit/s</td>
      </tr>
    </table>
  </div>
bash-5.2#

the entrypoint.sh script updates the values in the config generally, but not the "top of the page" part:

bash-5.2# cat entrypoint.sh
#!/bin/sh
[...]
POLL_INTERVAL=${POLL_INTERVAL:-300}
MAX_DOWNLOAD_BYTES=${MAX_DOWNLOAD_BYTES:-16000000000}
MAX_UPLOAD_BYTES=${MAX_UPLOAD_BYTES:-5300000000}
FRITZBOX_NR=${FRITZBOX_NR:-7530}
FRITZBOX=${FRITZBOX:-192.168.178.1}
RUN_WEBSERVER=${RUN_WEBSERVER:-1}
[...]
if [ ! -f /etc/mrtg.cfg ]; then
    sed -e "s|7490|${FRITZBOX_NR}|g" \
        -e "s|^MaxBytes1\[fritzbox\]:.*|MaxBytes1\[fritzbox\]: ${MAX_DOWNLOAD_BYTES}|g" \
        -e "s|^MaxBytes2\[fritzbox\]:.*|MaxBytes2\[fritzbox\]: ${MAX_UPLOAD_BYTES}|g" \
        -e "s|192.168.178.1 (fritzbox.home.lan)|${FRITZBOX}|g" \
        /fritzbox-bandwidth-monitor/mrtg.cfg > /etc/mrtg.cfg
fi
[...]
bash-5.2#

so it's probably neccessary to add 2 more lines to the sed part in the entrypoint.sh that replaces those values (and calculates them first obv).

EDIT: in entrypoint.sh replace

MAX_DOWNLOAD_BYTES=${MAX_DOWNLOAD_BYTES:-16000000000}
MAX_UPLOAD_BYTES=${MAX_UPLOAD_BYTES:-5300000000}

with

MAX_DOWNLOAD_BYTES=${MAX_DOWNLOAD_BYTES:-16000000000}
MAX_UPLOAD_BYTES=${MAX_UPLOAD_BYTES:-5300000000}
MAX_DOWNLOAD_BIT=$((MAX_DOWNLOAD_BYTES / 125))
MAX_UPLOAD_BIT=$((MAX_UPLOAD_BYTES / 125))

and

if [ ! -f /etc/mrtg.cfg ]; then
    sed -e "s|7490|${FRITZBOX_NR}|g" \
        -e "s|^MaxBytes1\[fritzbox\]:.*|MaxBytes1\[fritzbox\]: ${MAX_DOWNLOAD_BYTES}|g" \
        -e "s|^MaxBytes2\[fritzbox\]:.*|MaxBytes2\[fritzbox\]: ${MAX_UPLOAD_BYTES}|g" \
        -e "s|192.168.178.1 (fritzbox.home.lan)|${FRITZBOX}|g" \
        /fritzbox-bandwidth-monitor/mrtg.cfg > /etc/mrtg.cfg
fi

with

if [ ! -f /etc/mrtg.cfg ]; then
    sed -e "s|7490|${FRITZBOX_NR}|g" \
        -e "s|^MaxBytes1\[fritzbox\]:.*|MaxBytes1\[fritzbox\]: ${MAX_DOWNLOAD_BYTES}|g" \
        -e "s|^MaxBytes2\[fritzbox\]:.*|MaxBytes2\[fritzbox\]: ${MAX_UPLOAD_BYTES}|g" \
        -e "s|<td>16000 kbit/s</td>|<td>${MAX_DOWNLOAD_BIT} kbit/s</td>|g" \
        -e "s|<td>1024 kbit/s</td>|<td>${MAX_UPLOAD_BIT} kbit/s</td>|g" \
        -e "s|192.168.178.1 (fritzbox.home.lan)|${FRITZBOX}|g" \
        /fritzbox-bandwidth-monitor/mrtg.cfg > /etc/mrtg.cfg
fi

this will at least fix the top of the page numbers. image