-
Notifications
You must be signed in to change notification settings - Fork 186
InfluxDB silently ignores data points written to it using influxdb-client-python #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @TomLXXVI, thanks for using our client. If you are use a batching then errors from InfluxDB are log into standard output. You could use synchronous way and see errors immediately. Could you share Regards |
DATETIME_STR_FMT = "%Y-%m-%d %H:%M:%S"
"""DateTime format used by the SolarEdge Monitoring Server API""" As you can see in the format string the smallest time unit is seconds ( At this moment I run InfluxDB v2.0 inside a Docker container on Windows 10. I have almost no experience with Docker. I just followed the installation instructions on InfluxDB's website and luckily the installation went just fine. In "Docker Desktop" there is possibility to view log files and one has access to a terminal in the docker container. In none of these two I could see any error message from InfluxDB when I ran the first code snippet mentioned in my previous message (that's why I mentioned "...silently ignores...". When I ran the second snippet, I got immediately back an error message on my terminal from where I started my program (shown in my previous message) and also in the log file in Docker Desktop:
I used and still use "synchronous mode". The whole class implementation (with the working code version) for writing to InfluxDB looks like this: class DBWriter:
"""
Class that reads a csv-file from disk and stores the data in the InfluxDB time series database.
"""
bucket: str = ""
token: str = ""
org: str = ""
netloc: str = ""
client: Optional[InfluxDBClient] = None
writer: Optional[WriteApi] = None
csv_path: str = ""
@classmethod
def init(cls, bucket: str, token: str, org: str, netloc: str, csv_path: str):
"""Initialize `DBWriter` to connect to the database."""
cls.bucket = bucket
cls.token = token
cls.org = org
cls.netloc = f"http://{netloc}"
cls.client = InfluxDBClient(
url=cls.netloc,
token=cls.token,
org=cls.org
)
cls.writer = cls.client.write_api(write_options=SYNCHRONOUS)
cls.csv_path = csv_path
@classmethod
def read_power_csv(cls, start_date: date, end_date: date) -> pd.DataFrame:
csv_file = f"power-details_{start_date}--{end_date}"
with open(os.path.join(cls.csv_path, f"{csv_file}.csv")) as file_path:
df = pd.read_csv(file_path, index_col=['time'])
return df
@classmethod
def write_power_to_db(cls, df: pd.DataFrame, measurement_name: str):
columns = [col for col in df.columns if col != 'unit']
for index, row in df.iterrows():
for col in columns:
point = Point(measurement_name)
point.tag('powerFlow', col)
point.field('power', row[col])
point.time(datetime.strptime(index, DATETIME_STR_FMT), WritePrecision.S)
print(point.to_line_protocol())
cls.writer.write(cls.bucket, cls.org, point, WritePrecision.S) In the |
@TomLXXVI thanks for detail info. The first snipped: @classmethod
def write_power_to_db(cls, df: pd.DataFrame, measurement_name: str):
columns = [col for col in df.columns if col != 'unit']
for index, row in df.iterrows():
for col in columns:
point = Point(measurement_name)
point.tag('powerFlow', col)
point.field('power', row[col])
point.time(datetime.strptime(index, DATETIME_STR_FMT), WritePrecision.S)
print(point.to_line_protocol())
cls.writer.write(cls.bucket, cls.org, point) should work, but I found a bug in writing Points with different precision than is specified in So your data was written but with incorrect precision. Thanks again for detail info. We will fix it ASAP.
Regards |
I am experiencing the same issue. Point object seems to be formatted correctly, but the timestamp is interpreted incorrectly. Turned on debug mode:
Created a point with seconds precision. If you look to the output, it is clear that the API is called with nanoseconds precision. Code snippet:
Output: test_6,method=test value=10.0 1591264869 send: b'POST /api/v2/write?org=...&bucket=test_bucket&precision=ns HTTP/1.1\r\nHost: 10.10.20.62:9999\r\nAccept-Encoding: identity\r\nContent-Length: 40\r\nContent-Encoding: identity\r\nContent-Type: text/plain\r\nAccept: application/json\r\nAuthorization: Token ...\r\nUser-Agent: influxdb-client-python/1.7.0\r\n\r\n' send: b'test_6,method=test value=10.0 1591264869' reply: 'HTTP/1.1 204 No Content\r\n' header: Date: Thu, 04 Jun 2020 08:01:15 GMT Tried to change the E.g.
|
Hi @Eslih, your are right. client = InfluxDBClient(url="http://10.10.20.62:9999", precision=WritePrecision.S, token=token, org=org, debug=True) is correct workaround. Thx Regards |
Hi All, The issue is fixed in 1.8.0 milestone. If you would like to use a dev version then install client via:
Regards |
I had an issue with this piece of code that I wrote myself:
In this method I get data out of a Pandas
DataFrame
object, put it in aPoint
object and then write this object to its destination in my InfluxDB bucket. This code runs without any error or warning. But: no data in the bucket!If I change the code to:
then I get an error back from InfluxDB:
I finally could solve the issue myself just by coincidence when I tried this:
The text was updated successfully, but these errors were encountered: