datacollect/ops/myinflux.py
2019-08-19 16:45:37 +08:00

31 lines
825 B
Python

# -*- coding: utf-8 -*-
import logging
from influxdb import InfluxDBClient, exceptions
from config.config_real import My_influx
log = logging.getLogger(__name__)
class Myinflux:
def __init__(self):
self.influxdb = InfluxDBClient(**My_influx)
def write(self, body):
self._write(body)
def _write(self, body):
try:
self.influxdb.write_points(body)
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