From 9e09b6488185d50f66f494faaa5e2012b65ce5a5 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Sat, 9 Jan 2021 13:22:22 -0800 Subject: [PATCH 1/8] Update Dockerfile Name & run in daemon mode --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 58ae64a..4439c34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,6 @@ python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. -- python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi_config.proto && \ echo "$CRON_ENTRY" | crontab - && cron -f -# docker run -e INFLUXDB_HOST=192.168.1.34 -e INFLUXDB_PORT=8086 -e INFLUXDB_DB=starlink +# docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST=192.168.1.34 -e INFLUXDB_PORT=8086 -e INFLUXDB_DB=starlink # -e "CRON_ENTRY=* * * * * /usr/local/bin/python3 /app/dishStatusInflux_cron.py > /proc/1/fd/1 2>/proc/1/fd/2" # --net='br0' --ip='192.168.1.39' neurocis/starlink-grpc-tools From 27ce46cb3cff7e74424f6e96a0849edb3b5b2b52 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Sat, 9 Jan 2021 13:22:55 -0800 Subject: [PATCH 2/8] Update README.md Name & run docker in daemon mode. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d79491..30305f1 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ The Starlink router also exposes a gRPC service, on ports 9000 (HTTP/2.0) and 90 `dishStatusInflux_cron.py` is a docker-cron friendly script which will post status to an InfluxDB as specified by evironment variables passed to the container. Initialization of the container can be performed with the following command: ``` -docker run -e INFLUXDB_HOST={InfluxDB Hostname} +docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST={InfluxDB Hostname} -e INFLUXDB_PORT={Port, 8086 usually} -e INFLUXDB_USER={Optional, InfluxDB Username} -e INFLUXDB_PWD={Optional, InfluxDB Password} From ee1d19ce35132140bd14c974bacb270b4311ee5e Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Sun, 10 Jan 2021 23:40:02 -0800 Subject: [PATCH 3/8] Delete dishStatusInflux_cron.py --- dishStatusInflux_cron.py | 93 ---------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 dishStatusInflux_cron.py diff --git a/dishStatusInflux_cron.py b/dishStatusInflux_cron.py deleted file mode 100644 index a4e7503..0000000 --- a/dishStatusInflux_cron.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/python3 -###################################################################### -# -# Write get_status info to an InfluxDB database. -# -# This script will poll current status and write it to -# the specified InfluxDB database. -# -###################################################################### -import os -import grpc -import spacex.api.device.device_pb2 -import spacex.api.device.device_pb2_grpc - -from influxdb import InfluxDBClient -from influxdb import SeriesHelper - -influxdb_host = os.environ.get("INFLUXDB_HOST") -influxdb_port = os.environ.get("INFLUXDB_PORT") -influxdb_user = os.environ.get("INFLUXDB_USER") -influxdb_pwd = os.environ.get("INFLUXDB_PWD") -influxdb_db = os.environ.get("INFLUXDB_DB") - -class DeviceStatusSeries(SeriesHelper): - class Meta: - series_name = "spacex.starlink.user_terminal.status" - fields = [ - "hardware_version", - "software_version", - "state", - "alert_motors_stuck", - "alert_thermal_throttle", - "alert_thermal_shutdown", - "alert_unexpected_location", - "snr", - "seconds_to_first_nonempty_slot", - "pop_ping_drop_rate", - "downlink_throughput_bps", - "uplink_throughput_bps", - "pop_ping_latency_ms", - "currently_obstructed", - "fraction_obstructed"] - tags = ["id"] - -influx_client = InfluxDBClient(host=influxdb_host, port=influxdb_port, username=influxdb_user, password=influxdb_pwd, database=influxdb_db, ssl=False, retries=1, timeout=15) - -dish_channel = None -last_id = None -last_failed = False - -while True: - try: - if dish_channel is None: - dish_channel = grpc.insecure_channel("192.168.100.1:9200") - stub = spacex.api.device.device_pb2_grpc.DeviceStub(dish_channel) - response = stub.Handle(spacex.api.device.device_pb2.Request(get_status={})) - status = response.dish_get_status - DeviceStatusSeries( - id=status.device_info.id, - hardware_version=status.device_info.hardware_version, - software_version=status.device_info.software_version, - state=spacex.api.device.dish_pb2.DishState.Name(status.state), - alert_motors_stuck=status.alerts.motors_stuck, - alert_thermal_throttle=status.alerts.thermal_throttle, - alert_thermal_shutdown=status.alerts.thermal_shutdown, - alert_unexpected_location=status.alerts.unexpected_location, - snr=status.snr, - seconds_to_first_nonempty_slot=status.seconds_to_first_nonempty_slot, - pop_ping_drop_rate=status.pop_ping_drop_rate, - downlink_throughput_bps=status.downlink_throughput_bps, - uplink_throughput_bps=status.uplink_throughput_bps, - pop_ping_latency_ms=status.pop_ping_latency_ms, - currently_obstructed=status.obstruction_stats.currently_obstructed, - fraction_obstructed=status.obstruction_stats.fraction_obstructed) - last_id = status.device_info.id - last_failed = False - except grpc.RpcError: - if dish_channel is not None: - dish_channel.close() - dish_channel = None - if last_failed: - if last_id is not None: - DeviceStatusSeries(id=last_id, state="DISH_UNREACHABLE") - else: - # Retry once, because the connection may have been lost while - # we were sleeping - last_failed = True - continue - try: - DeviceStatusSeries.commit(influx_client) - except Exception as e: - print("Failed to write: " + str(e)) - break From 21e9c010e2475e4047d5fe38cf31eb6689ee8f1f Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Sun, 10 Jan 2021 23:41:05 -0800 Subject: [PATCH 4/8] Create entrypoint.sh --- entrypoint.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..e2d91ef --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +printenv >> /etc/environment +ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +grpcurl -plaintext -protoset-out dish.protoset 192.168.100.1:9200 describe SpaceX.API.Device.Device +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/device.proto +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/common/status/status.proto +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/command.proto +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/common.proto +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/dish.proto +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi.proto +python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi_config.proto +/usr/local/bin/python3 $1 From 7fb595bbda87ba7d8dcc6c4f10628e56629779b5 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Sun, 10 Jan 2021 23:41:44 -0800 Subject: [PATCH 5/8] Update Dockerfile --- Dockerfile | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4439c34..b909990 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,6 @@ FROM python:3.9 LABEL maintainer="neurocis " RUN true && \ -# Install package prerequisites -apt-get update && \ -apt-get install -qy cron && \ -apt-get clean && \ -rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ \ # Install GRPCurl wget https://github.com/fullstorydev/grpcurl/releases/download/v1.8.0/grpcurl_1.8.0_linux_x86_64.tar.gz && \ @@ -23,20 +18,8 @@ ADD . /app WORKDIR /app # run crond as main process of container -CMD true && \ -printenv >> /etc/environment && \ -ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \ -#ntpd -p pool.ntp.org && \ -grpcurl -plaintext -protoset-out dish.protoset 192.168.100.1:9200 describe SpaceX.API.Device.Device && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/device.proto && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/common/status/status.proto && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/command.proto && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/common.proto && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/dish.proto && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi.proto && \ -python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi_config.proto && \ -echo "$CRON_ENTRY" | crontab - && cron -f +ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"] +CMD ["dishStatusInflux.py"] -# docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST=192.168.1.34 -e INFLUXDB_PORT=8086 -e INFLUXDB_DB=starlink -# -e "CRON_ENTRY=* * * * * /usr/local/bin/python3 /app/dishStatusInflux_cron.py > /proc/1/fd/1 2>/proc/1/fd/2" -# --net='br0' --ip='192.168.1.39' neurocis/starlink-grpc-tools +# docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST=192.168.1.34 -e INFLUXDB_PORT=8086 -e INFLUXDB_DB=starlink +# --net='br0' --ip='192.168.1.39' neurocis/starlink-grpc-tools dishStatusInflux.py From d0fd5a0a2b53837e4ed0bb4b838ab20316963081 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Sun, 10 Jan 2021 23:57:06 -0800 Subject: [PATCH 6/8] Update entrypoint.sh Change to passthrough all args. --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e2d91ef..5cce7fe 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,4 +10,4 @@ python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. -- python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/dish.proto python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi.proto python3 -m grpc_tools.protoc --descriptor_set_in=dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi_config.proto -/usr/local/bin/python3 $1 +/usr/local/bin/python3 $@ From d21b196f7898a3d6ca91dbacefa38790add67afd Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Mon, 11 Jan 2021 00:00:49 -0800 Subject: [PATCH 7/8] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d1cdcae..2d2a3bc 100644 --- a/README.md +++ b/README.md @@ -72,15 +72,15 @@ The Starlink router also exposes a gRPC service, on ports 9000 (HTTP/2.0) and 90 ## Docker for InfluxDB ( & MQTT under development ) -`dishStatusInflux_cron.py` is a docker-cron friendly script which will post status to an InfluxDB as specified by evironment variables passed to the container. Initialization of the container can be performed with the following command: +Initialization of the container can be performed with the following command: ``` -docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST={InfluxDB Hostname} - -e INFLUXDB_PORT={Port, 8086 usually} - -e INFLUXDB_USER={Optional, InfluxDB Username} - -e INFLUXDB_PWD={Optional, InfluxDB Password} - -e INFLUXDB_DB={Pre-created DB name, starlinkstats works well} - -e "CRON_ENTRY=* * * * * /usr/local/bin/python3 /app/dishStatusInflux_cron.py > /proc/1/fd/1 2>/proc/1/fd/2" neurocis/starlink-grpc-tools +docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST={InfluxDB Hostname} \ + -e INFLUXDB_PORT={Port, 8086 usually} \ + -e INFLUXDB_USER={Optional, InfluxDB Username} \ + -e INFLUXDB_PWD={Optional, InfluxDB Password} \ + -e INFLUXDB_DB={Pre-created DB name, starlinkstats works well} \ + neurocis/starlink-grpc-tools dishStatusInflux.py -v ``` -Adjust the `CRON_ENTRY` to your desired polling schedule. I (neurocis) will push a Grafana dashboard in the near future, or please create and share your own. +`dishStatusInflux.py -v` is optional and will run same but not -verbose, or you can replace it with one the other scripts if you wish to run that instead. I (neurocis) will push a Grafana dashboard in the near future, or please create and share your own. From eecc65a5ba3538b3449bde804c90b4c25cf9b5eb Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Mon, 11 Jan 2021 00:01:50 -0800 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d2a3bc..6832cb4 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,4 @@ docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST={InfluxDB Hostname} neurocis/starlink-grpc-tools dishStatusInflux.py -v ``` -`dishStatusInflux.py -v` is optional and will run same but not -verbose, or you can replace it with one the other scripts if you wish to run that instead. I (neurocis) will push a Grafana dashboard in the near future, or please create and share your own. +`dishStatusInflux.py -v` is optional and will run same but not -verbose, or you can replace it with one of the other scripts if you wish to run that instead. I (neurocis) will push a Grafana dashboard in the near future, or please create and share your own.