├── Dockerfile ├── README.md ├── assets ├── mrtg-cron ├── mrtg.cfg └── upnp2mrtg.sh └── images └── example.png /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:latest 2 | MAINTAINER tom@harhar.net 3 | 4 | ENV DEBIAN_FRONTEND noninteractive 5 | 6 | RUN ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \ 7 | dpkg-reconfigure -f noninteractive tzdata 8 | 9 | RUN apt-get update && \ 10 | apt-get -y dist-upgrade 11 | 12 | RUN apt-get -y install locales psmisc supervisor cron rsyslog wget mrtg apache2 netcat 13 | 14 | RUN dpkg-reconfigure -f noninteractive locales 15 | RUN sed --in-place '/de_DE.UTF-8/s/^#//' /etc/locale.gen 16 | RUN locale-gen de_DE.UTF-8 17 | ENV LANG de_DE.UTF-8 18 | ENV LANGUAGE de_DE:de 19 | ENV LC_ALL de_DE.UTF-8 20 | 21 | COPY assets/upnp2mrtg.sh /usr/local/bin 22 | COPY assets/mrtg.cfg /etc 23 | COPY assets/mrtg-cron /etc/cron.d/mrtg 24 | 25 | RUN rm /var/www/html/index.html 26 | 27 | CMD /bin/sh -c "service cron start; service apache2 start; while true; do echo Hello world; sleep 3600; done" 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fritzbox-bandwidth-monitor 2 | Monitor your fritz.box with mrtg using docker 3 | 4 | Build: 5 | ```` 6 | docker build -t fritzbox-bandwidth-monitor . 7 | ```` 8 | 9 | Run with "docker": 10 | ``` 11 | docker run -d -p 80:80 fritzbox-bandwidth-monitor 12 | ```` 13 | or (in case you want to persist the HTML output and log): 14 | ``` 15 | mkdir -p /home/pi/fritzbox/html 16 | docker run -d -v /home/pi/fritzbox/html:/var/www/html --restart always -p 80:80 fritzbox-bandwidth-monitor 17 | ``` 18 | 19 | Or using docker-compose: 20 | ``` 21 | fritzbox-bandwidth-monitor: 22 | image: fritzbox-bandwidth-monitor 23 | container_name: fritzbox-bandwidth-monitor 24 | ports: 25 | - 80:80 26 | restart: unless-stopped 27 | ``` 28 | 29 | Point your Browser to http://localhost/fritzbox.html and view your traffic stats. Cron runs every five minutes and updates the html data within the container. 30 | 31 | ![Example image](images/example.png) 32 | 33 | Other fritzbox related monitoring projects: 34 | https://github.com/Tafkas/fritzbox-munin 35 | 36 | -------------------------------------------------------------------------------- /assets/mrtg-cron: -------------------------------------------------------------------------------- 1 | */5 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ] && [ -d "$(grep '^[[:space:]]*[^#]*[[:space:]]*WorkDir' /etc/mrtg.cfg | awk '{ print $NF }')" ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi 2 | -------------------------------------------------------------------------------- /assets/mrtg.cfg: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # System: FRITZ!Box 7490 3 | # Description: AVM FRITZ!Box 7490 4 | ###################################################################### 5 | WorkDir: /var/www/html 6 | Target[fritzbox]: `/usr/local/bin/upnp2mrtg.sh` 7 | Title[fritzbox]: Traffic Analysis for FRITZ!Box 7490 8 | 9 | # DSL light (384 kbit / 64 kbit) 10 | #MaxBytes1[fritzbox]: 48000 11 | #MaxBytes2[fritzbox]: 8000 12 | 13 | # DSL 1024 (1024 kbit / 128 kbit) 14 | #MaxBytes1[fritzbox]: 128000 15 | #MaxBytes2[fritzbox]: 16000 16 | 17 | # DSL 2048 (2048 kbit / 192 kbit) 18 | #MaxBytes1[fritzbox]: 256000 19 | #MaxBytes2[fritzbox]: 24000 20 | 21 | # DSL 6016 (6016 kbit / 576 kbit) 22 | #MaxBytes1[fritzbox]: 752000 23 | #MaxBytes2[fritzbox]: 72000 24 | 25 | # DSL 16000 (16000 kbit / 1024 kbit) 26 | #MaxBytes1[fritzbox]: 2000000 27 | #MaxBytes2[fritzbox]: 128000 28 | 29 | MaxBytes1[fritzbox]: 512000 30 | MaxBytes2[fritzbox]: 384000 31 | 32 | PageTop[fritzbox]:

Traffic Analysis for FRITZ!Box 7490

33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
System:FRITZ!Box 7490
IP Address:192.168.178.1 (fritzbox.home.lan)
Description:DSL
Max Download Speed:16000 kbit/s
Max Upload Speed:1024 kbit/s
56 |
57 | -------------------------------------------------------------------------------- /assets/upnp2mrtg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # upnp2mrtg - Monitoring AVM Fritz!Box With MRTG 4 | # This versions have been reported as working: 3030, 5050, 7050, 7141 and 7170 5 | # 6 | # Copyright (C) 2005 Michael Tomschitz 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | # 22 | # The latest version of this software can be obtained here: 23 | # 24 | # http://www.ANetzB.de/upnp2mrtg/ 25 | # 26 | # $Id: upnp2mrtg,v 1.9 2008/02/09 15:37:57 tomcat Exp $ 27 | 28 | # default configuration 29 | HOST="fritz.box" 30 | PORT="49000" 31 | NETCAT="netcat" 32 | 33 | # if available, read configuration 34 | test -f /etc/upnp2mrtg.cfg && . /etc/upnp2mrtg.cfg 35 | 36 | case $NETCAT in 37 | bash) nc="shell_netcat" ;; 38 | netcat) nc="netcat" ;; 39 | nc_q) nc="nc -q 1" ;; 40 | *) nc="nc" ;; 41 | esac 42 | 43 | ver_txt="upnp2mrtg, version $Revision: 1.9 $ 44 | Copyright (C) 2005-2008 Michael Tomschitz 45 | upnp2mrtg comes with ABSOLUTELY NO WARRANTY. This is free software, 46 | and you are welcome to redistribute it under certain conditions." 47 | 48 | help_txt="\ 49 | Usage: upnp2mrtg [-a ] [-p ] [-P] [-d] [-h] [-i] [-t] [-v] [-V] 50 | 51 | -a hostname or ip adress of upnp device (default: $HOST) 52 | -p port to connect (default: $PORT) 53 | -P query packets instead of bytes 54 | -d debug mode 55 | -h show help and exit 56 | -i get all igd description 57 | -t test connection 58 | -v show upnp2mrtg version and exit 59 | -V be verbose for testing 60 | " 61 | 62 | while getopts "a:dhi:p:PtvV" option; do 63 | case $option in 64 | a) HOST="$OPTARG";; 65 | d) set -x ;; 66 | h) echo "$help_txt"; exit 0;; 67 | i) MODE=igd; IGDXML="$OPTARG";; 68 | p) PORT="$OPTARG";; 69 | P) PACKET_MODE=true;; 70 | t) MODE="test";; 71 | v) echo "$ver_txt"; exit 0;; 72 | V) VERBOSE=true;; 73 | ?) exit 1;; 74 | esac 75 | done 76 | 77 | # functions 78 | request_header () { 79 | echo "POST /igdupnp/control/$4 HTTP/1.0 80 | HOST: $1:$2 81 | CONTENT-LENGTH: $3 82 | CONTENT-TYPE: text/xml; charset=\"utf-8\" 83 | SOAPACTION: \"urn:schemas-upnp-org:service:$5:1#$6\"" 84 | } 85 | soap_form () { 86 | echo " 87 | 90 | 91 | 92 | 93 | " 94 | } 95 | get_attribute () { 96 | _get_attribute_start_tag () { echo "${2#*<$1>*}"; } 97 | _get_attribute_end_tag () { echo "${2%**}"; } 98 | _get_attribute_tag () { _get_attribute_start_tag "$1" "`_get_attribute_end_tag $1 "$2"`" ; } 99 | _get_attribute_num () { echo $#; } 100 | if [ `_get_attribute_num $1` -gt 1 ]; then 101 | get_attribute "${1#* }" "`_get_attribute_tag "${1%% *}" "$2"`" 102 | else 103 | _get_attribute_tag "${1}" "$2" 104 | fi 105 | } 106 | modulo_time () { 107 | echo "$((${1} / ${2})) $((${1} % ${2}))" 108 | } 109 | shell_netcat () { 110 | exec 5<>/dev/tcp/$1/$2; cat >&5; cat <&5; 111 | } 112 | get_response () { 113 | _get_response_rs="`echo "$1" | $nc $HOST $PORT 2>/dev/null`" 114 | _get_response_rv=$? 115 | echo "$_get_response_rs" 116 | if ${VERBOSE:-false}; then 117 | echo 118 | echo "---- REQUEST: ----">&2 119 | echo "$1">&2 120 | echo "---- RESPONSE: ----">&2 121 | echo "$_get_response_rs">&2 122 | echo "----">&2 123 | fi 124 | return $_get_response_rv 125 | } 126 | request_header_http () { 127 | echo "GET $3 HTTP/1.0 128 | 129 | " 130 | } 131 | ws_operation () { 132 | request="`soap_form "$1" WANCommonInterfaceConfig`" 133 | post="`request_header $HOST $PORT ${#request} WANCommonIFC1 WANCommonInterfaceConfig "$1"` 134 | 135 | $request" 136 | rs="`get_response "$post"`" 137 | if [ $? -eq 0 ]; then 138 | echo "`get_attribute "$2" "$rs"`" 139 | fi 140 | } 141 | 142 | case $MODE in 143 | test) 144 | echo "GET /any.xml HTTP/1.0 145 | " | $nc $HOST $PORT >/dev/null 146 | if [ $? -eq 0 ]; then 147 | echo "OK"; exit 0 148 | else 149 | echo "Connection Error"; exit 1 150 | fi;; 151 | igd) 152 | if [ -f "$IGDXML" ];then 153 | echo "ERROR: $IGDXML: File exists.">&2; exit 1 154 | fi 155 | for igd in any igdconnSCPD igddesc igddslSCPD igdicfgSCPD; do 156 | request="`request_header_http $HOST $PORT /$igd.xml` 157 | " 158 | rs="`get_response "$request"`" 159 | if [ "$IGDXML" = "-" ]; then 160 | echo "---- $igd.xml ---- 161 | $rs" 162 | else 163 | echo "---- $igd.xml ---- 164 | $rs" >> "$IGDXML" 165 | fi 166 | done;; 167 | *) 168 | # get uptime 169 | request="`soap_form GetStatusInfo WANIPConnection`" 170 | post="`request_header $HOST $PORT ${#request} WANIPConn1 WANIPConnection GetStatusInfo` 171 | 172 | $request" 173 | # rs="`echo "$post" | $nc $HOST $PORT 2>/dev/null`" 174 | rs="`get_response "$post"`" 175 | if [ $? -eq 0 ]; then 176 | ut=`get_attribute NewUptime "$rs"` 177 | 178 | # calculate days + hours, minutes, seconds 179 | s=`modulo_time $ut 60` 180 | m=`modulo_time ${s% *} 60` 181 | h=`modulo_time ${m% *} 24` 182 | fi 183 | 184 | # get data in/out 185 | if ${PACKET_MODE:-false}; then 186 | b1="`ws_operation GetTotalPacketsReceived NewTotalPacketsReceived`" 187 | b2="`ws_operation GetTotalPacketsSent NewTotalPacketsSent`" 188 | else 189 | b1="`ws_operation GetAddonInfos NewTotalBytesReceived`" 190 | b2="`ws_operation GetAddonInfos NewTotalBytesSent`" 191 | fi 192 | 193 | # output for mrtg 194 | printf "%s\n%s\n%d days %.2d:%.2d:%.2d h (online)\nFRITZ!Box\n" \ 195 | "${b1:-UNKNOWN}" "${b2:-UNKNOWN}" "${h% *}" "${h#* }" "${m#* }" "${s#* }" 196 | ;; 197 | esac 198 | 199 | -------------------------------------------------------------------------------- /images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mottobug/fritzbox-bandwidth-monitor/1c07e9ef4b6d0a4454330b2fc510aed42ba3a6c9/images/example.png --------------------------------------------------------------------------------