Skip to content
Snippets Groups Projects
Commit f98f0bf8 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Add --userconfig option and display load on server

parent 9e07d4bc
Branches
Tags v0.1.15
No related merge requests found
...@@ -38,7 +38,8 @@ class AliasedGroup(click.Group): ...@@ -38,7 +38,8 @@ class AliasedGroup(click.Group):
@click.group(context_settings=CONTEXT_SETTINGS, cls=AliasedGroup) @click.group(context_settings=CONTEXT_SETTINGS, cls=AliasedGroup)
def main(): @click.option('--userconfig', '-u', is_flag=True, help="Use user config even if on server")
def main(userconfig):
"""BBBMON is a small CLI utility to monitor bbb usage """BBBMON is a small CLI utility to monitor bbb usage
\b \b
...@@ -53,6 +54,7 @@ def main(): ...@@ -53,6 +54,7 @@ def main():
@main.command(context_settings=CONTEXT_SETTINGS) @main.command(context_settings=CONTEXT_SETTINGS)
@click.pass_context @click.pass_context
@click.option('--userconfig', '-u', is_flag=True, help="Use user config even if on server")
@click.option('--endpoint', '-e', multiple=True, help="Filter by one or more endpoints as named in the user configuration (e.g. [servername]). Order is respected.") @click.option('--endpoint', '-e', multiple=True, help="Filter by one or more endpoints as named in the user configuration (e.g. [servername]). Order is respected.")
@click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True)) @click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True))
@click.option('--leaderboards/--no-leaderboards', default=True, show_default=True, help="Hide or show the meeting leaderboards") @click.option('--leaderboards/--no-leaderboards', default=True, show_default=True, help="Hide or show the meeting leaderboards")
...@@ -64,7 +66,7 @@ def main(): ...@@ -64,7 +66,7 @@ def main():
@click.option('--twolines', '-2', is_flag=True, help="Print essentials on two lines") @click.option('--twolines', '-2', is_flag=True, help="Print essentials on two lines")
@click.option('--all', '-a', 'all_', is_flag=True, help="Print all") @click.option('--all', '-a', 'all_', is_flag=True, help="Print all")
@click.option('--fancy/--no-fancy', default=True, show_default=True, help="Use fancy headers") @click.option('--fancy/--no-fancy', default=True, show_default=True, help="Use fancy headers")
def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy): def meetings(ctx, userconfig, short, all_, twolines, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
"""View currently active meetings""" """View currently active meetings"""
if short: if short:
leaderboards = False leaderboards = False
...@@ -75,7 +77,7 @@ def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter, ...@@ -75,7 +77,7 @@ def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter,
presenter_id = True presenter_id = True
meetings = True meetings = True
config = init_config() config = init_config(userconfig)
config.filter_endpoints(endpoint) config.filter_endpoints(endpoint)
if watch is not None: if watch is not None:
while watch is not None: while watch is not None:
...@@ -98,7 +100,7 @@ def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter, ...@@ -98,7 +100,7 @@ def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter,
@click.option('--edit', is_flag=True, help="Open the config in the default editor") @click.option('--edit', is_flag=True, help="Open the config in the default editor")
@click.option('--print', 'print_', is_flag=True, help="Print the config to stdout") @click.option('--print', 'print_', is_flag=True, help="Print the config to stdout")
@click.option('--path', is_flag=True, help="Print the path to the config") @click.option('--path', is_flag=True, help="Print the path to the config")
def config(ctx, new, edit, path, print_): def config(ctx, userconfig, new, edit, path, print_):
"""Print, show or edit the config""" """Print, show or edit the config"""
user_config_path = get_user_config_path() user_config_path = get_user_config_path()
......
...@@ -33,6 +33,7 @@ class Config(): ...@@ -33,6 +33,7 @@ class Config():
def __init__(self): def __init__(self):
self.endpoints = [] self.endpoints = []
self.path = None self.path = None
self.on_server = None
def from_server(self, path: str=SERVER_PROPERTIES_FILE) -> 'Config': def from_server(self, path: str=SERVER_PROPERTIES_FILE) -> 'Config':
""" """
...@@ -49,6 +50,7 @@ class Config(): ...@@ -49,6 +50,7 @@ class Config():
endpoint = Endpoint(url=bbb_url, secret=secret) endpoint = Endpoint(url=bbb_url, secret=secret)
self.endpoints.append(endpoint) self.endpoints.append(endpoint)
self.path = path self.path = path
self.on_server = True
return self return self
def from_config(self, path: str) -> 'Config': def from_config(self, path: str) -> 'Config':
...@@ -66,10 +68,12 @@ class Config(): ...@@ -66,10 +68,12 @@ class Config():
endpoint = Endpoint(url=bbb_url, secret=secret, name=section) endpoint = Endpoint(url=bbb_url, secret=secret, name=section)
self.endpoints.append(endpoint) self.endpoints.append(endpoint)
self.path = path self.path = path
self.on_server = False
return self return self
# Fallback for config files without sections # Fallback for config files without sections
except configparser.MissingSectionHeaderError: except configparser.MissingSectionHeaderError:
self = self.from_server(path) self = self.from_server(path)
self.on_server = False
return self return self
def filter_endpoints(self, endpoint_options: List[str]) -> 'Config': def filter_endpoints(self, endpoint_options: List[str]) -> 'Config':
...@@ -125,7 +129,7 @@ class Endpoint(): ...@@ -125,7 +129,7 @@ class Endpoint():
self.name = name self.name = name
def init_config() -> Optional[Config]: def init_config(userconfig: bool) -> Optional[Config]:
""" """
Read the config either from the servers bigbluebutton.properties-file or from Read the config either from the servers bigbluebutton.properties-file or from
the user config path. Display a message if neither of these files exist. the user config path. Display a message if neither of these files exist.
...@@ -134,7 +138,7 @@ def init_config() -> Optional[Config]: ...@@ -134,7 +138,7 @@ def init_config() -> Optional[Config]:
user_config_path = get_user_config_path() user_config_path = get_user_config_path()
# Check if we are on the server and try to read that properties file first # Check if we are on the server and try to read that properties file first
if os.path.isfile(SERVER_PROPERTIES_FILE): if os.path.isfile(SERVER_PROPERTIES_FILE) and not userconfig:
return Config().from_server() return Config().from_server()
elif os.path.isfile(user_config_path): elif os.path.isfile(user_config_path):
return Config().from_config(user_config_path) return Config().from_config(user_config_path)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import subprocess
import hashlib import hashlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
import requests import requests
...@@ -193,7 +194,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool): ...@@ -193,7 +194,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
# If there are no meetings, skip to next endpoint # If there are no meetings, skip to next endpoint
if len(meeting) == 0: if len(meeting) == 0:
lines = [ lines = [
"{:^60}".format("bbb there are no meetings currently."), "{:^60}".format("{} there are no meetings currently.").format(endpoint.name[:3]),
"" ""
] ]
# Cut above 60 characters fill empty # Cut above 60 characters fill empty
...@@ -213,8 +214,18 @@ def meetings_twolines(config: Config, watch: int, fancy: bool): ...@@ -213,8 +214,18 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
avg_s = avg_s/60./60. avg_s = avg_s/60./60.
if not fancy: if not fancy:
if config.on_server:
# If on server get load
w = subprocess.run(["w | head -1 | awk '{print $10}' | sed -e 's/,$//'"], shell=True, stdout=subprocess.PIPE)
w = float(w.stdout.decode('utf-8'))
lines = [ lines = [
"{} rec / ses ppl mod vid mic ear".format(endpoint.name), "{} rec / ses ppl mod vid mic ear lod".format(endpoint.name[:3]),
"stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3} {:.1f}"\
.format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners, w)
]
else:
lines = [
"{} rec / ses ppl mod vid mic ear".format(endpoint.name[:3]),
"stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3}"\ "stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3}"\
.format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners) .format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners)
] ]
......
[tool.poetry] [tool.poetry]
name = "bbbmon" name = "bbbmon"
version = "0.1.14" version = "0.1.15"
description = "A small CLI utility to monitor bbb usage" description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"] authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"] maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment