Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit bde2096

Browse files
Merge pull request #1 from influxdb/master
Updating master
2 parents 1a62701 + 6dfc326 commit bde2096

33 files changed

+4079
-1162
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
install:
1313
- sudo pip install tox
1414
- sudo pip install coveralls
15+
- ./build_influxdb_server.sh
1516
script:
1617
- travis_wait tox -e $TOX_ENV
1718
after_success:

README.rst

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ InfluxDB-Python is a client for interacting with InfluxDB_.
66
:target: https://travis-ci.org/influxdb/influxdb-python
77

88
.. image:: https://readthedocs.org/projects/influxdb-python/badge/?version=latest&style
9-
:target: https://readthedocs.org/projects/influxdb-python/?badge=latest
9+
:target: http://influxdb-python.readthedocs.org/
1010
:alt: Documentation Status
1111

1212
.. image:: https://img.shields.io/coveralls/influxdb/influxdb-python.svg
@@ -36,14 +36,16 @@ InfluxDB is an open-source distributed time series database, find more about Inf
3636

3737
.. _installation:
3838

39-
InfluxDB v0.9.0
40-
===============
39+
InfluxDB > v0.9 support
40+
=======================
4141

42-
InfluxDB v0.9.0 brings many changes to the influxDB api. v0.9.0 users may use the ``0.9.0_support`` branch. Keep in mind that this is a development branch and may break. When v0.9.0 is released, we will merge the ``0.9.0_support`` branch to master and push it to pypi.
42+
The 1.0.0 version of this library now supports InfluxDB 0.9. Please note that InfluxDB 0.9 is still pre-release software. For stability, you should use the ``influxdb.influxdb08`` module in conjunction with InfluxDB 0.8.
4343

44-
You may install it from pip with the following command::
4544

46-
$ pip install https://github.com/influxdb/influxdb-python/archive/0.9.0_support.zip
45+
InfluxDB v0.8.X users
46+
=====================
47+
48+
Influxdb >=0.9.0 brings many breaking changes to the API. InfluxDB 0.8.X users may use the legacy client by using ``from influxdb.influxdb08 import InfluxDBClient`` instead.
4749

4850
Installation
4951
============
@@ -100,14 +102,19 @@ Here's a basic example (for more see the examples directory)::
100102

101103
>>> from influxdb import InfluxDBClient
102104

103-
>>> json_body = [{
104-
"points": [
105-
["1", 1, 1.0],
106-
["2", 2, 2.0]
107-
],
108-
"name": "foo",
109-
"columns": ["column_one", "column_two", "column_three"]
110-
}]
105+
>>> json_body = [
106+
{
107+
"name": "cpu_load_short",
108+
"tags": {
109+
"host": "server01",
110+
"region": "us-west"
111+
},
112+
"timestamp": "2009-11-10T23:00:00Z",
113+
"fields": {
114+
"value": 0.64
115+
}
116+
}
117+
]
111118

112119
>>> client = InfluxDBClient('localhost', 8086, 'root', 'root', 'example')
113120

@@ -149,6 +156,12 @@ problems or submit contributions.
149156
.. _Issues: https://github.com/influxdb/influxdb-python/issues
150157

151158

159+
TODO
160+
====
161+
162+
The TODO/Roadmap can be found in Github bug tracker: https://github.com/influxdb/influxdb-python/issues/109
163+
164+
152165
Source code
153166
===========
154167

build_influxdb_server.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# build and install,
5+
# the latest influxdb server master
6+
#
7+
8+
set -e
9+
10+
tmpdir=$(mktemp -d)
11+
12+
echo "Using tempdir $tmpdir .."
13+
14+
cd "$tmpdir"
15+
16+
# rpm for package.sh (below) which will also build an .rpm
17+
sudo apt-get install ruby ruby-dev build-essential rpm
18+
19+
echo $PATH
20+
echo $(which gem)
21+
echo $(which ruby)
22+
23+
gem=$(which gem)
24+
25+
sudo $gem install fpm
26+
27+
mkdir -p go/src/github.com/influxdb
28+
cd go/src/github.com/influxdb
29+
30+
git clone --depth 5 https://github.com/influxdb/influxdb
31+
cd influxdb
32+
33+
version=0.0.0-$(git describe --always | sed 's/^v//')
34+
echo "describe: $version"
35+
36+
export GOPATH="$tmpdir/go"
37+
{ echo y ; yes no ; } | ./package.sh "$version"
38+
39+
deb=$(ls *.deb)
40+
sudo dpkg -i "$deb"

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ mock
44
pandas
55
Sphinx==1.2.3
66
sphinx_rtd_theme
7+
wheel
8+
twine

examples/tutorial.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,28 @@ def main(host='localhost', port=8086):
99
dbname = 'example'
1010
dbuser = 'smly'
1111
dbuser_password = 'my_secret_password'
12-
query = 'select column_one from foo;'
13-
json_body = [{
14-
"points": [
15-
["1", 1, 1.0],
16-
["2", 2, 2.0]
17-
],
18-
"name": "foo",
19-
"columns": ["column_one", "column_two", "column_three"]
20-
}]
12+
query = 'select value from cpu_load_short;'
13+
json_body = [
14+
{
15+
"name": "cpu_load_short",
16+
"tags": {
17+
"host": "server01",
18+
"region": "us-west"
19+
},
20+
"timestamp": "2009-11-10T23:00:00Z",
21+
"fields": {
22+
"value": 0.64
23+
}
24+
}
25+
]
2126

2227
client = InfluxDBClient(host, port, user, password, dbname)
2328

2429
print("Create database: " + dbname)
2530
client.create_database(dbname)
2631

27-
dbusers = client.get_database_users()
28-
print("Get list of database users: {0}".format(dbusers))
29-
30-
print("Add database user: " + dbuser)
31-
client.add_database_user(dbuser, dbuser_password)
32-
33-
print("Make user a database admin")
34-
client.set_database_admin(dbuser)
35-
36-
print("Remove admin privilege from user")
37-
client.unset_database_admin(dbuser)
38-
39-
dbusers = client.get_database_users()
40-
print("Get list of database users again: {0}".format(dbusers))
32+
print("Create a retention policy")
33+
client.create_retention_policy('awesome_policy', '3d', 3, default=True)
4134

4235
print("Switch user: " + dbuser)
4336
client.switch_user(dbuser, dbuser_password)
@@ -53,8 +46,8 @@ def main(host='localhost', port=8086):
5346
print("Switch user: " + user)
5447
client.switch_user(user, password)
5548

56-
print("Delete database: " + dbname)
57-
client.delete_database(dbname)
49+
print("Drop database: " + dbname)
50+
client.drop_database(dbname)
5851

5952

6053
def parse_args():

examples/tutorial_pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main(host='localhost', port=8086):
2020
client.create_database(dbname)
2121

2222
print("Write DataFrame")
23-
client.write_points({'demo':df})
23+
client.write_points({'demo': df})
2424

2525
print("Read DataFrame")
2626
client.query("select * from demo")

examples/tutorial_serieshelper.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
1+
"""
2+
Tutorial/Example how to use the class helper `SeriesHelper`
3+
"""
4+
15
from influxdb import InfluxDBClient
26
from influxdb import SeriesHelper
37

8+
# InfluxDB connections settings
9+
host = 'localhost'
10+
port = 8086
11+
user = 'root'
12+
password = 'root'
13+
dbname = 'mydb'
14+
15+
myclient = InfluxDBClient(host, port, user, password, dbname)
16+
17+
# Uncomment the following code if the database is not yet created
18+
# myclient.create_database(dbname)
19+
# myclient.create_retention_policy('awesome_policy', '3d', 3, default=True)
20+
421

522
class MySeriesHelper(SeriesHelper):
23+
# Meta class stores time series helper configuration.
624
class Meta:
7-
# Meta class stores time series helper configuration.
8-
client = InfluxDBClient()
925
# The client should be an instance of InfluxDBClient.
26+
client = myclient
27+
# The series name must be a string. Add dependent fields/tags in curly brackets.
1028
series_name = 'events.stats.{server_name}'
11-
# The series name must be a string. Add dependent field names in curly brackets.
12-
fields = ['time', 'server_name']
1329
# Defines all the fields in this time series.
14-
bulk_size = 5
30+
fields = ['some_stat', 'other_stat']
31+
# Defines all the tags for the series.
32+
tags = ['server_name']
1533
# Defines the number of data points to store prior to writing on the wire.
34+
bulk_size = 5
35+
# autocommit must be set to True when using bulk_size
36+
autocommit = True
37+
1638

1739
# The following will create *five* (immutable) data points.
1840
# Since bulk_size is set to 5, upon the fifth construction call, *all* data
1941
# points will be written on the wire via MySeriesHelper.Meta.client.
20-
MySeriesHelper(server_name='us.east-1', time=159)
21-
MySeriesHelper(server_name='us.east-1', time=158)
22-
MySeriesHelper(server_name='us.east-1', time=157)
23-
MySeriesHelper(server_name='us.east-1', time=156)
24-
MySeriesHelper(server_name='us.east-1', time=155)
42+
MySeriesHelper(server_name='us.east-1', some_stat=159, other_stat=10)
43+
MySeriesHelper(server_name='us.east-1', some_stat=158, other_stat=20)
44+
MySeriesHelper(server_name='us.east-1', some_stat=157, other_stat=30)
45+
MySeriesHelper(server_name='us.east-1', some_stat=156, other_stat=40)
46+
MySeriesHelper(server_name='us.east-1', some_stat=155, other_stat=50)
2547

2648
# To manually submit data points which are not yet written, call commit:
2749
MySeriesHelper.commit()

examples/tutorial_server_data.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import argparse
22

33
from influxdb import InfluxDBClient
4+
from influxdb.client import InfluxDBClientError
45
import datetime
56
import random
7+
import time
68

79

810
USER = 'root'
@@ -17,34 +19,53 @@ def main(host='localhost', port=8086, nb_day=15):
1719
total_minutes = 1440 * nb_day
1820
total_records = int(total_minutes / timeinterval_min)
1921
now = datetime.datetime.today()
20-
cpu_series = [{
21-
'name': "server_data.cpu_idle",
22-
'columns': ["time", "value", "hostName"],
23-
'points': []
24-
}]
22+
metric = "server_data.cpu_idle"
23+
series = []
2524

2625
for i in range(0, total_records):
2726
past_date = now - datetime.timedelta(minutes=i * timeinterval_min)
2827
value = random.randint(0, 200)
2928
hostName = "server-%d" % random.randint(1, 5)
30-
pointValues = [int(past_date.strftime('%s')), value, hostName]
31-
cpu_series[0]['points'].append(pointValues)
29+
# pointValues = [int(past_date.strftime('%s')), value, hostName]
30+
pointValues = {
31+
"timestamp": int(past_date.strftime('%s')),
32+
"name": metric,
33+
'fields': {
34+
'value': value,
35+
},
36+
'tags': {
37+
"hostName": hostName,
38+
},
39+
}
40+
series.append(pointValues)
41+
print series
3242

3343
client = InfluxDBClient(host, port, USER, PASSWORD, DBNAME)
3444

3545
print("Create database: " + DBNAME)
36-
client.create_database(DBNAME)
46+
try:
47+
client.create_database(DBNAME)
48+
except InfluxDBClientError:
49+
# Drop and create
50+
client.drop_database(DBNAME)
51+
client.create_database(DBNAME)
52+
53+
print("Create a retention policy")
54+
retention_policy = 'awesome_policy'
55+
client.create_retention_policy(retention_policy, '3d', 3, default=True)
3756

3857
print("Write points #: {0}".format(total_records))
39-
client.write_points(cpu_series)
58+
client.write_points(series, retention_policy=retention_policy)
59+
60+
time.sleep(2)
4061

41-
query = 'SELECT MEAN(value) FROM server_data.cpu_idle GROUP BY time(30m) WHERE time > now() - 1d;'
42-
print("Queying data: " + query)
43-
result = client.query(query)
62+
query = "SELECT MEAN(value) FROM %s WHERE time > now() - 10d GROUP BY time(500m)" % (metric)
63+
result = client.query(query, database=DBNAME, raw=False)
64+
print (result)
4465
print("Result: {0}".format(result))
4566

46-
print("Delete database: " + DBNAME)
47-
client.delete_database(DBNAME)
67+
print("Drop database: " + DBNAME)
68+
client.drop_database(DBNAME)
4869

4970

5071
def parse_args():

influxdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
]
1212

1313

14-
__version__ = '0.3.0'
14+
__version__ = '1.0.2'

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