added stats pull from tautulli -,-
This commit is contained in:
parent
831498f89b
commit
67b98d57ea
5 changed files with 49 additions and 3 deletions
|
@ -103,6 +103,8 @@ if __name__ == "__main__":
|
|||
TAUTULLI = TautulliAPI(server, DBMANAGER, GEOIPHANDLER)
|
||||
if server.get_activity:
|
||||
schedule.every(server.get_activity_run_seconds).seconds.do(threaded, TAUTULLI.get_activity)
|
||||
if server.get_stats:
|
||||
schedule.every(server.get_stats_run_seconds).seconds.do(threaded, TAUTULLI.get_stats)
|
||||
|
||||
if CONFIG.radarr_enabled:
|
||||
for server in CONFIG.radarr_servers:
|
||||
|
|
|
@ -27,6 +27,8 @@ ssl = false
|
|||
verify_ssl = false
|
||||
get_activity = true
|
||||
get_activity_run_seconds = 30
|
||||
get_stats = true
|
||||
get_stats_run_seconds = 3600
|
||||
|
||||
[sonarr-1]
|
||||
url = sonarr1.domain.tld:8989
|
||||
|
|
|
@ -160,8 +160,13 @@ class INIParser(object):
|
|||
|
||||
get_activity_run_seconds = self.config.getint(section, 'get_activity_run_seconds')
|
||||
|
||||
get_stats = self.config.getboolean(section, 'get_stats')
|
||||
|
||||
get_stats_run_seconds = self.config.getint(section, 'get_stats_run_seconds')
|
||||
|
||||
server = TautulliServer(server_id, scheme + url, fallback_ip, apikey, verify_ssl,
|
||||
get_activity, get_activity_run_seconds)
|
||||
get_activity, get_activity_run_seconds, get_stats,
|
||||
get_stats_run_seconds)
|
||||
|
||||
if service == 'ombi':
|
||||
request_type_counts = self.config.getboolean(section, 'get_request_type_counts')
|
||||
|
|
|
@ -71,6 +71,8 @@ class TautulliServer(NamedTuple):
|
|||
verify_ssl: bool = None
|
||||
get_activity: bool = False
|
||||
get_activity_run_seconds: int = 30
|
||||
get_stats: bool = False
|
||||
get_stats_run_seconds: int = 30
|
||||
|
||||
|
||||
class InfluxServer(NamedTuple):
|
||||
|
|
|
@ -13,7 +13,7 @@ class TautulliAPI(object):
|
|||
self.server = server
|
||||
self.geoiphandler = geoiphandler
|
||||
self.session = Session()
|
||||
self.session.params = {'apikey': self.server.api_key, 'cmd': 'get_activity'}
|
||||
self.session.params = {'apikey': self.server.api_key}
|
||||
self.endpoint = '/api/v2'
|
||||
self.logger = getLogger()
|
||||
|
||||
|
@ -23,8 +23,9 @@ class TautulliAPI(object):
|
|||
def get_activity(self):
|
||||
now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
influx_payload = []
|
||||
params = {'cmd': 'get_activity'}
|
||||
|
||||
req = self.session.prepare_request(Request('GET', self.server.url + self.endpoint))
|
||||
req = self.session.prepare_request(Request('GET', self.server.url + self.endpoint, params=params))
|
||||
g = connection_handler(self.session, req, self.server.verify_ssl)
|
||||
|
||||
if not g:
|
||||
|
@ -150,3 +151,37 @@ class TautulliAPI(object):
|
|||
)
|
||||
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
||||
def get_stats(self):
|
||||
now = datetime.now(timezone.utc).astimezone().isoformat()
|
||||
influx_payload = []
|
||||
params = {'cmd': 'get_libraries'}
|
||||
|
||||
req = self.session.prepare_request(Request('GET', self.server.url + self.endpoint, params=params))
|
||||
g = connection_handler(self.session, req, self.server.verify_ssl)
|
||||
|
||||
if not g:
|
||||
return
|
||||
|
||||
get = g['response']['data']
|
||||
|
||||
for library in get:
|
||||
data = {
|
||||
"measurement": "Tautulli",
|
||||
"tags": {
|
||||
"type": "library_stats",
|
||||
"server": self.server.id,
|
||||
"section_name": library['section_name'],
|
||||
"section_type": library['section_type']
|
||||
},
|
||||
"time": now,
|
||||
"fields": {
|
||||
"total": int(library['count'])
|
||||
}
|
||||
}
|
||||
if library['section_type'] == 'show':
|
||||
data['fields']['seasons'] = int(library['parent_count'])
|
||||
data['fields']['episodes'] = int(library['child_count'])
|
||||
influx_payload.append(data)
|
||||
|
||||
self.dbmanager.write_points(influx_payload)
|
||||
|
|
Loading…
Reference in a new issue