Skip to content

Commit 28925ab

Browse files
committed
Merge pull request influxdata#121 from areski/fix-tutorial-serieshelper
Fix tutorial serieshelper
2 parents cccea83 + cdbf1bf commit 28925ab

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

examples/tutorial_serieshelper.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +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.
10-
series_name = 'events.stats.{server_name}'
26+
client = myclient
1127
# The series name must be a string. Add dependent fields/tags in curly brackets.
12-
fields = ['some_stat']
28+
series_name = 'events.stats.{server_name}'
1329
# Defines all the fields in this time series.
14-
tags = ['server_name']
30+
fields = ['some_stat', 'other_stat']
1531
# Defines all the tags for the series.
16-
bulk_size = 5
32+
tags = ['server_name']
1733
# 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+
1838

1939
# The following will create *five* (immutable) data points.
2040
# Since bulk_size is set to 5, upon the fifth construction call, *all* data
2141
# points will be written on the wire via MySeriesHelper.Meta.client.
22-
MySeriesHelper(server_name='us.east-1', some_stat=159)
23-
MySeriesHelper(server_name='us.east-1', some_stat=158)
24-
MySeriesHelper(server_name='us.east-1', some_stat=157)
25-
MySeriesHelper(server_name='us.east-1', some_stat=156)
26-
MySeriesHelper(server_name='us.east-1', some_stat=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)
2747

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

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