jshbrntt / speed-monitor-pi

Monitor your internet speed with a Raspberry Pi.
https://jshbrntt.dev/posts/how-covid-19-affected-my-internet-connection/
5 stars 3 forks source link

Measurement not inserted if packet loss is not zero #5

Open No0ne opened 2 days ago

No0ne commented 2 days ago

If I have non-zero packet loss the measurement is not inserted into influx:

speed_test,interface_external_ip=2a02:8388:e2c2::xxx,interface_internal_ip=2a02:8388:e2c2::xxx,interface_is_vpn=false,interface_mac_addr=DC:A6:32:xx:xx:xx,interface_name=wlan0,isp=Magenta\ Telekom,result_persisted=true,server_country=Austria,server_host=speedtest.ama-networx.net,server_id=16472,server_ip=2a0b:6c40:0:35:185:211:217:25,server_location=Vienna,server_name=AMA\ netwoRX\ GmbH,server_port=8080,type=result download_bandwidth=12343658u,download_bytes=125825364u,download_elapsed=10208u,download_latency_high=996.162,download_latency_iqm=412.966,download_latency_jitter=72.836,download_latency_low=15.437,packet_loss=0.49019607843137253,ping_high=14.272,ping_jitter=1.427,ping_latency=11.731,ping_low=10.782,result_id="xxx",result_url="xxx",upload_bandwidth=6433045u,upload_bytes=57321348u,upload_elapsed=9314u,upload_latency_high=292.045,upload_latency_iqm=28.647,upload_latency_jitter=4.397,upload_latency_low=8.596 1728724908
Traceback (most recent call last):
  File "/usr/local/sbin/speedtest.py", line 96, in <module>
    write_api.write(
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/client/write_api.py", line 378, in write
    results = list(map(write_payload, payloads.items()))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/client/write_api.py", line 376, in write_payload
    return self._post_write(_async_req, bucket, org, final_string, payload[0])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/client/write_api.py", line 509, in _post_write
    return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/service/write_service.py", line 60, in post_write
    (data) = self.post_write_with_http_info(org, bucket, body, **kwargs)  # noqa: E501
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/service/write_service.py", line 90, in post_write_with_http_info
    return self.api_client.call_api(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/_sync/api_client.py", line 343, in call_api
    return self.__call_api(resource_path, method,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/_sync/api_client.py", line 173, in __call_api
    response_data = self.request(
                    ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/_sync/api_client.py", line 388, in request
    return self.rest_client.POST(url,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/_sync/rest.py", line 311, in POST
    return self.request("POST", url,
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/influxdb_client/_sync/rest.py", line 261, in request
    raise ApiException(http_resp=r)
influxdb_client.rest.ApiException: (422)
Reason: Unprocessable Entity
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.4.0', 'X-Platform-Error-Code': 'unprocessable entity', 'Date': 'Sat, 12 Oct 2024 09:21:49 GMT', 'Content-Length': '230'})
HTTP response body: {"code":"unprocessable entity","message":"failure writing points to database: partial write: field type conflict: input field \"packet_loss\" on measurement \"speed_test\" is type float, already exists as type unsigned dropped=1"}
No0ne commented 2 days ago

Fixed it by adding this after line 73 in /usr/local/sbin/speedtest.py:

    if key == 'packet_loss':
        fields[key] = '{}'.format(value)