From 4c28d1a7cbc0fd9fdb1a4d75e707fcc1fe727bac Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 Dec 2022 09:19:21 +0100 Subject: [PATCH] Ajout d'outils de statistiques --- statistiques/check_jitsi_room.py | 74 ++++++++++++++++++++++++++++++++ statistiques/getStats.py | 52 ++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100755 statistiques/check_jitsi_room.py create mode 100755 statistiques/getStats.py diff --git a/statistiques/check_jitsi_room.py b/statistiques/check_jitsi_room.py new file mode 100755 index 0000000..984d08e --- /dev/null +++ b/statistiques/check_jitsi_room.py @@ -0,0 +1,74 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Imports +import os +import sys +import requests +import time +import datetime +import argparse + +# Constantes +api_url = 'http://localhost:8080/colibri/stats' + +# Classes +class JitsiStats: + def __init__(self): + self.datas = requests.get(api_url,timeout=1) + + def getTimestamp(self): + return self.datas.json()['current_timestamp'] + + def getVal(self,index): + for (key,value) in self.datas.json().items(): + if key.lower() == index.lower(): + return value + + def getStatsList(self): + liste = [] + for (key,value) in self.datas.json().items(): + t = (key,value) + liste.append(t) + return liste + +# Fonctions +def runMain(): + retStatus = 3 + restString = 'UNKNOWN serveur jitsi meet, champs inconnu(s)' + parser = argparse.ArgumentParser( prog = 'getJistiStats', description = 'Sonde pour les salons jitsi-meet',) + parser.add_argument('-l,--liste', dest="liste", action='store_true') + parser.add_argument('-f,--field', dest='fields', action='append') + args = parser.parse_args() + + stats = JitsiStats() + + if args.liste is True: + champs = stats.getStatsList() + for c in champs: + print(c) + sys.exit(0) + + perfs = '' + if len(args.fields) == 1: + fields = [] + for f in args.fields[0].split(','): + fields.append(f) + else: + fields = args.fields + for field in fields: + if stats.getVal(field) is not None: + #print(f"{field}: {stats.getVal(field)}") + perfs = f"{perfs} {field}={stats.getVal(field)}" + if perfs != '': + #perfs = perfs.replace(' ',';') + restString = f"OK statistiques jitsi-meet {perfs} | {perfs}" + retStatus = 0 + + return (retStatus,restString) + +# Principal +if __name__ == '__main__': + retStatus,restString = runMain() + print(restString) + sys.exit(retStatus) diff --git a/statistiques/getStats.py b/statistiques/getStats.py new file mode 100755 index 0000000..b0e4a3c --- /dev/null +++ b/statistiques/getStats.py @@ -0,0 +1,52 @@ +#! /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' + +# Classes + +# Fonctions +def runMain(): + print('getting...') + 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'/tmp/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(f"total_loss_degraded_participant_seconds {total_loss_degraded_participant_seconds} {timestamp}") + +# Principal +if __name__ == '__main__': + runMain() + sys.exit(0)