Skip to content

Commit f08dfdb

Browse files
committed
fix: add an example to try simulate loosing data
1 parent d6ba893 commit f08dfdb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

examples/loosing_data.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
from datetime import datetime
3+
from influxdb_client import InfluxDBClient, WriteOptions, Point
4+
5+
token = "..."
6+
org = "..."
7+
bucket = "..."
8+
measurement = "Pressure"
9+
10+
client = InfluxDBClient(url="https://us-west-2-1.aws.cloud2.influxdata.com", token=token, debug=True)
11+
write_api = client.write_api(
12+
write_options=WriteOptions(batch_size=8, flush_interval=8, jitter_interval=0, retry_interval=1000))
13+
for i in range(50):
14+
valOne = float(i)
15+
valTwo = float(i) + 0.5
16+
pointOne = Point(measurement).tag("sensor", "sensor1").field("PSI", valOne).time(time=datetime.utcnow())
17+
pointTwo = Point(measurement).tag("sensor", "sensor2").field("PSI", valTwo).time(time=datetime.utcnow())
18+
19+
write_api.write(bucket, org, [pointOne, pointTwo])
20+
print("PSI Readings: (%f, %f)" % (valOne, valTwo))
21+
time.sleep(0.5)
22+
23+
write_api.__del__()
24+
25+
query = f'from(bucket: "{bucket}") |> range(start: 0) |> filter(fn: (r) => r["_measurement"] == "{measurement}") |> count()'
26+
tables = client.query_api().query(query, org)
27+
for table in tables:
28+
for record in table.records:
29+
print(f'{record.get_measurement()}: {record.get_field()} count: {record.get_value()}')
30+
31+
client.__del__()
32+
print("end")
33+
34+

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