This commit is contained in:
oe73773 2020-07-13 00:41:05 -04:00 committed by GitHub
commit c02adc6901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 323 additions and 94 deletions

View File

@ -1,26 +1,9 @@
# fritzbox-munin
A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7590](http://geni.us/OO2c7S)(Amazon link) running FRITZ!OS 7.00.
A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7490](http://geni.us/OO2c7S)(Amazon link) running FRITZ!OS 07.12.
If you are using the scripts on a different Fritz!Box model please let me know by
- opening an issue
- submitting a pull request
So far the following models (running FRITZ!OS 06.83) have been confirmed working:
- [FRITZ!Box 3370](http://geni.us/zh3U)
- [FRITZ!Box 5490](http://geni.us/ACtUyFt)
- [FRITZ!Box 7362 SL](http://geni.us/fTyoY)
- [FRITZ!Box 7390](http://geni.us/BlAP)
- [FRITZ!Box 7430](http://geni.us/BlAP)
- [FRITZ!Box 7490](http://geni.us/fTyoY)
- [FRITZ!Box 7560](http://geni.us/6gPZNI)
- [FRITZ!Box 7580](http://geni.us/yUYyQTE)
- [FRITZ!Box 7590](http://geni.us/OO2c7S)
If you are still running Fritz!OS 6.30 check out the [releases section](https://github.com/Tafkas/fritzbox-munin/releases/tag/6.30.1).
## Introduction
These python scripts are [Munin](http://munin-monitoring.org) plugins for monitoring the [Fritz!Box](http://avm.de/produkte/fritzbox/) router by AVM.
@ -74,25 +57,61 @@ If you are using the scripts on a different Fritz!Box model please let me know b
1. Pre-requesites for the fritzbox\_traffic and fritzbox\_uptime plugins are the [fritzconnection](https://pypi.python.org/pypi/fritzconnection) and [requests](https://pypi.python.org/pypi/requests) package. To install it
pip install fritzconnection
pip install requests
pip install lxml
2. Make sure the FritzBox has UPnP status information enabled. (German interface: Heimnetz > Heimnetzübersicht > Netzwerkeinstellungen > Statusinformationen über UPnP übertragen)
3. Copy all the scripts to `/usr/share/munin/plugins`
3. Copy all the scripts (*.py) to `/usr/share/munin/plugins`
4. Create entry in `/etc/munin/plugin-conf.d/munin-node`:
4. Make all the scripts execute able (chmod 755 /usr/share/munin/plugins.*py)
[fritzbox_*]
env.fritzbox_ip <ip_address_to_your_fritzbox>
env.fritzbox_password <fritzbox_password>
env.traffic_remove_max true # if you do not want the possible max values
host_name fritzbox
5. Create entry in `/etc/munin/plugin-conf.d/munin-node`:
1. only one fritzbox or all fritzboxes use the same password:
5. Create symbolic links to `/etc/munin/plugins`.
[fritzbox_*]
env.fritzbox_password <fritzbox_password>
env.traffic_remove_max true # if you do not want the possible max values
2. multiple fritzboxes:
[fritzbox_<fqdn1>_*]
env.fritzbox_password <fritzbox_password>
env.traffic_remove_max true # if you do not want the possible max values
6. Restart the munin-node daemon: `/etc/init.d/munin-node restart`.
[fritzbox_<fqdn2>_*]
env.fritzbox_password <fritzbox_password>
env.traffic_remove_max true # if you do not want the possible max values
7. Done. You should now start to see the charts on the Munin pages.
6. Create symbolic link in `/etc/munin/plugins` for `fritzbox_helper.py`.
cd /etc/munin/plugins
ln -d /usr/share/munin/plugins/fritzbox_helper.py fritzbox_helper.py
7. Create symbolic link in `/etc/munin/plugins` for probes.
link `/usr/share/munin/plugins/fritzbox__<probe>.py` to `fritzbox_<fqdn>_<probe>`
example
cd /etc/munin/plugins
ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_fritz.box_cpu_usage
ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_fritz.box_cpu_temperature
...
if you have multiple fritz box just create multiple sets of links with a different fqdn or ip.
example
cd /etc/munin/plugins
ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_fritz.box_cpu_usage
ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_box2.fritz.box_cpu_usage
ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_192.168.100.1_cpu_usage
ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_box2.fritz.box_cpu_temperature
ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_box2.fritz.box_cpu_temperature
ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_192.168.100.1_cpu_temperature
...
8. Restart the munin-node daemon: `systemctl restart munin-node`.
9. Done. You should now start to see the charts on the Munin pages.
## Localization
@ -106,26 +125,22 @@ You can change the used locale by setting an environment variable in your plugin
env.locale en
## Different hosts for the fritzbox and your system
## Set a group for your fritzboxes
You can split the graphs of your fritzbox from the localhost graphs by following the next steps:
You can group the graphs of your fritzbox:
1. Use the following as your host configuration in `/etc/munin/munin.conf`
1. Use the following as your host configuration in `/etc/munin/munin.conf` or by creating a file in `/etc/munin/munin-conf.d`
[home.yourhost.net;server]
address 127.0.0.1
use_node_name yes
[home.yourhost.net;fritzbox]
[<groupname>;<fqdn>]
address 127.0.0.1
use_node_name no
2. Add the following to your munin-node configuration
example:
[Network;fritz.box]
address 127.0.0.1
use_node_name no
env.host_name fritzbox
3. Restart your munin-node: `systemctl restart munin-node`
2. Restart your munin-node: `systemctl restart munin-node`
## Environment Settings

View File

@ -3,6 +3,11 @@
fritzbox_connection_uptime - A munin plugin for Linux to monitor AVM Fritzbox connection uptime
Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license
@ -17,23 +22,25 @@
import os
import sys
from fritzconnection import FritzConnection
from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1]
def print_values():
try:
conn = FritzConnection(address=os.environ['fritzbox_ip'])
except Exception as e:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception:
sys.exit("Couldn't get connection uptime")
uptime = conn.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime']
print('uptime.value %.2f' % (int(uptime) / 86400.0))
uptime = conn.uptime
print('uptime.value %.2f' % (int(uptime) / 3600.0))
def print_config():
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box Connection Uptime")
print("graph_args --base 1000 -l 0")
print('graph_vlabel uptime in days')
print('graph_vlabel uptime in hours')
print("graph_scale no'")
print("graph_category network")
print("uptime.label uptime")

View File

@ -21,12 +21,13 @@ import sys
import fritzbox_helper as fh
PAGE = 'ecoStat'
hostname = os.path.basename(__file__).split('_')[1]
def get_cpu_temperature():
"""get the current cpu temperature"""
server = os.environ['fritzbox_ip']
server = hostname
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
@ -36,6 +37,7 @@ def get_cpu_temperature():
def print_config():
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box CPU temperature")
print("graph_vlabel degrees Celsius")
print("graph_category sensors")

4
fritzbox_cpu_usage.py → fritzbox__cpu_usage.py Executable file → Normal file
View File

@ -21,12 +21,13 @@ import sys
import fritzbox_helper as fh
PAGE = 'ecoStat'
hostname = os.path.basename(__file__).split('_')[1]
def get_cpu_usage():
"""get the current cpu usage"""
server = os.environ['fritzbox_ip']
server = hostname
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
@ -36,6 +37,7 @@ def get_cpu_usage():
def print_config():
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box CPU usage")
print("graph_vlabel %")
print("graph_category system")

4
fritzbox_memory_usage.py → fritzbox__memory_usage.py Executable file → Normal file
View File

@ -22,12 +22,13 @@ import fritzbox_helper as fh
PAGE = 'ecoStat'
USAGE = ['strict', 'cache', 'free']
hostname = os.path.basename(__file__).split('_')[1]
def get_memory_usage():
"""get the current memory usage"""
server = os.environ['fritzbox_ip']
server = hostname
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
@ -38,6 +39,7 @@ def get_memory_usage():
def print_config():
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box Memory")
print("graph_vlabel %")
print("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100")

View File

@ -24,12 +24,12 @@ import fritzbox_helper as fh
PAGE = 'energy'
DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb']
hostname = os.path.basename(__file__).split('_')[1]
def get_power_consumption():
"""get the current power consumption usage"""
server = os.environ['fritzbox_ip']
server = hostname
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
@ -41,6 +41,7 @@ def get_power_consumption():
def print_config():
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box Power Consumption")
print("graph_vlabel %")
print("graph_category system")

60
fritzbox_traffic.py → fritzbox__traffic.py Executable file → Normal file
View File

@ -3,6 +3,11 @@
fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic
Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license
@ -17,52 +22,65 @@
import os
import sys
from fritzconnection import FritzConnection
from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1]
def print_values():
try:
conn = FritzConnection(address=os.environ['fritzbox_ip'])
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get WAN traffic")
down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived']
print('down.value %d' % down_traffic)
traffic = conn.transmission_rate
up = traffic[0]*8
down = traffic[1]*8
print('down.value %d' % down)
up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent']
print('up.value %d' % up_traffic)
print('up.value %d' % up)
if not os.environ.get('traffic_remove_max'):
max_down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[
'NewLayer1DownstreamMaxBitRate']
print('maxdown.value %d' % max_down_traffic)
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_traffic = conn.max_bit_rate
print('maxdown.value %d' % max_traffic[1])
max_up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[
'NewLayer1UpstreamMaxBitRate']
print('maxup.value %d' % max_up_traffic)
print('maxup.value %d' % max_traffic[0])
def print_config():
try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get WAN traffic")
max_traffic = conn.max_bit_rate
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box WAN traffic")
print("graph_args --base 1000")
print("graph_vlabel bits in (-) / out (+) per \${graph_period}")
print("graph_vlabel bit up (+) / down (-) per ${graph_period}")
print("graph_category network")
print("graph_order down up maxdown maxup")
print("down.label received")
print("down.type DERIVE")
print("down.type GAUGE")
print("down.graph no")
print("down.cdef down,8,*")
#print("down.cdef down,8,*")
print("down.min 0")
print("down.max 1000000000")
print("down.max %d" % max_traffic[1])
#print("down.warning %.0f" % (max_traffic[1]*0.6))
#print("down.critical %.0f" % (max_traffic[1]*0.8))
print("up.label bps")
print("up.type DERIVE")
print("up.type GAUGE")
print("up.draw AREA")
print("up.cdef up,8,*")
#print("up.cdef up,8,*")
print("up.min 0")
print("up.max 1000000000")
print("up.max %d" % max_traffic[0])
print("up.negative down")
#print("up.warning %.0f" % (max_traffic[0]*0.6))
#print("down.critical %.0f" % (max_traffic[0]*0.8))
print("up.info Traffic of the WAN interface.")
if not os.environ.get('traffic_remove_max'):
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
print("maxdown.label received")
print("maxdown.type GAUGE")
print("maxdown.graph no")

92
fritzbox__traffic_down.py Normal file
View File

@ -0,0 +1,92 @@
#!/usr/bin/env python
"""
fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic
Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
This plugin requires the fritzconnection plugin. To install it using pip:
pip install fritzconnection
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
#%# capabilities=autoconf
"""
import os
import sys
from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1]
def print_values():
try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get WAN traffic")
traffic = conn.transmission_rate
up = traffic[0]*8
down = traffic[1]*8
print('down.value %d' % down)
print('up.value %d' % up)
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_traffic = conn.max_bit_rate
print('maxdown.value %d' % max_traffic[1])
print('maxup.value %d' % max_traffic[0])
def print_config():
try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get WAN traffic")
max_traffic = conn.max_bit_rate
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box WAN traffic")
print("graph_args --base 1000")
print("graph_vlabel bit down per ${graph_period}")
print("graph_category network")
print("graph_order down maxdown")
print("down.label bps")
print("down.type GAUGE")
print("down.draw AREA")
print("down.graph no")
print("down.min 0")
print("down.max %d" % max_traffic[1])
print("down.warning %.0f" % (max_traffic[1]*0.6))
print("down.critical %.0f" % (max_traffic[1]*0.8))
print("down.info Traffic of the WAN interface.")
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
print("maxdown.label received")
print("maxdown.type GAUGE")
print("maxdown.graph no")
print("maxdown.info Maximum down speed of the WAN interface.")
if os.environ.get('host_name'):
print("host_name " + os.environ['host_name'])
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print("yes") # Some docs say it'll be called with fetch, some say no arg at all
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'):
try:
print_values()
except:
sys.exit("Couldn't retrieve fritzbox traffic")

91
fritzbox__traffic_up.py Normal file
View File

@ -0,0 +1,91 @@
#!/usr/bin/env python
"""
fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic
Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
This plugin requires the fritzconnection plugin. To install it using pip:
pip install fritzconnection
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
#%# capabilities=autoconf
"""
import os
import sys
from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1]
def print_values():
try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get WAN traffic")
traffic = conn.transmission_rate
up = traffic[0]*8
down = traffic[1]*8
print('down.value %d' % down)
print('up.value %d' % up)
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_traffic = conn.max_bit_rate
print('maxdown.value %d' % max_traffic[1])
print('maxup.value %d' % max_traffic[0])
def print_config():
try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get WAN traffic")
max_traffic = conn.max_bit_rate
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box WAN traffic")
print("graph_args --base 1000")
print("graph_vlabel bit up per ${graph_period}")
print("graph_category network")
print("graph_order up maxup")
print("up.label bps")
print("up.type GAUGE")
print("up.draw AREA")
print("up.min 0")
print("up.max %d" % max_traffic[1])
print("up.warning %.0f" % (max_traffic[1]*0.6))
print("up.critical %.0f" % (max_traffic[1]*0.8))
print("up.info Traffic of the WAN interface.")
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
print("maxup.label MAX")
print("maxup.type GAUGE")
print("maxup.draw LINE1")
print("maxup.info Maximum up speed of the WAN interface.")
if os.environ.get('host_name'):
print("host_name " + os.environ['host_name'])
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print("yes") # Some docs say it'll be called with fetch, some say no arg at all
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'):
try:
print_values()
except:
sys.exit("Couldn't retrieve fritzbox traffic")

4
fritzbox_uptime.py → fritzbox__uptime.py Executable file → Normal file
View File

@ -31,12 +31,13 @@ minutesLoc = {"de": "Minuten", "en": "minutes"}
PAGE = 'energy'
pattern = re.compile(patternLoc[locale])
hostname = os.path.basename(__file__).split('_')[1]
def get_uptime():
"""get the current uptime"""
server = os.environ['fritzbox_ip']
server = hostname
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
@ -59,6 +60,7 @@ def get_uptime():
def print_config():
print("host_name %s" % hostname)
print("graph_title AVM Fritz!Box Uptime")
print("graph_args --base 1000 -l 0")
print('graph_vlabel uptime in days')

35
fritzbox_wifi_devices.py → fritzbox__wifi_devices.py Executable file → Normal file
View File

@ -3,6 +3,11 @@
fritzbox_wifi_devices - A munin plugin for Linux to monitor AVM Fritzbox
Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration:
@ -15,37 +20,29 @@
#%# family=auto contrib
#%# capabilities=autoconf
"""
import json
import os
import re
import sys
import fritzbox_helper as fh
locale = os.environ.get('locale', 'de')
patternLoc = {"de": r"(\d+) WLAN",
"en": r"(\d+) wireless LAN"}
PAGE = 'energy'
pattern = re.compile(patternLoc[locale])
from fritzconnection.lib.fritzwlan import FritzWLAN
hostname = os.path.basename(__file__).split('_')[1]
def get_connected_wifi_devices():
"""gets the numbrer of currently connected wifi devices"""
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
try:
conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get connection uptime")
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
m = re.search(pattern, data['data']['drain'][2]['statuses'][-1])
if m:
connected_devices = int(m.group(1))
print('wifi.value %d' % connected_devices)
connected_devices = conn.host_number
print('wifi.value %d' % connected_devices)
def print_config():
print("host_name %s" % hostname)
print('graph_title AVM Fritz!Box Connected Wifi Devices')
print('graph_vlabel Number of devices')
print('graph_args --base 1000')

0
fritzbox_helper.py Executable file → Normal file
View File