Mise a jour outils de stats
This commit is contained in:
parent
4c28d1a7cb
commit
7c06d545c2
@ -10,12 +10,13 @@ import datetime
|
||||
|
||||
# Constantes
|
||||
api_url = 'http://localhost:8080/colibri/stats'
|
||||
statsPath = '/srv/visio.chapril.org/statistiques'
|
||||
|
||||
# Classes
|
||||
|
||||
# Fonctions
|
||||
def runMain():
|
||||
print('getting...')
|
||||
#print('getting...')
|
||||
response = requests.get(api_url,timeout=1)
|
||||
|
||||
current_ts = response.json()['current_timestamp']
|
||||
@ -32,18 +33,18 @@ def runMain():
|
||||
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'/tmp/jisti_meet_stats_{timestamp}.csv','w') as fh:
|
||||
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")
|
||||
print('-------------------------------------------------------')
|
||||
print(f"conferences {conferences} {timestamp}")
|
||||
print(f"participants {participants} {timestamp}")
|
||||
print(f"bit_rate_upload {bit_rate_upload} {timestamp}")
|
||||
print(f"total_participants {total_participants} {timestamp}")
|
||||
print(f"total_visitors {total_visitors} {timestamp}")
|
||||
print(f"total_conference_seconds {total_conference_seconds} {timestamp}")
|
||||
print(f"total_conferences_created {total_conferences_created} {timestamp}")
|
||||
print(f"total_failed_conferences {total_failed_conferences} {timestamp}")
|
||||
#print('-------------------------------------------------------')
|
||||
#print(f"conferences {conferences} {timestamp}")
|
||||
#print(f"participants {participants} {timestamp}")
|
||||
#print(f"bit_rate_upload {bit_rate_upload} {timestamp}")
|
||||
#print(f"total_participants {total_participants} {timestamp}")
|
||||
#print(f"total_visitors {total_visitors} {timestamp}")
|
||||
#print(f"total_conference_seconds {total_conference_seconds} {timestamp}")
|
||||
#print(f"total_conferences_created {total_conferences_created} {timestamp}")
|
||||
#print(f"total_failed_conferences {total_failed_conferences} {timestamp}")
|
||||
#print(f"total_loss_degraded_participant_seconds {total_loss_degraded_participant_seconds} {timestamp}")
|
||||
|
||||
# Principal
|
||||
|
128
statistiques/parseStats.py
Executable file
128
statistiques/parseStats.py
Executable file
@ -0,0 +1,128 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Imports
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
from calendar import monthrange
|
||||
|
||||
|
||||
# Constantes
|
||||
STAT_DIR = '/srv/visio.chapril.org/statistiques/'
|
||||
STATS_TOT_FIELDS = ['total_participants','total_visitors','total_conferences_completed','total_conferences_created','total_partially_failed_conferences','total_failed_conferences',]
|
||||
STATS_FR_TOT_FIELDS = ['participants total','visiteurs total','conferences terminees total','conferences creees total','conferences partiellement echouees','conferences totalement echouees',]
|
||||
STATS_AVG_FIELDS = ['largest_conference',]
|
||||
STATS_FR_AVG_FIELDS = ['plus grande conference',]
|
||||
|
||||
# Classes
|
||||
class Stats:
|
||||
def __init__(self,year,mois):
|
||||
self.year = year
|
||||
self.mois = mois
|
||||
self.files = os.listdir(STAT_DIR)
|
||||
self.startDate = self.EndDate = None
|
||||
self.consolided = {}
|
||||
self.consolided_datas = {}
|
||||
self.__initBounds()
|
||||
|
||||
def __initBounds(self):
|
||||
self.__setStartDate(f'{self.year}-{self.mois}-01 00:00:00')
|
||||
maxDays = monthrange(self.year,self.mois)[1]
|
||||
self.__setEndDate(f'{self.year}-{self.mois}-{maxDays} 23:59:59')
|
||||
|
||||
|
||||
def __setStartDate(self,thisDate):
|
||||
self.startDate = self.__date2timestamp(thisDate)
|
||||
|
||||
def getStartDate(self):
|
||||
if self.startDate is not None:
|
||||
return self.startDate
|
||||
else:
|
||||
return 'undefiined'
|
||||
|
||||
def getEndDate(self):
|
||||
if self.endDate is not None:
|
||||
return self.endDate
|
||||
else:
|
||||
return 'undefiined'
|
||||
|
||||
def __setEndDate(self,thisDate):
|
||||
self.endDate = self.__date2timestamp(thisDate)
|
||||
|
||||
def __date2timestamp(self,thisDate):
|
||||
timestamp = time.mktime(time.strptime(thisDate, '%Y-%m-%d %H:%M:%S'))
|
||||
return int(timestamp)
|
||||
|
||||
def parse(self):
|
||||
if len(self.files) <= 0:
|
||||
return None
|
||||
for f in self.files:
|
||||
ts = int(f.split('.')[0].split('_')[3])
|
||||
if ts >= self.startDate and ts <= self.endDate:
|
||||
with open(f"{STAT_DIR}/{f}") as fh:
|
||||
datas = fh.readlines()
|
||||
for line in datas:
|
||||
if line.split(';')[0].lower() in STATS_TOT_FIELDS:
|
||||
key = line.split(';')[0].lower()
|
||||
value = int(line.split(';')[1])
|
||||
if key in self.consolided_datas:
|
||||
datas = self.consolided_datas[key]
|
||||
if datas[0] <= 0:
|
||||
self.consolided_datas[key][0] = value
|
||||
else:
|
||||
if value > datas[1]:
|
||||
self.consolided_datas[key][1] = value
|
||||
else:
|
||||
self.consolided_datas[key] = [value,0]
|
||||
|
||||
if line.split(';')[0].lower() in STATS_AVG_FIELDS:
|
||||
key = line.split(';')[0].lower()
|
||||
value = int(line.split(';')[1])
|
||||
if key in self.consolided:
|
||||
if self.consolided[key] < int(value):
|
||||
self.consolided[key] = int(value)
|
||||
else:
|
||||
self.consolided[key] = 0
|
||||
|
||||
for (k,v) in self.consolided_datas.items():
|
||||
self.consolided[k] = v[1] - v[0]
|
||||
return self.consolided
|
||||
|
||||
# Fonctions
|
||||
|
||||
# Principal
|
||||
def runMain():
|
||||
if len(sys.argv) <= 1:
|
||||
print('Argument manquant: mois')
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
mois = int(sys.argv[1])
|
||||
except ValueError:
|
||||
print('Le mois doit etre un nombre compris entre 1 et 12 !')
|
||||
sys.exit(1)
|
||||
|
||||
if mois < 1 or mois > 12:
|
||||
print('Le mois doit etre un nombre compris entre 1 et 12 !')
|
||||
sys.exit(1)
|
||||
|
||||
currentDate = datetime.date.today()
|
||||
if len(sys.argv) >= 3:
|
||||
year = int(sys.argv[2])
|
||||
else:
|
||||
year = currentDate.year
|
||||
|
||||
stats = Stats(year,mois)
|
||||
res = stats.parse()
|
||||
for (k,v) in res.items():
|
||||
if k in STATS_TOT_FIELDS:
|
||||
chaine = STATS_FR_TOT_FIELDS[STATS_TOT_FIELDS.index(k)]
|
||||
elif k in STATS_AVG_FIELDS:
|
||||
chaine = STATS_FR_AVG_FIELDS[STATS_AVG_FIELDS.index(k)]
|
||||
print(f"{chaine} : {v}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
runMain()
|
||||
# Fin du programme
|
Loading…
Reference in New Issue
Block a user