This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
Add Example for sending information to DB via UDP #648
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e133e3f
Add Example for sending information to DB via UDP
shantanoo-desai dee3b61
Merge remote-tracking branch 'upstream/master'
shantanoo-desai 8303640
Add Documentation for UDP Example
shantanoo-desai 0af9b5d
Adapt example to proper pydocstyle
shantanoo-desai c7425c0
Improve `tutorial_udp.py` example
shantanoo-desai 56bf22e
Merge branch 'master' of https://github.com/shantanoo-desai/influxdb-…
shantanoo-desai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Example for sending batch information to InfluxDB via UDP.""" | ||
|
||
""" | ||
INFO: In order to use UDP, one should enable the UDP service from the | ||
`influxdb.conf` under section | ||
[[udp]] | ||
enabled = true | ||
bind-address = ":8089" # port number for sending data via UDP | ||
shantanoo-desai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
database = "udp1" # name of database to be stored | ||
[[udp]] | ||
enabled = true | ||
bind-address = ":8090" | ||
database = "udp2" | ||
""" | ||
|
||
|
||
import argparse | ||
|
||
from influxdb import InfluxDBClient | ||
|
||
|
||
def main(uport): | ||
"""Instantiate connection to the InfluxDB.""" | ||
# NOTE: structure of the UDP packet is different than that of information | ||
# sent via HTTP | ||
json_body = { | ||
"tags": { | ||
"host": "server01", | ||
"region": "us-west" | ||
}, | ||
"time": "2009-11-10T23:00:00Z", | ||
"points": [{ | ||
"measurement": "cpu_load_short", | ||
"fields": { | ||
"value": 0.64 | ||
} | ||
}, | ||
{ | ||
"measurement": "cpu_load_short", | ||
"fields": { | ||
"value": 0.67 | ||
} | ||
}] | ||
} | ||
|
||
# make `use_udp` True and add `udp_port` number from `influxdb.conf` file | ||
# no need to mention the database name since it is already configured | ||
client = InfluxDBClient(use_udp=True, udp_port=uport) | ||
|
||
# Instead of `write_points` use `send_packet` | ||
client.send_packet(json_body) | ||
|
||
|
||
def parse_args(): | ||
"""Parse the args.""" | ||
parser = argparse.ArgumentParser( | ||
description='example code to play with InfluxDB along with UDP Port') | ||
parser.add_argument('--uport', type=int, required=True, | ||
help=' UDP port of InfluxDB') | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = parse_args() | ||
main(uport=args.uport) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.