Skip to content

Commit

Permalink
Implement metrics configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
ndecker committed Dec 12, 2022
1 parent 3defd66 commit 146ccd9
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 472 deletions.
289 changes: 80 additions & 209 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Fritz!Box Upnp statistics exporter for prometheus
# FRITZ!Box Upnp statistics exporter for prometheus

This exporter exports some variables from an
[AVM Fritzbox](http://avm.de/produkte/fritzbox/)
to prometheus.
This exporter exports some variables from an [AVM Fritzbox](http://avm.de/produkte/fritzbox/) to prometheus.

## Compatibility

Expand Down Expand Up @@ -35,27 +33,9 @@ This exporter is known to work with the following models:
git clone https://github.com/ndecker/fritzbox_exporter/
docker build -t fritzbox_exporter fritzbox_exporter

## Running

In the configuration of the Fritzbox the option "Statusinformationen über UPnP übertragen" in the dialog "Heimnetz >
Heimnetzübersicht > Netzwerkeinstellungen" has to be enabled.

## Configuration

| command line parameter | environment variable | default | |
|------------------------|---------------------------|-----------|------------------------------------------------|
| -listen-address | FRITZBOX_EXPORTER_LISTEN | :9133 | The address to listen on for HTTP requests |
| -gateway-address | FRITZBOX_DEVICE | fritz.box | The hostname or IP of the FRITZ!Box |
| -gateway-port | FRITZBOX_PORT | 49000 | The port of the FRITZ!Box UPnP service |
| -gateway-port | FRITZBOX_PORT_TLS | 49443 | The port of the FRITZ!Box TLS UPnP service |
| -username | FRITZBOX_USERNAME | | The user for the FRITZ!Box UPnP service |
| -password | FRITZBOX_PASSWORD | | The password for the FRITZ!Box UPnP service |
| -use-tls | FRITZBOX_USE_TLS | true | Use TLS/HTTPS connection to FRITZ!Box |
| -allow-selfsigned | FTITZBOX_ALLOW_SELFSIGNED | true | Allow selfsigned certificate from FRITZ!Box |
| -test | | | Print all available metrics to stdout and exit |


## Prerequisites
In the configuration of the Fritzbox the option "Statusinformationen über UPnP übertragen" has to be enabled.

### FRITZ!OS 7.00+

`Heimnetz` > `Netzwerk` > `Netwerkeinstellungen` > `Statusinformationen über UPnP übertragen`
Expand All @@ -64,190 +44,81 @@ Heimnetzübersicht > Netzwerkeinstellungen" has to be enabled.

`Heimnetz` > `Heimnetzübersicht` > `Netzwerkeinstellungen` > `Statusinformationen über UPnP übertragen`


## Configuration

| command line parameter | environment variable | default | |
|------------------------|---------------------------|------------|------------------------------------------------------------|
| -metrics | FRITZBOX_EXPORTER_METRICS | <internal> | YAML file describing exported metrics |
| -test-metrics | | | Test which metrics can be read and print YAML metrics file |
| -listen-address | FRITZBOX_EXPORTER_LISTEN | :9133 | The address to listen on for HTTP requests |
| -gateway-address | FRITZBOX_DEVICE | fritz.box | The hostname or IP of the FRITZ!Box |
| -gateway-port | FRITZBOX_PORT | 49000 | The port of the FRITZ!Box UPnP service |
| -gateway-port | FRITZBOX_PORT_TLS | 49443 | The port of the FRITZ!Box TLS UPnP service |
| -username | FRITZBOX_USERNAME | | The user for the FRITZ!Box UPnP service |
| -password | FRITZBOX_PASSWORD | | The password for the FRITZ!Box UPnP service |
| -use-tls | FRITZBOX_USE_TLS | true | Use TLS/HTTPS connection to FRITZ!Box |
| -allow-selfsigned | FRITZBOX_ALLOW_SELFSIGNED | true | Allow selfsigned certificate from FRITZ!Box |


## Exported metrics

These metrics are exported:

# HELP fritzbox_exporter_collect_errors Number of collection errors.
# TYPE fritzbox_exporter_collect_errors counter
fritzbox_exporter_collect_errors 0
# HELP gateway_wan_bytes_received bytes received on gateway WAN interface
# TYPE gateway_wan_bytes_received counter
gateway_wan_bytes_received{gateway="fritz.box"} 5.037749914e+09
# HELP gateway_wan_bytes_sent bytes sent on gateway WAN interface
# TYPE gateway_wan_bytes_sent counter
gateway_wan_bytes_sent{gateway="fritz.box"} 2.55707479e+08
# HELP gateway_wan_connection_status WAN connection status (Connected = 1)
# TYPE gateway_wan_connection_status gauge
gateway_wan_connection_status{gateway="fritz.box"} 1
# HELP gateway_wan_connection_uptime_seconds WAN connection uptime
# TYPE gateway_wan_connection_uptime_seconds gauge
gateway_wan_connection_uptime_seconds{gateway="fritz.box"} 65259
# HELP gateway_wan_layer1_downstream_max_bitrate Layer1 downstream max bitrate
# TYPE gateway_wan_layer1_downstream_max_bitrate gauge
gateway_wan_layer1_downstream_max_bitrate{gateway="fritz.box"} 1.286e+07
# HELP gateway_wan_layer1_link_status Status of physical link (Up = 1)
# TYPE gateway_wan_layer1_link_status gauge
gateway_wan_layer1_link_status{gateway="fritz.box"} 1
# HELP gateway_wan_layer1_upstream_max_bitrate Layer1 upstream max bitrate
# TYPE gateway_wan_layer1_upstream_max_bitrate gauge
gateway_wan_layer1_upstream_max_bitrate{gateway="fritz.box"} 1.148e+06
# HELP gateway_wan_packets_received packets received on gateway WAN interface
# TYPE gateway_wan_packets_received counter
gateway_wan_packets_received{gateway="fritz.box"} 1.346625e+06
# HELP gateway_wan_packets_sent packets sent on gateway WAN interface
# TYPE gateway_wan_packets_sent counter
gateway_wan_packets_sent{gateway="fritz.box"} 3.05051e+06


## Output of -test

The exporter prints all available Variables to stdout when called with the -test option.
These values are determined by parsing all services from http://fritz.box:49000/igddesc.xml

GetFirewallStatus
FirewallEnabled: true
InboundPinholeAllowed: false
GetInfo
MaxCharsPassword: 32
MinCharsPassword: 0
AllowedCharsPassword: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
X_AVM-DE_GetAnonymousLogin
X_AVM-DE_AnonymousLoginEnabled: false
X_AVM-DE_ButtonLoginEnabled: false
X_AVM-DE_GetUserList
X_AVM-DE_UserList: <List><Username last_user="1">xxx</Username>
X_AVM-DE_GetWLANConnectionInfo
AssociatedDeviceMACAddress: <nil>
SSID: <nil>
BSSID: <nil>
BeaconType: <nil>
Channel: <nil>
Standard: <nil>
X_AVM-DE_SignalStrength: <nil>
X_AVM-DE_Speed: <nil>
X_AVM-DE_SpeedRX: <nil>
X_AVM-DE_SpeedMax: <nil>
X_AVM-DE_SpeedRXMax: <nil>
GetHostNumberOfEntries
HostNumberOfEntries: 5
X_AVM-DE_GetChangeCounter
X_AVM-DE_ChangeCounter: 0
X_AVM-DE_DoUpdate
UpgradeAvailable: false
X_AVM-DE_UpdateState: NoUpdate
GetSecurityPort
SecurityPort: 49443
GetAddonInfos
ByteSendRate: 35
ByteReceiveRate: 26
PacketSendRate: 0
PacketReceiveRate: 0
TotalBytesSent: 354858561
TotalBytesReceived: 626712195
AutoDisconnectTime: 0
IdleDisconnectTime: 1
DNSServer1: xxx.xxx.xxx.xxx
DNSServer2: xxx.xxx.xxx.xxx
VoipDNSServer1: xxx.xxx.xxx.xxx
VoipDNSServer2: xxx.xxx.xxx.xxx
UpnpControlEnabled: false
RoutedBridgedModeBoth: 1
X_AVM_DE_TotalBytesSent64: 354858561
X_AVM_DE_TotalBytesReceived64: 4921679491
X_AVM_DE_WANAccessType: DSL
X_AVM_DE_GetDsliteStatus
X_AVM_DE_DsliteStatus: false
X_AVM_DE_GetIPTVInfos
X_AVM_DE_IPTV_Enabled: false
X_AVM_DE_IPTV_Provider:
X_AVM_DE_IPTV_URL:
GetCommonLinkProperties
WANAccessType: DSL
Layer1UpstreamMaxBitRate: 33251000
Layer1DownstreamMaxBitRate: 114110000
PhysicalLinkStatus: Up
GetTotalBytesSent
TotalBytesSent: 354858561
GetTotalBytesReceived
TotalBytesReceived: 626712195
GetTotalPacketsSent
TotalPacketsSent: 245896
GetTotalPacketsReceived
TotalPacketsReceived: 69248
X_AVM_DE_GetDNSServer
IPv4DNSServer1: xxx.xxx.xxx.xxx
IPv4DNSServer2: xxx.xxx.xxx.xxx
GetIdleDisconnectTime
IdleDisconnectTime: 0
GetStatusInfo
ConnectionStatus: Connected
LastConnectionError: ERROR_NONE
Uptime: 70993
GetNATRSIPStatus
RSIPAvailable: false
NATEnabled: true
GetAutoDisconnectTime
AutoDisconnectTime: 0
X_AVM_DE_GetIPv6Prefix
IPv6Prefix:
PrefixLength: 0
ValidLifetime: 0
PreferedLifetime: 0
GetConnectionTypeInfo
ConnectionType: IP_Routed
PossibleConnectionTypes: IP_Routed
X_AVM_DE_GetExternalIPv6Address
ExternalIPv6Address:
PrefixLength: 0
ValidLifetime: 0
PreferedLifetime: 0
X_AVM_DE_GetIPv6DNSServer
IPv6DNSServer1:
ValidLifetime1: 0
IPv6DNSServer2:
ValidLifetime2: 2003335812
GetExternalIPAddress
ExternalIPAddress: xxx.xxx.xxx.xxx
X_AVM-DE_GetNightControl
NightControl: <rule id="0" enabled="0"><item day="127" time="2100" action="0" /><item
day="127" time="2300" action="1" /></rule>

NightTimeControlNoForcedOff: false
X_AVM-DE_GetWLANConnectionInfo
AssociatedDeviceMACAddress: <nil>
SSID: <nil>
BSSID: <nil>
BeaconType: <nil>
Channel: <nil>
Standard: <nil>
X_AVM-DE_SignalStrength: <nil>
X_AVM-DE_Speed: <nil>
X_AVM-DE_SpeedRX: <nil>
X_AVM-DE_SpeedMax: <nil>
X_AVM-DE_SpeedRXMax: <nil>
X_AVM-DE_GetWLANConnectionInfo
AssociatedDeviceMACAddress: <nil>
SSID: <nil>
BSSID: <nil>
BeaconType: <nil>
Channel: <nil>
Standard: <nil>
X_AVM-DE_SignalStrength: <nil>
X_AVM-DE_Speed: <nil>
X_AVM-DE_SpeedRX: <nil>
X_AVM-DE_SpeedMax: <nil>
X_AVM-DE_SpeedRXMax: <nil>
GetAutoConfig
AutoConfig: false
GetModulationType
ModulationType:
GetDSLLinkInfo
LinkType: PPPoE
LinkStatus: Up
GetATMEncapsulation
ATMEncapsulation:
GetFCSPreserved
FCSPreserved: false
GetDestinationAddress
DestinationAddress:
The default metrics to be exported are described in [default-metrics.yaml](default-metrics.yaml).
This file is compiled into the binary and used by default.
With the `-metrics` option a different file can be specified.

With the `-test-metrics` option all possible metrics of the FRITZ!Box can be queried. This can take a few minutes.
For TR64 metrics username/password must be provided.

fritzbox_exporter -test-metrics > metrics.yaml
edit metrics.yaml
fritzbox_exporter -metrics metrics.yaml

### Examples

This is an example metric as exported by `-test-metrics`

- metric: "" # prometheus metric name (required)
help: "" # prometheus help text
type: "" # metric type: gauge, counter
service: urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
action: GetTotalBytesReceived
result: TotalBytesReceived
examplevalue: "325538505" # current value of the metric. Only for info; not used
source: "igddesc.xml" # source of the value (iggdesc.xml or tr64desc.xml). Only for info; not used


If you wanted to for example to monitor the number of hosts in you local network, you could use this:

- metric: "gateway_number_of_hosts"
help: "Number of hosts in the local network"
type: "gauge"
service: urn:dslforum-org:service:Hosts:1
action: GetHostNumberOfEntries
result: HostNumberOfEntries

### Metrics with `okvalue`

If the value is a string you can use the `okvalue` field to specify a value to compare the string to.
The metric will be 1 if the value matches okvalue; 0 otherwise.

- metric: gateway_wan_layer1_link_status
help: Status of physical link (Up = 1)
type: gauge
service: urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
action: GetCommonLinkProperties
result: PhysicalLinkStatus
okvalue: Up

### Metrics with `labelname`

You can specify `labelname` to set a metric label with the value. The metric value will always be 1.
The following will give a metric `gateway_version{device="fritz.box", version="113.07.29"} = 1`

- metric: "gateway_version"
type: "gauge"
service: urn:dslforum-org:service:DeviceInfo:1
action: GetInfo
result: SoftwareVersion
labelname: version
source: tr64desc.xml
Loading

0 comments on commit 146ccd9

Please sign in to comment.