GithubHelp home page GithubHelp logo

plusnet_monitoring's Introduction

plusnet_monitoring

This is a small python app which can pull DSL sync statistics from a Plusnet Hub 2 router and send the stats to InfluxDB. Its been tested when the router is in "bridge mode" so non-DSL sync stuff hasnt been verified. It doesn't work on the BT Smarthub 2 (slightly different firmware which doesnt expose the /nonAuth/wan_conn.xml endpoint)

Thanks to @hamishcoleman who did something similar in perl.

Running

You have a few options if you want to run this yourself...

  • clone the repo, install the python dependencies listed in the requirements.txt file and run monitor.py

  • run the docker image either periodically from cron, something like the below. Change podman for docker if you're still on old-school docker...

    podman run -e INFLUX_DB=modemstats -e ROUTER_IP=modem.lan -e INFLUX_HOST=10.43.238.72 ghcr.io/potchin/plusnet_monitoring:main

  • run the image in the background with the a REPORT_INTERVAL value. This will leave the container running..

    podman run -d -e REPORT_INTERVAL=60 -e ROUTER_IP=modem.lan -e INFLUX_HOST=10.43.238.72 ghcr.io/potchin/plusnet_monitoring:main

  • run as a cron job inside kubernetes (see example)

Configuration

The script is designed to run in a docker container so all config is read from the environment:

Variable Default Description
ROUTER_IP 192.168.1.254 hostname/IP of your router.
INFLUX_HOST None Hostname/IP of machine running influxdb
INFLUX_PORT 8086 port to connect to influxdb
INFLUX_USER root InfluxDB username
INFLUX_PASS root InfluxDB password
INFLUX_DB routerstats InfluxDB database
REPORT_INTERVAL 0 How often (in seconds) to grab stats, set to 0 to send stats once then exit (useful for cron)

Viewing

If you have InfluxDb then you've probably heard of Grafana. Use that...

grafana_stats.png

If you're down with the kids and run Home Assistant then you can also create sensors with the latest value from InfluxDB with something like...

sensor:
  - platform: influxdb
    host: influxdb
    port: 8086
    queries:
      - name: dsl_rate_down
        unit_of_measurement: "Mbit/sec"
        value_template: "{{ (int(value) /1024) | round(1) }}"
        where:  'time >= now() - 1h'
        measurement: rate_down
        field: "value"
        group_function: last
        database: routerstats
      - name: dsl_rate_up
        unit_of_measurement: "Mbit/sec"
        value_template: "{{ (int(value) /1024) | round(1) }}"
        where:  'time >= now() - 1h'
        measurement: rate_up
        field: "value"
        group_function: last
        database: routerstats
      - name: dsl_attainable_rate_down
        unit_of_measurement: "Mbit/sec"
        value_template: "{{ (int(value) /1024) | round(1) }}"
        where:  'time >= now() - 1h'
        measurement: attainable_rate_down
        field: "value"
        group_function: last
        database: routerstats
      - name: dsl_attainable_rate_up
        unit_of_measurement: "Mbit/sec"
        value_template: "{{ (int(value) /1024) | round(1)}}"
        where:  'time >= now() - 1h'
        measurement: attainable_rate_up
        field: "value"
        group_function: last
        database: routerstats

plusnet_monitoring's People

Contributors

potchin avatar

Stargazers

 avatar

Watchers

 avatar

plusnet_monitoring's Issues

Data Collection Broken from recent firmware update?

The container exits with the error log below.

Traceback (most recent call last):
File "/usr/src/app/./monitor.py", line 151, in
main()
File "/usr/src/app/./monitor.py", line 143, in main
output_data = get_data_from_router()
File "/usr/src/app/./monitor.py", line 48, in get_data_from_router
r.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: http://192.168.1.254/nonAuth/wan_conn.xml

Viewing this link in a browser doesn't work and does indeed get a 403 error.

A google suggests a change in the firmware and a user on the plusnet forum has worked around this in their script by making the request with a specific header.

The post mentions..

"Previously I was grabbing the page into my script with:

curl --silent http://192.168.1.254/nonAuth/wan_conn.xml -H "Accept: application/xml"

but that no longer works.

I have now found that if I include a referrer (I don't know why it needs that header, but it does), I can grab the XML file OK. So I've amended my script this, and now it's working again:

curl --silent http://192.168.1.254/nonAuth/wan_conn.xml -H "Referer: http://192.168.1.254/basic_-_status.htm" -H "Accept: application/xml"

Are you able to fix @potchin ?

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.