Skip to content

Commit 9d2a290

Browse files
author
aviau
committed
Added UDP support
1 parent 5767c53 commit 9d2a290

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

influxdb/client.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
python client for influxdb
44
"""
55
import json
6-
6+
import socket
77
import requests
88
session = requests.Session()
99

@@ -13,8 +13,18 @@ class InfluxDBClient(object):
1313
InfluxDB Client
1414
"""
1515

16-
def __init__(self, host='localhost', port=8086, username='root',
17-
password='root', database=None, ssl=False, verify_ssl=False):
16+
def __init__(
17+
self,
18+
host='localhost',
19+
port=8086,
20+
username='root',
21+
password='root',
22+
database=None,
23+
ssl=False,
24+
verify_ssl=False,
25+
use_udp=False,
26+
udp_port=4444):
27+
1828
"""
1929
Initialize client
2030
"""
@@ -26,6 +36,11 @@ def __init__(self, host='localhost', port=8086, username='root',
2636

2737
self._verify_ssl = verify_ssl
2838

39+
self.use_udp = use_udp
40+
self.udp_port = udp_port
41+
if use_udp:
42+
self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
43+
2944
self._scheme = "http"
3045

3146
if ssl is True:
@@ -159,13 +174,16 @@ def write_points_with_precision(self, data, time_precision='s'):
159174
'time_precision': time_precision
160175
}
161176

162-
self.request(
163-
url=url,
164-
method='POST',
165-
params=params,
166-
data=data,
167-
status_code=200
168-
)
177+
if self.use_udp:
178+
self.send_packet(data)
179+
else:
180+
self.request(
181+
url=url,
182+
method='POST',
183+
params=params,
184+
data=data,
185+
status_code=200
186+
)
169187

170188
return True
171189

@@ -604,3 +622,8 @@ def update_permission(self, username, json_body):
604622
See also: src/api/http/api.go:l57
605623
"""
606624
raise NotImplementedError()
625+
626+
def send_packet(self, packet):
627+
data = json.dumps(packet)
628+
byte = data.encode('utf-8')
629+
self.udp_socket.sendto(byte, (self._host, self.udp_port))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy