1
0
mirror of https://github.com/Tafkas/fritzbox-munin.git synced 2023-10-10 13:36:55 +02:00

Merge pull request #1 from oe73773/multi-fb-support

Multi fb support
This commit is contained in:
oe73773 2020-07-12 21:42:35 +02:00 committed by GitHub
commit c1ea899479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 277 additions and 60 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

@ -24,11 +24,12 @@ import sys
from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1]
def print_values():
try:
conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
except Exception as e:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception:
sys.exit("Couldn't get connection uptime")
uptime = conn.uptime
@ -36,6 +37,7 @@ def print_values():
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 hours')

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")

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

@ -24,15 +24,18 @@ import sys
from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1]
def print_values():
try:
conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
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]
down = traffic[1]
up = traffic[0]*8
down = traffic[1]*8
print('down.value %d' % down)
print('up.value %d' % up)
@ -46,29 +49,31 @@ def print_values():
def print_config():
try:
conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
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 (-) / down (+) 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 %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 %d" % max_traffic[0])
print("up.negative down")

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')

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

@ -25,13 +25,15 @@ import sys
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"""
try:
conn = FritzWLAN(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e:
print(e)
sys.exit("Couldn't get connection uptime")
@ -40,6 +42,7 @@ def get_connected_wifi_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