|
9 | 9 | from bbblb.services.bbb import BBBHelper |
10 | 10 | from bbblb.services.db import DBContext |
11 | 11 |
|
12 | | -from . import main, async_command |
| 12 | +from . import Table, main, async_command |
13 | 13 |
|
14 | 14 |
|
15 | 15 | @main.group() |
@@ -177,26 +177,39 @@ async def _end_meeting(obj: ServiceRegistry, meeting: model.Meeting): |
177 | 177 |
|
178 | 178 |
|
179 | 179 | @server.command() |
| 180 | +@Table.option |
180 | 181 | @async_command() |
181 | | -async def list(obj: ServiceRegistry): |
| 182 | +async def list(obj: ServiceRegistry, table_format: str): |
182 | 183 | """List all servers with their secrets.""" |
183 | 184 | db = await obj.use(DBContext) |
184 | 185 |
|
| 186 | + tbl = Table() |
185 | 187 | async with db.session() as session: |
186 | 188 | stmt = model.Server.select().order_by(model.Server.domain) |
187 | 189 | for server in (await session.execute(stmt)).scalars(): |
188 | | - out = f"{server.domain} {server.secret}" |
189 | | - click.echo(out) |
| 190 | + tbl.row(server=server.domain, secret=server.secret) |
| 191 | + tbl.print(format=table_format) |
190 | 192 |
|
191 | 193 |
|
192 | 194 | @server.command() |
| 195 | +@Table.option |
193 | 196 | @async_command() |
194 | | -async def stats(obj: ServiceRegistry): |
| 197 | +async def stats(obj: ServiceRegistry, table_format): |
195 | 198 | """Show server statistics (state, health, load).""" |
196 | 199 | db = await obj.use(DBContext) |
197 | 200 |
|
| 201 | + tbl = Table() |
198 | 202 | async with db.session() as session: |
199 | 203 | stmt = model.Server.select().order_by(model.Server.domain) |
200 | 204 | for server in (await session.execute(stmt)).scalars(): |
201 | | - out = f"{server.domain} enabled={server.enabled} health={server.health.name.lower()} load={server.load:.1f}" |
202 | | - click.echo(out) |
| 205 | + tbl.row( |
| 206 | + server=server.domain, |
| 207 | + enabled=server.enabled, |
| 208 | + state=server.health.name.lower(), |
| 209 | + meetings=server.stats.get("meetings", 0), |
| 210 | + users=server.stats.get("users", 0), |
| 211 | + voice=server.stats.get("voice", 0), |
| 212 | + video=server.stats.get("video", 0), |
| 213 | + load=server.load, |
| 214 | + ) |
| 215 | + tbl.print(format=table_format) |
0 commit comments