visio.chapril.org-tools/statistiques/getStats.py

43 lines
1.4 KiB
Python
Executable File

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Imports
import os
import sys
import requests
import time
import datetime
# Constantes
api_url = 'http://localhost:8080/colibri/stats'
statsPath = '/srv/visio.chapril.org/statistiques'
# Classes
# Fonctions
def runMain():
response = requests.get(api_url,timeout=1)
current_ts = response.json()['current_timestamp']
total_participants = response.json()['total_participants']
bit_rate_download = response.json()['bit_rate_download']
total_loss_degraded_participant_seconds = response.json()['total_loss_degraded_participant_seconds']
conferences = response.json()['conferences']
participants = response.json()['participants']
bit_rate_upload = response.json()['bit_rate_upload']
total_visitors = response.json()['total_visitors']
total_conference_seconds = response.json()['total_conference_seconds']
total_conferences_created = response.json()['total_conferences_created']
total_failed_conferences = response.json()['total_failed_conferences']
element = datetime.datetime.strptime(response.json()['current_timestamp'],'%Y-%m-%d %H:%M:%S.%f')
tpl = element.timetuple()
timestamp = int(time.mktime(tpl))
with open(f'/{statsPath}/jisti_meet_stats_{timestamp}.csv','w') as fh:
for (k,v) in response.json().items():
fh.write(f"{k};{v};{timestamp}\n")
# Principal
if __name__ == '__main__':
runMain()
sys.exit(0)