33 lines
908 B
Python
33 lines
908 B
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
from influxdb import InfluxDBClient, exceptions
|
|
from config.config_real import My_influx
|
|
|
|
log = logging.getLogger(__name__)
|
|
import pdb
|
|
|
|
class Myinflux:
|
|
def __init__(self):
|
|
self.influxdb = InfluxDBClient(**My_influx)
|
|
|
|
def write(self, body):
|
|
self._write(body)
|
|
|
|
def _write(self, body):
|
|
try:
|
|
pdb.set_trace()
|
|
self.influxdb.write_points(body)
|
|
print(f"write {body} 2 influx!")
|
|
return True
|
|
except exceptions.InfluxDBClientError:
|
|
log.error(f"write {body} to influx failed!", exc_info=True)
|
|
return False
|
|
|
|
def _read(self, query):
|
|
try:
|
|
result = self.client.query(query)
|
|
return result
|
|
except exceptions.InfluxDBClientError:
|
|
log.error(f"write {query} to influx failed!", exc_info=True)
|
|
return False
|