created and assigned basic dbmanager
This commit is contained in:
parent
818f4bea7c
commit
0249f58247
8 changed files with 46 additions and 42 deletions
11
README.md
11
README.md
|
@ -1,5 +1,8 @@
|
|||
# Grafana Scripts
|
||||
Repo for api scripts written (both pushing and pulling) to aggregate data into influxdb for grafana
|
||||
# Varken
|
||||
Dutch for PIG. PIG is an Acronym for PlexDB/Influx/Grafana
|
||||
|
||||
Varken is a standalone commmandline utility that will aggregate date
|
||||
from the plex ecosystem into influxdb to be displayed in grafana
|
||||
|
||||
Requirements /w install links: [Grafana](http://docs.grafana.org/installation/), [Python3](https://www.python.org/downloads/), [InfluxDB](https://docs.influxdata.com/influxdb/v1.5/introduction/installation/)
|
||||
|
||||
|
@ -7,8 +10,8 @@ Requirements /w install links: [Grafana](http://docs.grafana.org/installation/),
|
|||
|
||||
## Quick Setup
|
||||
1. Install requirements `pip3 install -r requirements.txt`
|
||||
1. Make a copy of `configuration.example.py` to `configuration.py`
|
||||
2. Make the appropriate changes to `configuration.py`
|
||||
1. Make a copy of `varken.example.ini` to `varken.ini` in the `data` folder
|
||||
2. Make the appropriate changes to `varken.ini`
|
||||
1. Create your plex database in influx
|
||||
```sh
|
||||
user@server: ~$ influx
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
from influxdb import InfluxDBClient
|
||||
|
||||
class DBManager(object):
|
||||
def __init__(self, server):
|
||||
self.server = server
|
||||
self.influx = InfluxDBClient(self.server.url, self.server.port, self.server.username, self.server.password,
|
||||
'plex2')
|
||||
databases = [db['name'] for db in self.influx.get_list_database()]
|
||||
|
||||
if 'varken' not in databases:
|
||||
self.influx.create_database('varken')
|
||||
self.influx.create_retention_policy('Varken 30d/1h', '30d', '1', 'varken', False, '1h')
|
||||
|
||||
def write_points(self, data):
|
||||
self.influx.write_points(data)
|
|
@ -6,18 +6,14 @@ from Varken.helpers import OmbiRequestCounts
|
|||
from Varken.logger import logging
|
||||
|
||||
class OmbiAPI(object):
|
||||
def __init__(self, server, influx_server):
|
||||
def __init__(self, server, dbmanager):
|
||||
self.now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
self.influx = InfluxDBClient(influx_server.url, influx_server.port, influx_server.username,
|
||||
influx_server.password, 'plex2')
|
||||
self.dbmanager = dbmanager
|
||||
self.server = server
|
||||
# Create session to reduce server web thread load, and globally define pageSize for all requests
|
||||
self.session = Session()
|
||||
self.session.headers = {'Apikey': self.server.api_key}
|
||||
|
||||
def influx_push(self, payload):
|
||||
self.influx.write_points(payload)
|
||||
|
||||
@logging
|
||||
def get_total_requests(self):
|
||||
self.now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
|
@ -44,7 +40,7 @@ class OmbiAPI(object):
|
|||
}
|
||||
]
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
||||
@logging
|
||||
def get_request_counts(self):
|
||||
|
@ -67,4 +63,4 @@ class OmbiAPI(object):
|
|||
}
|
||||
]
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
|
|
@ -7,17 +7,13 @@ from Varken.helpers import Movie, Queue
|
|||
|
||||
|
||||
class RadarrAPI(object):
|
||||
def __init__(self, server, influx_server):
|
||||
def __init__(self, server, dbmanager):
|
||||
self.now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
self.influx = InfluxDBClient(influx_server.url, influx_server.port, influx_server.username,
|
||||
influx_server.password, 'plex2')
|
||||
self.dbmanager = dbmanager
|
||||
self.server = server
|
||||
# Create session to reduce server web thread load, and globally define pageSize for all requests
|
||||
self.session = Session()
|
||||
|
||||
def influx_push(self, payload):
|
||||
self.influx.write_points(payload)
|
||||
|
||||
@logging
|
||||
def get_missing(self):
|
||||
endpoint = '/api/movie'
|
||||
|
@ -55,7 +51,7 @@ class RadarrAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
||||
@logging
|
||||
def get_queue(self):
|
||||
|
@ -100,4 +96,4 @@ class RadarrAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from requests import Session
|
||||
from influxdb import InfluxDBClient
|
||||
from datetime import datetime, timezone, date, timedelta
|
||||
|
||||
from Varken.logger import logging
|
||||
|
@ -7,12 +6,11 @@ from Varken.helpers import TVShow, Queue
|
|||
|
||||
|
||||
class SonarrAPI(object):
|
||||
def __init__(self, server, influx_server):
|
||||
def __init__(self, server, dbmanager):
|
||||
# Set Time of initialization
|
||||
self.now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
self.dbmanager = dbmanager
|
||||
self.today = str(date.today())
|
||||
self.influx = InfluxDBClient(influx_server.url, influx_server.port, influx_server.username,
|
||||
influx_server.password, 'plex')
|
||||
self.server = server
|
||||
# Create session to reduce server web thread load, and globally define pageSize for all requests
|
||||
self.session = Session()
|
||||
|
@ -58,7 +56,7 @@ class SonarrAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
||||
@logging
|
||||
def get_future(self):
|
||||
|
@ -98,7 +96,7 @@ class SonarrAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
||||
@logging
|
||||
def get_queue(self):
|
||||
|
@ -142,7 +140,4 @@ class SonarrAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
|
||||
def influx_push(self, payload):
|
||||
self.influx.write_points(payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
|
|
@ -7,18 +7,14 @@ from Varken.logger import logging
|
|||
|
||||
|
||||
class TautulliAPI(object):
|
||||
def __init__(self, server, influx_server):
|
||||
def __init__(self, server, dbmanager):
|
||||
# Set Time of initialization
|
||||
self.now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
self.influx = InfluxDBClient(influx_server.url, influx_server.port, influx_server.username,
|
||||
influx_server.password, 'plex2')
|
||||
self.dbmanager = dbmanager
|
||||
self.server = server
|
||||
self.session = Session()
|
||||
self.endpoint = '/api/v2'
|
||||
|
||||
def influx_push(self, payload):
|
||||
self.influx.write_points(payload)
|
||||
|
||||
@logging
|
||||
def get_activity(self):
|
||||
self.now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
|
@ -48,7 +44,7 @@ class TautulliAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
||||
@logging
|
||||
def get_sessions(self):
|
||||
|
@ -144,4 +140,4 @@ class TautulliAPI(object):
|
|||
}
|
||||
)
|
||||
|
||||
self.influx_push(influx_payload)
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
requests
|
||||
geoip2
|
||||
influxdb
|
||||
schedule
|
10
varken.py
10
varken.py
|
@ -7,6 +7,7 @@ from Varken.sonarr import SonarrAPI
|
|||
from Varken.tautulli import TautulliAPI
|
||||
from Varken.radarr import RadarrAPI
|
||||
from Varken.ombi import OmbiAPI
|
||||
from Varken.dbmanager import DBManager
|
||||
|
||||
def threaded(job):
|
||||
thread = threading.Thread(target=job)
|
||||
|
@ -15,10 +16,11 @@ def threaded(job):
|
|||
|
||||
if __name__ == "__main__":
|
||||
CONFIG = INIParser()
|
||||
DBMANAGER = DBManager(CONFIG.influx_server)
|
||||
|
||||
if CONFIG.sonarr_enabled:
|
||||
for server in CONFIG.sonarr_servers:
|
||||
SONARR = SonarrAPI(server, CONFIG.influx_server)
|
||||
SONARR = SonarrAPI(server, DBMANAGER)
|
||||
if server.queue:
|
||||
schedule.every(server.queue_run_seconds).seconds.do(threaded, SONARR.get_queue)
|
||||
if server.missing_days > 0:
|
||||
|
@ -28,7 +30,7 @@ if __name__ == "__main__":
|
|||
|
||||
if CONFIG.tautulli_enabled:
|
||||
for server in CONFIG.tautulli_servers:
|
||||
TAUTULLI = TautulliAPI(server, CONFIG.influx_server)
|
||||
TAUTULLI = TautulliAPI(server, DBMANAGER)
|
||||
if server.get_activity:
|
||||
schedule.every(server.get_activity_run_seconds).seconds.do(threaded, TAUTULLI.get_activity)
|
||||
if server.get_sessions:
|
||||
|
@ -36,7 +38,7 @@ if __name__ == "__main__":
|
|||
|
||||
if CONFIG.radarr_enabled:
|
||||
for server in CONFIG.radarr_servers:
|
||||
RADARR = RadarrAPI(server, CONFIG.influx_server)
|
||||
RADARR = RadarrAPI(server, DBMANAGER)
|
||||
if server.get_missing:
|
||||
schedule.every(server.get_missing_run_seconds).seconds.do(threaded, RADARR.get_missing)
|
||||
if server.queue:
|
||||
|
@ -44,7 +46,7 @@ if __name__ == "__main__":
|
|||
|
||||
if CONFIG.ombi_enabled:
|
||||
for server in CONFIG.ombi_servers:
|
||||
OMBI = OmbiAPI(server, CONFIG.influx_server)
|
||||
OMBI = OmbiAPI(server, DBMANAGER)
|
||||
if server.request_type_counts:
|
||||
schedule.every(server.request_type_run_seconds).seconds.do(threaded, OMBI.get_request_counts)
|
||||
if server.request_total_counts:
|
||||
|
|
Loading…
Reference in a new issue