config test
This commit is contained in:
parent
efe5c0cb2f
commit
dd580e6bd9
@ -13,6 +13,7 @@ import sqlite3
|
|||||||
api_url = 'http://localhost:8080/colibri/stats'
|
api_url = 'http://localhost:8080/colibri/stats'
|
||||||
statsPath = '/srv/visio.chapril.org/statistiques'
|
statsPath = '/srv/visio.chapril.org/statistiques'
|
||||||
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
|
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
|
||||||
|
dbName = 'jitsi_stats'
|
||||||
|
|
||||||
# Classes
|
# Classes
|
||||||
class SQLite:
|
class SQLite:
|
||||||
@ -22,7 +23,7 @@ class SQLite:
|
|||||||
|
|
||||||
def __initDb(self):
|
def __initDb(self):
|
||||||
self.__openDb()
|
self.__openDb()
|
||||||
self.cursor.execute(''' create table jitsi_stats(
|
self.cursor.execute(f''' create table {dbName}(
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
timestamp text,
|
timestamp text,
|
||||||
key_field text,
|
key_field text,
|
||||||
@ -42,14 +43,14 @@ class SQLite:
|
|||||||
|
|
||||||
def dbQuery(self,query='SELECT'):
|
def dbQuery(self,query='SELECT'):
|
||||||
self.__openDb()
|
self.__openDb()
|
||||||
self.cursor.execute(f"""SELECT * FROM jististats""")
|
self.cursor.execute(f"""SELECT * FROM {dbName}""")
|
||||||
rows = self.cursor.fetchall()
|
rows = self.cursor.fetchall()
|
||||||
self.__closeDb()
|
self.__closeDb()
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
def dbInsert(self,ts,k,v):
|
def dbInsert(self,ts,k,v):
|
||||||
self.__openDb()
|
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.conn.commit()
|
||||||
self.__closeDb()
|
self.__closeDb()
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
from calendar import monthrange
|
from calendar import monthrange
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
# Constantes
|
# Constantes
|
||||||
STAT_DIR = '/srv/visio.chapril.org/statistiques/'
|
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_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_AVG_FIELDS = ['largest_conference',]
|
||||||
STATS_FR_AVG_FIELDS = ['plus grande conference',]
|
STATS_FR_AVG_FIELDS = ['plus grande conference',]
|
||||||
|
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
|
||||||
|
|
||||||
# Classes
|
# Classes
|
||||||
class Stats:
|
class Stats:
|
||||||
def __init__(self,year,mois):
|
def __init__(self,year,mois):
|
||||||
|
self.db = SQLite()
|
||||||
self.year = year
|
self.year = year
|
||||||
self.mois = mois
|
self.mois = mois
|
||||||
self.files = os.listdir(STAT_DIR)
|
self.files = os.listdir(STAT_DIR)
|
||||||
@ -80,6 +82,10 @@ class Stats:
|
|||||||
octets = int(octets * 10) / 10
|
octets = int(octets * 10) / 10
|
||||||
return octets,unit
|
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):
|
def parse(self):
|
||||||
if len(self.files) <= 0:
|
if len(self.files) <= 0:
|
||||||
return None
|
return None
|
||||||
@ -121,6 +127,44 @@ class Stats:
|
|||||||
self.consolided[k] = f"{octets} {unit}"
|
self.consolided[k] = f"{octets} {unit}"
|
||||||
return self.consolided
|
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
|
# Fonctions
|
||||||
|
|
||||||
# Principal
|
# Principal
|
||||||
|
Loading…
Reference in New Issue
Block a user