Coder Social home page Coder Social logo

fritzbox_exporter's Introduction

FRITZ!Box Upnp statistics exporter for prometheus

This exporter exports some variables from an AVM Fritzbox to prometheus.

Compatibility

This exporter is known to work with the following models:

Model Firmware
FRITZ!Box 4040 06.83
FRITZ!Box 6490 6.51
FRITZ!Box 7390 6.51
FRITZ!Box 7490 6.51, 7.29
FRITZ!Box 7560 6.92
FRITZ!Box 7362 SL 7.12

Building

Go install

go install github.com/ndecker/fritzbox_exporter@latest

Go build

git clone https://github.com/ndecker/fritzbox_exporter/
cd fritzbox_exporter
go build
go install

Docker

git clone https://github.com/ndecker/fritzbox_exporter/
docker build -t fritzbox_exporter fritzbox_exporter

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

FRITZ!OS 6

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

Configuration

command line parameter environment variable default
-metrics FRITZBOX_EXPORTER_METRICS 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

The default metrics to be exported are described in 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

fritzbox_exporter's People

Contributors

123haynes avatar bachp avatar dependabot[bot] avatar iwittkau avatar juergenhoetzel avatar lfuelling avatar ndecker avatar themarix avatar xperimental avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fritzbox_exporter's Issues

Idea: Allow to scrape multiple fritzboxes

Currently the exporter can connect to exactly one fritzbox. So in order so monitor multiple devices multiple exporters need to be setup. And a new port assigned to each.

Other exporters that pull in metrics from other sources like the snmp_exporter or the blackbox_exporter allow to fetch from multiple sources at once.

I propose to extend the exporter to support multiple devices with a single process.
Most probaly the best way would be through a config file specifying which fritz boxes to scrape or torough paramters sent from prometheus like it is done for blackbox_exporter. So something like: http://localhost:9133/probe?address=fritz.box&port=49000.

Does this feature make sense or does it just over complicate stuff?

Release Package no usable

Maybe it is due to my lack of understanding of the GO language, but downloading and trying to use your release packe does not seem possible.

package .
imports ./vendor/github.com/prometheus/client_golang/prometheus: must be imported as github.com/prometheus/client_golang/prometheus

If I get all of that right it means I have to install directly from GitHub. So what is the purpose of the release package?

I prefer release packages as they ensure if I have them stored locally I can re-use them 10 years from now, weather you deleted your project or not.

Please advise if this is just my lack of understanding.

Panic when network is unreachable

Would be nice to handle this without aborting the program. Happened after a reboot with the systemd service starting before the network was up. DNS resolution worked because it was done on the local box.

panic: Get http://fritz.box:49000/igddesc.xml: dial tcp 192.168.0.1:49000: connect: network is unreachable
goroutine 1 [running]:
panic(0x852280, 0xc8201108a0)
        /usr/lib/go/src/runtime/panic.go:481 +0x3e6
main.main()
        .../src/src/github.com/ndecker/fritzbox_exporter/main.go:250 +0xbf

Thanks for creating this by the way, it's a nice source of data for my Grafana dashboard (using it for used bandwidth, available DSL bandwidth & uptime)

Incompatible with latest go versions

Hi,

go get github.com/ndecker/fritzbox_exporter

works under

  • ubuntu 20.04 with ubuntu-packaged go 1.13.8
  • alpine 3.13 with go 1.15.12

but not with

  • alpine 3.14 with go 1.16.5
  • ubuntu 20.04 with snap package go 1.16.6

Error message in both cases:

go/pkg/mod/github.com/ndecker/[email protected]/main.go:326:26: undefined: prometheus.Handler

Crashes at start: 606 - Action Not Authorized

I am using the latest published docker version and a 6660 (cable).
From the logs, it seems that the connection is properly established but it breaks right after.

LOG LEVEL READ FROM CONFIG
2021-09-02 20:11:10,168     INFO fritzexporter | registering 192.168.178.1 to collector
2021-09-02 20:11:10,984     INFO fritzexporter.fritzdevice | Connection to 192.168.178.1 successful, reading capabilities
2021-09-02 20:11:10,984    DEBUG fritzexporter.fritzcapability | Capability DeviceInfo set to {self.present} on device {device.host}
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/app/fritzexporter/__main__.py", line 74, in <module>
    main()
  File "/app/fritzexporter/__main__.py", line 58, in main
    FritzDevice(dev['hostname'], dev['username'], dev['password'], dev['name']))
  File "/app/fritzexporter/fritzdevice.py", line 35, in __init__
    self.capabilities = FritzCapabilities(self)
  File "/app/fritzexporter/fritzcapabilities.py", line 75, in __init__
    self.checkPresent(device)
  File "/app/fritzexporter/fritzcapabilities.py", line 99, in checkPresent
    self.capabilities[c].checkCapability(device)
  File "/app/fritzexporter/fritzcapabilities.py", line 46, in checkCapability
    device.fc.call_action(svc, action)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 227, in call_action
    return self.soaper.execute(service, action_name, arguments)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 238, in execute
    return handle_response(response)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 222, in handle_response
    raise_fritzconnection_error(response)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 147, in raise_fritzconnection_error
    raise exception(message)
fritzconnection.core.exceptions.FritzSecurityError: UPnPError: 
errorCode: 606
errorDescription: Action Not Authorized

Remote Monitoring?

Hello,

Is it possible to remote monitore a fritzbox with this exporter? Auf so, how can it be done using only the fritz box at the other network, no additional device.
Some Upnp Port opening on the fritzbox?

Hope to get some help thanks great work

test fails

followed instructions: https://github.com/ndecker/fritzbox_exporter#building
but received error before using

 △ github.com/ndecker/fritzbox_exporter @ raspberrypi ./fritzbox_exporter -h                                                                                      master :: 784d :: ⬢
Usage of ./fritzbox_exporter:
  -gateway-address string
        The hostname or IP of the FRITZ!Box (default "fritz.box")
  -gateway-port int
        The port of the FRITZ!Box UPnP service (default 49000)
  -listen-address string
        The address to listen on for HTTP requests. (default ":9133")
  -test
        print all available metrics to stdout

 △ github.com/ndecker/fritzbox_exporter @ raspberrypi ./fritzbox_exporter -test                                                                                   master :: 784d :: ⬢
panic: EOF

goroutine 1 [running]:
panic(0x2d94e0, 0x10726058)
        /usr/lib/go-1.7/src/runtime/panic.go:500 +0x33c
main.test()
        /root/go/src/github.com/ndecker/fritzbox_exporter/main.go:285 +0xa8
main.main()
        /root/go/src/github.com/ndecker/fritzbox_exporter/main.go:312 +0x2c

Creating a Fork, reviving the project.

Hello everyone,

reading through the state of this repository, it seems like the author has moved on. Which is completely fine! I have much appreciation and would like to thank @ndecker a lot for the awesome project he has created!

I have not really found that many alternatives to this project. There are some projects like https://github.com/wbwue/FritzExporter by @wbwue or https://github.com/pdreker/fritzbox_exporter by @pdreker , which are worth exploring and contacting.

My go experience is only average, but I have several ideas on how to push this project forward. I would like to start by creating a fork and eventually finding a few co-maintainer. They should be OK with the PR-based workflow and have at least some existing FOSS-Contribution history, then I am happy to add them as maintainer to the fork.
The goal would be to get things into shape with fixes tests, moving from vendoring to go modules.

Then collect issues and existing PRs and throw everything into the coming Hacktoberfest and hack on it.

With this issue I want to call out of anyone interested in helping or maybe there is already such an ongoing effort I have overlooked!

Happy to hear from anyone.

I'll do the next steps hopefully by the weekend.

Chances to get the PRs merged?

Hi,

found this project today and noticed that there are some interesting PRs pending and some other forks ongoing...

Hence the question if the PRs will be merged or if this fork is sort of abandoned?

TIA

/tklein

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.