Make InfluxDB connection options configurable
This commit is contained in:
parent
a130e2215a
commit
99e2fad2b2
@ -16,6 +16,9 @@ services:
|
|||||||
- "DATABASE_NAME=postgres"
|
- "DATABASE_NAME=postgres"
|
||||||
- "DATABASE_HOST=db"
|
- "DATABASE_HOST=db"
|
||||||
- "DATABASE_PORT=5432"
|
- "DATABASE_PORT=5432"
|
||||||
|
- "INFLUX_HOST=influx"
|
||||||
|
- "INFLUX_PORT=8086"
|
||||||
|
- "INFLUX_DB=pluralkit"
|
||||||
restart: always
|
restart: always
|
||||||
api:
|
api:
|
||||||
build: src/
|
build: src/
|
||||||
|
@ -126,8 +126,13 @@ class PluralKitBot:
|
|||||||
async with self.pool.acquire() as conn:
|
async with self.pool.acquire() as conn:
|
||||||
await db.create_tables(conn)
|
await db.create_tables(conn)
|
||||||
|
|
||||||
|
if "INFLUX_HOST" in os.environ:
|
||||||
self.logger.info("Connecting to InfluxDB...")
|
self.logger.info("Connecting to InfluxDB...")
|
||||||
self.stats = await InfluxStatCollector.connect()
|
self.stats = await InfluxStatCollector.connect(
|
||||||
|
os.environ["INFLUX_HOST"],
|
||||||
|
os.environ["INFLUX_PORT"],
|
||||||
|
os.environ["INFLUX_DB"]
|
||||||
|
)
|
||||||
|
|
||||||
self.logger.info("Starting periodical stat reporting...")
|
self.logger.info("Starting periodical stat reporting...")
|
||||||
asyncio.get_event_loop().create_task(self.periodical_stat_timer(self.pool))
|
asyncio.get_event_loop().create_task(self.periodical_stat_timer(self.pool))
|
||||||
|
@ -21,9 +21,9 @@ class NullStatCollector(StatCollector):
|
|||||||
|
|
||||||
class InfluxStatCollector(StatCollector):
|
class InfluxStatCollector(StatCollector):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def connect():
|
async def connect(host: str, port: int, db: str):
|
||||||
client = InfluxDBClient(host="influx", db="pluralkit")
|
client = InfluxDBClient(host=host, port=port, db=db)
|
||||||
await client.create_database(db="pluralkit")
|
await client.create_database(db=db)
|
||||||
|
|
||||||
return InfluxStatCollector(client)
|
return InfluxStatCollector(client)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user