This repository was archived by the owner on Oct 29, 2024. It is now read-only.
This repository was archived by the owner on Oct 29, 2024. It is now read-only.
Example for sending information via udp needed in documentation #646
Closed
Description
It would be really helpful to perhaps setup a udp
example in the repository. There is just mentions of it here and there in the API documents and they are not clear for usage.
-
Apparently the docs for
send_packet()
should mention alist
instead ofsequence
which is very confusing. -
if the protocol is
json
it mentions the value should be passed as adict
. For starters, I just copied the examplejson_body
in the code and this is the Error I get:
Traceback (most recent call last):
File "gpsinflux-udp.py", line 25, in <module>
main()
File "gpsinflux-udp.py", line 21, in main
client.send_packet(json_body)
File "/usr/local/lib/python3.4/dist-packages/influxdb/client.py", line 877, in send_packet
data = make_lines(packet).encode('utf-8')
File "/usr/local/lib/python3.4/dist-packages/influxdb/line_protocol.py", line 119, in make_lines
static_tags = data.get('tags')
AttributeError: 'list' object has no attribute 'get'
- If I only pass the
json_body
as a dict I get:
Traceback (most recent call last):
File "gpsinflux-udp.py", line 23, in <module>
main()
File "gpsinflux-udp.py", line 19, in main
client.send_packet(json_body)
File "/usr/local/lib/python3.4/dist-packages/influxdb/client.py", line 877, in send_packet
data = make_lines(packet).encode('utf-8')
File "/usr/local/lib/python3.4/dist-packages/influxdb/line_protocol.py", line 120, in make_lines
for point in data['points']:
KeyError: 'points'
Code
case 2
from influxdb import InfluxDBClient
def main():
client = InfluxDBClient('localhost', 8089, use_udp=True, udp_port=8089,
database='example')
json_body = [{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}]
client.send_packet(json_body)
if __name__ == '__main__':
main()
case 3
from influxdb import InfluxDBClient
def main():
client = InfluxDBClient('localhost', 8089, use_udp=True, udp_port=8089,
database='example')
json_body = {
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
client.send_packet(json_body)
if __name__ == '__main__':
main()
Won't harm to add a simple udp example for the repo
Metadata
Metadata
Assignees
Labels
No labels