config test

This commit is contained in:
David 2022-12-18 23:48:52 +01:00
parent efe5c0cb2f
commit dd580e6bd9
2 changed files with 49 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import sqlite3
api_url = 'http://localhost:8080/colibri/stats'
statsPath = '/srv/visio.chapril.org/statistiques'
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
dbName = 'jitsi_stats'
# Classes
class SQLite:
@ -22,7 +23,7 @@ class SQLite:
def __initDb(self):
self.__openDb()
self.cursor.execute(''' create table jitsi_stats(
self.cursor.execute(f''' create table {dbName}(
id integer primary key autoincrement,
timestamp text,
key_field text,
@ -42,14 +43,14 @@ class SQLite:
def dbQuery(self,query='SELECT'):
self.__openDb()
self.cursor.execute(f"""SELECT * FROM jististats""")
self.cursor.execute(f"""SELECT * FROM {dbName}""")
rows = self.cursor.fetchall()
self.__closeDb()
return rows
def dbInsert(self,ts,k,v):
self.__openDb()
self.cursor.execute(f"""INSERT INTO jististats (timestamp,key_field,value_field) VALUES ('{ts}','{k}','{v}')""")
self.cursor.execute(f"""INSERT INTO {dbname} (timestamp,key_field,value_field) VALUES ('{ts}','{k}','{v}')""")
self.conn.commit()
self.__closeDb()

View File

@ -7,7 +7,7 @@ import sys
import time
import datetime
from calendar import monthrange
import sqlite3
# Constantes
STAT_DIR = '/srv/visio.chapril.org/statistiques/'
@ -16,10 +16,12 @@ STATS_TOT_FIELDS = ['total_conferences_created','total_failed_conferences','tota
STATS_FR_TOT_FIELDS = ['conferences creees total','conferences totalement echouees','conferences terminees total','duree totale conferences','total octets reçus','total octets envoyés','total participants','nombre de conferences','canaux video','clients en audio',]
STATS_AVG_FIELDS = ['largest_conference',]
STATS_FR_AVG_FIELDS = ['plus grande conference',]
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
# Classes
class Stats:
def __init__(self,year,mois):
self.db = SQLite()
self.year = year
self.mois = mois
self.files = os.listdir(STAT_DIR)
@ -80,6 +82,10 @@ class Stats:
octets = int(octets * 10) / 10
return octets,unit
def parse2(self):
res = self.db.dbQuery(f"""SELECT * FROM {dbname} WHERE ts > {self.startDate} AND ts < {self.endDate}""")
return res
def parse(self):
if len(self.files) <= 0:
return None
@ -121,6 +127,44 @@ class Stats:
self.consolided[k] = f"{octets} {unit}"
return self.consolided
class SQLite:
def __init__(self):
if not os.path.isfile(dbPath):
self.__initDb()
def __initDb(self):
self.__openDb()
self.cursor.execute(''' create table jitsi_stats(
id integer primary key autoincrement,
timestamp text,
key_field text,
value_field text
)
''')
self.conn.commit()
self.__closeDb()
def __openDb(self):
self.conn = sqlite3.connect(dbPath)
self.cursor = self.conn.cursor()
def __closeDb(self):
self.cursor.close()
self.conn.close()
def dbQuery(self,query='SELECT'):
self.__openDb()
self.cursor.execute(query)
rows = self.cursor.fetchall()
self.__closeDb()
return rows
def dbInsert(self,ts,k,v):
self.__openDb()
self.cursor.execute(f"""INSERT INTO jististats (timestamp,key_field,value_field) VALUES ('{ts}','{k}','{v}')""")
self.conn.commit()
self.__closeDb()
# Fonctions
# Principal