override logging interval with secret/minutes.txt

This commit is contained in:
Daniel Langbein 2022-05-31 14:59:18 +02:00
parent ac28f77543
commit 724a9c1d1d
8 changed files with 38 additions and 29 deletions

View File

@ -5,7 +5,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (venv-39)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10 (venv-310)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PackageRequirementsSettings">

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (venv-39)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (venv-310)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,13 +1,15 @@
# README
# bbb-status
Python3 script to log and plot BigBlueButton usage statistics.
Thanks to Bernd Wurst who inspired this project with his gist on github:
* https://gist.github.com/bwurst/7f94e0392c75d273a08d1e686182fc5e
* [https://gist.github.com/bwurst/7f94e0392c75d273a08d1e686182fc5e]()
## setup
## Setup
Execute `bbb-conf --secret` on your server.
This gives you your **API-secret**, the **URL** at which BigBlueButton is running at.
This gives you your **API-secret** and the **URL** at which BigBlueButton is running at.
Save these two values in the first line of the following files:
@ -16,7 +18,9 @@ Save these two values in the first line of the following files:
Note: You may `chmod 600` on the two above files.
## run
Optionally: Set the log interval to something different from 5 minutes by creating `secret/minutes.txt` with an integer in the first line.
## Run
Start logging in the background:
@ -30,7 +34,7 @@ Generate a new plot based on saved meeting data:
sudo docker-compose run bbb-status plot
```
## example logging
## Example - log meeting statistics
```shell
sudo docker-compose up -d # start logging in the background
@ -53,6 +57,6 @@ bbb-status_1 | moderatorCount: 1
bbb-status_1 | >> Sleeping for five minutes <<
```
## example plot
## Example - create a plot from saved statistics
![plot of one month BBB usage](plot-last-month.png)

View File

@ -73,7 +73,7 @@ def getRequestUrl(api_method: str = 'getMeetings', query_string: str = '') -> st
def getUrl() -> str:
filepath = fileUtil.getProjectBaseDir().joinpath("secret").joinpath("url.txt")
filepath = fileUtil.getProjectBaseDir() / "secret" / "url.txt"
url = fileUtil.readFirstLine(filepath).strip()
if not url.endswith("/"):
raise ValueError("url should end with '/'")
@ -81,9 +81,16 @@ def getUrl() -> str:
def getSecret() -> str:
filepath = fileUtil.getProjectBaseDir().joinpath("secret").joinpath("secret.txt")
filepath = fileUtil.getProjectBaseDir() / "secret" / "secret.txt"
secret = fileUtil.readFirstLine(filepath).strip()
min_length = 12
if len(secret) <= min_length:
raise ValueError("secret should be longer than {} characters!".format(min_length))
raise ValueError(f"secret should be longer than {min_length} characters!")
return secret
def getSleepMinutes() -> int:
filepath = fileUtil.getProjectBaseDir() / "secret" / "minutes.txt"
if not filepath.exists():
return 5
return int(fileUtil.readFirstLine(filepath).strip())

View File

@ -1,21 +1,19 @@
#!/usr/bin/python3
import sys
import time
from pathlib import Path
from langfingaz import parseMeetings, bbbRequest, saveData
from langfingaz.bbbRequest import getSleepMinutes
from langfingaz.util import util as util
import langfingaz.util.fileUtil as fileUtil
def sleepFiveMin(verbose=False):
minute = 60
fiveMinutes = 5 * minute
def sleepMinutes(verbose=False):
minutes = getSleepMinutes()
seconds = minutes * 60
if verbose:
print(">> Sleeping for five minutes <<")
util.sleep(fiveMinutes)
print(f">> Sleeping for {minutes} minutes <<")
util.sleep(seconds)
def v2(folder: Path = fileUtil.getDataDir()):
@ -24,21 +22,21 @@ def v2(folder: Path = fileUtil.getDataDir()):
while True:
meetingsStr = bbbRequest.requestMeetingData()
savedFile = saveData.saveMeetingsData(meetingsStr, folder)
print("Saved meetings at {}".format(savedFile))
print(f"Saved meetings at {savedFile}")
meetings = parseMeetings.parseMeetingsData(meetingsStr)
bbbStatus = parseMeetings.BbbStatus(meetings)
bbbStatusStr = str(bbbStatus)
print(util.indentMultilineStr(bbbStatusStr))
sleepFiveMin(verbose=True)
sleepMinutes(verbose=True)
def v1(folder: Path = fileUtil.getDataDir()):
while True:
saveData.requestAndSaveMeetingData(folder)
print('.')
sleepFiveMin()
sleepMinutes()
if __name__ == '__main__':

View File

@ -14,7 +14,7 @@ from langfingaz.util import util
def getDefaultPlotFolder() -> Path:
return fileUtil.getProjectBaseDir().joinpath("plot")
return fileUtil.getProjectBaseDir() / "plot"
def plotMeetings(dataDir: Path = fileUtil.getDataDir()):
@ -81,7 +81,7 @@ def doPlotMeetings(bbbStati: List[BbbStatus]) -> Path:
fig.autofmt_xdate()
imgFormat = 'png'
image: Path = getDefaultPlotFolder().joinpath(
image: Path = getDefaultPlotFolder() / (
"{}_until_{}.{}".format(
fileUtil.asString(time[0]),
fileUtil.asString(time[-1]),

View File

@ -39,7 +39,7 @@ def doSaveData(dataStr: str, folder: Path, dataType: str) -> Path:
:return: Path to created file
"""
fileWithoutDate = folder.joinpath(dataType + '.xml')
fileWithoutDate = folder / f"{dataType}.xml"
prefixedFile = fileUtil.setDatetimePrefix(fileWithoutDate, datetime.now())
with open(prefixedFile, "w") as xml_file:

View File

@ -15,7 +15,7 @@ def getDataDir() -> Path:
"""
:return: The default data directory
"""
return getProjectBaseDir().joinpath("data")
return getProjectBaseDir() / "data"
def readFirstLine(file: Path) -> str:
@ -39,14 +39,14 @@ def setDatetimePrefix(file: Path, t: datetime) -> Path:
# filename = file.name
prefix = asString(t)
filename = prefix + "_" + file.name
return file.parent.joinpath(filename)
return file.parent / filename
def removeDatetimePrefix(file: Path) -> Path:
prefixLen = __getDatetimePrefixLength()
# prefixlen + 1 to remove the underline!
return file.parent.joinpath(file.name[prefixLen + 1:])
return file.parent / file.name[prefixLen + 1:]
def getDatetimePrefix(file: Path) -> datetime: