Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versatile Smart Home Stats (Power, Battery, Humidity, States, Temperatures) and wifi link speeds (FritzOS 7.56) #8

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 108 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Munin Plugins for FritzBox

A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a FRITZ!Box 7590 running FRITZ!OS 7.50 and a FRITZ!WLAN Repeater 1750E running FRITZ!OS 7.27.
A collection of munin plugins to monitor your AVM FRITZ!Box
router. The scripts have been developed using a FRITZ!Box
7490,7590,5690 Pro running FRITZ!OS 7.50...7.62 and a FRITZ!WLAN
Repeater 1750E running FRITZ!OS 7.27.

If you are using the scripts on a different FRITZ!Box model please let me know by

Expand All @@ -9,6 +12,7 @@ If you are using the scripts on a different FRITZ!Box model please let me know b

These python scripts are [Munin](http://munin-monitoring.org) plugins for monitoring the [FRITZ!Box](https://avm.de/produkte/fritzbox/) router by AVM.


## Purpose of this Fork

The scripts are build upon the original [fritzbox-munin](https://github.com/Tafkas/fritzbox-munin) with the goal to make use of the modern APIs that FRITZ!OS 7 provides.
Expand All @@ -25,7 +29,9 @@ The main differences to the original version are:
- FRITZ!Box router with FRITZ!OS >= 07.50 (if you are on an older FRITZ!OS version, select an older version of fritzbox-munin-fast by browsing the tags in this repository)
- Munin 1.4.0 or later is required
- Python 3.x

- Recommendation: python venv installation in munin home directory


## Available Plugins

### Connection Uptime
Expand All @@ -36,12 +42,12 @@ Shows the WAN connection uptime.
### DSL Errors
Plugin: `fritzbox_dsl.py`
Multigraph plugin, showing:
- DSL checksum errors
- DSL transmission errors
- line loss
- link capacity
- error correction statistics
- signal-to-noise ratio
- DSL checksum errors<br>![DSL checksum errors](doc/dsl_crc-month.png)
- DSL transmission errors<br>![DSL transmission errors](doc/dsl_errors-month.png)
- line loss<br>![line loss](doc/dsl_damping-month.png)
- signal-to-noise ratio<br>![signal-to-noise ratio](doc/dsl_snr-month.png)
- link capacity<br>![link capacity](doc/dsl_capacity-month.png)
- error correction statistics<br>![error correction statistics](doc/dsl_ecc-month.png)

### CPU & Memory
Plugin: `fritzbox_ecostat.py`
Expand All @@ -50,9 +56,30 @@ Multigraph plugin, showing:
- CPU load
- CPU temperature

### Smart Home Temperature
Plugin: `fritzbox_smart_home_temperature.py`
![Smart Home Temperature](doc/smart_home_temperature.png)
Note: Currently not supported by FRITZ!Box 5690 Pro with FRITZ!OS 7.62.

### Smart Home
Plugin: `fritzbox_smart_home.py`
Multigraph plugin, showing
- Battery state of battery driven smart home devices
<br>![Battery state of battery driven smart home devices](doc/battery-month.png)
- Energy (kWh aggregated over lifetime) of smart home power devices
<br>![Energy (kWh aggregated over lifetime)](doc/energy-month.png)
- Instantaneous power of smart home power devices (W instantaneously, sub-sampled due to 5 minute munin sampling grid, most accurate in resolution, inaccurate w.r.t. energy/average due to sub-sampling)
<br>![Instantaneous power of smart home power devices](doc/smarthome_power-week.png)
- Average power of smart home power devices (W derived from energy counters, accurate w.r.t. average and hence no sub-sampling issue, tendency to visual noise in 5 minute sampling grid, but exact when averaged e.g. in weekly plots with 30 min sampling grid)
<br>![Average power of smart home power devices: Day](doc/smarthome_powerAvg-day.png)
![Average power of smart home power devices: Week](doc/smarthome_powerAvg-week.png)
- Power switch on/off
- Voltage measurements for smart home power devivces
<br>![Voltage measurements for smart home power devivces](doc/voltage-day.png)
- Measured temperature for temperature sensors
<br>![Measured temperature for temperature sensors](doc/temperatures-day.png)
- Target temperature for thermostats
- Humidity sensors
<br>![Humidity sensors](doc/humidity-day.png)



### Energy
Plugin: `fritzbox_energy.py`
Expand All @@ -61,47 +88,108 @@ Multigraph plugin, showing:
- devices connected on WiFi and LAN
- system uptime

Note: Currently not supported by FRITZ!Box 5690 Pro with FRITZ!OS 7.62.

### Link Saturation
Plugin: `fritzbox_link_saturation.py`
Multigraph plugin, showing saturation of WAN uplink and downlink by QoS priority
<br>![Uplink saturation](doc/saturation_up-day.png)
![Downlink saturation](doc/saturation_down-day.png)


### Traffic
Plugin: `fritzbox_traffic.py`
Similar to fritzbox_link_saturation, but single-graph and without QoS monitoring.

### Wifi
### Wifi Load
Plugin: `fritzbox_wifi_load.py`
Multigraph plugin, showing for 2.4GHz and 5GHz
Multigraph plugin
- 2.4 GHz
- 5 GHz
- 6 GHz
- WiFi uplink and downlink bandwidth usage
<br>![2.4 GHz Saturation](doc/bandwidth_24ghz-week.png)
![5 GHz Saturation](doc/bandwidth_5ghz-week.png)
- neighbor APs on same and on different channels

<br>![2.4 GHz Neighbors](doc/neighbors_24ghz-week.png)
![5 GHz Neighbors](doc/neighbors_5ghz-week.png)

### Wifi Speed
Plugin: `fritzbox_wifi_speed.py`
Multigraph plugin
- 2.4 GHz instantaneous RX and TX speeds per connected device
<br>![2.4 GHz RX Speed](doc/wifiDeviceSpeed_ghz24_rx-week.png)
![2.4 GHz TX Speed](doc/wifiDeviceSpeed_ghz24_tx-week.png)
- 5 GHz instantaneous RX and TX speeds per connected device
<br>![5 GHz RX Speed](doc/wifiDeviceSpeed_ghz5_rx-week.png)
![5 GHz TX Speed](doc/wifiDeviceSpeed_ghz5_tx-week.png)
- 6 GHz instantaneous RX and TX speeds per connected device
<br>![6 GHz RX Speed](doc/wifiDeviceSpeed_ghz6_rx-week.png)
![6 GHz TX Speed](doc/wifiDeviceSpeed_ghz6_tx-week.png)
- Ethernet instantaneous RX and TX speeds per connected device

## Installation & Configuration


1. Pre-requisites for the `fritzbox_traffic` and `fritzbox_connection_uptime` plugins are the [fritzconnection](https://pypi.python.org/pypi/fritzconnection) and [requests](https://pypi.python.org/pypi/requests) package. To install run

- Recommended: python venv in munin home directory

```
sudo -u munin bash
cd ~munin
python3 -m venv venv
source ~munin/venv/bin/activate
~munin/venv/bin/python3 -m pip install -r <path-to-your-git-clone>/requirements.txt
```

- Alternative without venv (pip might complain that the packages are centrally managed by your distribution's packaging tool):

```
pip install -r requirements.txt
```

1. Make sure the FRITZ!Box has UPnP status information enabled. (web interface: _Home Network > Network > Network Settings > Universal Plug & Play (UPnP)_)

1. Copy all the scripts from `src/` folder to `/usr/share/munin/plugins`

1. (optional) If you want to connect to FRITZ!Box using SSL, download the Fritz certificate (web interface: _Internet > Freigaben > FritzBox Dienste > Zertifikat > Zertifikat herunterladen_) and save it to `/etc/munin/box.cer`.

1. Create entry in `/etc/munin/plugin-conf.d/munin-node`:
1. Create entry in `/etc/munin/plugin-conf.d/munin-node`, for example (please check further configuration options inside the plugin documentation, typically in form of comments at the top of each plugin):

[fritzbox_*]
env.fritzbox_password <fritzbox_password>
env.fritzbox_user <fritzbox_user>
env.fritzbox_use_tls true
host_name fritzbox

env.fritzbox_ip fritz.box
env.fritzbox_password <fritzbox_password>
env.fritzbox_user <fritzbox_user>
env.fritzbox_use_tls true
env.fritzbox_certificate <path to certificate used by the FRITZ!Box>
env.ecostat_modes cpu temp ram
env.dsl_modes capacity snr damping errors crc ecc
env.energy_modes power devices uptime
env.energy_product DSL

env.wifi_freqs 24 5 6
env.wifi_modes freqs neighbors
env.locale de
env.wifi_speeds_dev_info_storage_path <path for a temporary .json file where the plugin stores device names in order to "remember" and display their history in the munin-stats even while they are disconnected and do not appear in the stats of the FRITZ!Box, e.g. /var/lib/munin-node/persistent-plugin-state/fritzbox-wifi-speed.json>
# env.traffic_remove_max true # if you do not want the possible max values

host_name fritzbox
user munin


See the plugin files for plugin-specific configuration options.

1. For each plugin you want to activate, create a symbolic link to `/etc/munin/plugins`, e.g.:
```
ln -s fritzbox_dsl.py /etc/munin/plugins/fritzbox_dsl.py
ln -s /usr/share/munin/plugins/fritzbox_dsl.py /etc/munin/plugins/
ln -s /usr/share/munin/plugins/fritzbox_connection_uptime.sh /etc/munin/plugins/
...
```

<em>Please note that you need to take the .sh version in case of venv usage for fritzbox_traffic and fritzbox_connection_uptime, see above under "Pre-requisites"</em>

1. Restart the munin-node daemon: `service munin-node restart`.

1. Done. You should now start to see the charts on the Munin pages!
Expand Down
Binary file added doc/bandwidth_24ghz-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/bandwidth_5ghz-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/battery-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/dsl_capacity-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/dsl_crc-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/dsl_damping-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/dsl_ecc-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/dsl_errors-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/dsl_snr-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/energy-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/humidity-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/neighbors_24ghz-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/neighbors_5ghz-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/saturation_down-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/saturation_up-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/smart_home_temperature.png
Binary file not shown.
Binary file added doc/smarthome_power-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/smarthome_powerAvg-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/smarthome_powerAvg-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/temperatures-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/voltage-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/wifiDeviceSpeed_ghz24_rx-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/wifiDeviceSpeed_ghz24_tx-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/wifiDeviceSpeed_ghz5_rx-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/wifiDeviceSpeed_ghz5_tx-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/wifiDeviceSpeed_ghz6_rx-week.png
Binary file added doc/wifiDeviceSpeed_ghz6_tx-week.png
10 changes: 9 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
fritzconnection>=1.3.0
requests
lxml
lxml
chardet
pyfritzhome
fritzchecksum
fritzctl
fritzcollectd
fritzremote
fritzhome
fritzconnection
67 changes: 55 additions & 12 deletions src/FritzboxConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,58 @@ class FritzboxConfig:
useTls = True
certificateFile = str(os.getenv('MUNIN_CONFDIR')) + '/box.cer'

# default constructor
def __init__(self):
if os.getenv('fritzbox_ip'):
self.server = str(os.getenv('fritzbox_ip'))
if os.getenv('fritzbox_port'):
self.port = int(os.getenv('fritzbox_port'))
self.user = str(os.getenv('fritzbox_user'))
self.password = str(os.getenv('fritzbox_password'))
if os.getenv('fritzbox_certificate'):
self.certificateFile = str(os.getenv('fritzbox_certificate'))
if os.getenv('fritzbox_use_tls'):
self.useTls = str(os.getenv('fritzbox_use_tls')) == 'true'
def __init__(self,
fritzbox_ip = None,
fritzbox_port = None,
fritzbox_user = None,
fritzbox_password = None,
fritzbox_certificate = None,
fritzbox_useTls = None,
):
if fritzbox_ip is None:
if os.getenv('fritzbox_ip'):
self.server = str(os.getenv('fritzbox_ip'))
# end if
else:
self.server = fritzbox_ip
# end if

if fritzbox_port is None:
if os.getenv('fritzbox_port'):
self.port = int(os.getenv('fritzbox_port'))
# end if
else:
self.port = fritzbox_port
# end if

if fritzbox_user is None:
self.user = str(os.getenv('fritzbox_user'))
else:
self.user = fritzbox_user
# endif

if fritzbox_password is None:
self.password = str(os.getenv('fritzbox_password'))
else:
self.password = fritzbox_password
# endif

if fritzbox_certificate is None:
if os.getenv('fritzbox_certificate'):
self.certificateFile = str(os.getenv('fritzbox_certificate'))
# endif
else:
self.certificateFile = fritzbox_certificate
# endif

if fritzbox_useTls is None:
if os.getenv('fritzbox_use_tls'):
self.useTls = str(os.getenv('fritzbox_use_tls')) == 'true'
# endif
else:
self.useTls = fritzbox_use_tls
# endif

# end __init__
# end class FritzboxConfig

11 changes: 9 additions & 2 deletions src/FritzboxInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ class FritzboxInterface:
__baseUri = ""

# default constructor
def __init__(self):
self.config = FritzboxConfig()
def __init__(self,
config = None
):
if config is None:
self.config = FritzboxConfig()
else:
self.config = config
# endif

self.__session = FritzboxFileSession(self.config.server, self.config.user, self.config.port)
self.__baseUri = self.__getBaseUri()

Expand Down
7 changes: 4 additions & 3 deletions src/fritzbox_connection_uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ def __init__(self):
sys.exit("Couldn't get connection uptime: " + str(e))

def printUptime(self):
print('uptime.value %.2f' % (int(self.__connection.uptime) / 3600.0))
print('connUptime.value %.2f' % (int(self.__connection.uptime) / 3600.0))

def printConfig(self):
print("graph_title Connection Uptime")
print("graph_args --base 1000 -l 0")
print("graph_vlabel uptime in hours")
print("graph_scale no")
print("graph_category network")
print("uptime.label uptime")
print("uptime.draw AREA")
print("connUptime.label uptime")
print("connUptime.type GAUGE")
print("connUptime.draw AREA")
print("graph_info The uptime in hours after the last disconnect.<br />Public IP address (ipv4): " + self.__connection.external_ip + ", Public IP address (ipv6): " + self.__connection.external_ipv6)

if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions src/fritzbox_connection_uptime.sh
Loading