mirror of
https://github.com/kemko/keenetic-grafana-monitoring.git
synced 2026-01-01 15:45:43 +03:00
Using admin api, instead open port (#1)
* influxdb2 integration * using python alpine base image * add authorization, refactoring config * logging instead print, keenetic api exception handling when try to collect metrics, a little pep8
This commit is contained in:
committed by
GitHub
parent
7661b5819d
commit
16a37bf0d9
@@ -1,22 +1,27 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from influxdb import InfluxDBClient
|
||||
|
||||
class InfuxWritter(object):
|
||||
|
||||
class InfuxWriter(object):
|
||||
|
||||
def __init__(self, configuration):
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
self._configuration = configuration['influxdb']
|
||||
self._client = InfluxDBClient(self._configuration['host'], self._configuration['port'], self._configuration['username'], self._configuration['password'], self._configuration['db'])
|
||||
self._configuration = configuration
|
||||
self._client = InfluxDBClient(self._configuration['host'], self._configuration['port'],
|
||||
self._configuration['username'], self._configuration['password'],
|
||||
self._configuration['db'])
|
||||
self.init_database()
|
||||
|
||||
def init_database(self):
|
||||
print("Connecting to InfluxDB: " + self._configuration['host'])
|
||||
logging.info("Connecting to InfluxDB: " + self._configuration['host'])
|
||||
db_name = self._configuration['db']
|
||||
# self._client.drop_database(db_name)
|
||||
|
||||
if db_name not in self._client.get_list_database():
|
||||
print("Creating InfluxDB database: " + db_name)
|
||||
logging.info("Creating InfluxDB database: " + db_name)
|
||||
self._client.create_database(db_name)
|
||||
|
||||
def write_metrics(self, metrics):
|
||||
self._client.write_points( metrics )
|
||||
self._client.write_points(metrics)
|
||||
|
||||
Reference in New Issue
Block a user