Skip to content

Dashboard

dashboard_state_verification

dashboard_state_verification(ctx)

Perform cli commands verification (state checking).

Parameters:

Name Type Description Default
ctx Context

Typer (Click like) special internal object that holds state relevant for the script execution at every single level.

required
Source code in src/trecover/app/cli/dashboard.py
@cli.callback(invoke_without_command=True)
def dashboard_state_verification(ctx: Context) -> None:
    """
    Perform cli commands verification (state checking).

    Parameters
    ----------
    ctx : Context
        Typer (Click like) special internal object that holds state relevant
        for the script execution at every single level.

    """

    from trecover.config import log

    if var.DASHBOARD_PID.exists():
        if ctx.invoked_subcommand in ('start', None):
            log.project_console.print(':rocket: The dashboard service is already started', style='bright_blue')
            ctx.exit(0)

    elif ctx.invoked_subcommand is None:
        dashboard_start(host=var.STREAMLIT_HOST, port=var.STREAMLIT_PORT, loglevel=var.LogLevel.info, attach=False,
                        no_daemon=False)

    elif ctx.invoked_subcommand != 'start':
        log.project_console.print('The dashboard service is not started', style='yellow')
        ctx.exit(1)

dashboard_start

dashboard_start(
    host=Option(
        var.STREAMLIT_HOST,
        "--host",
        "-h",
        help="Bind socket to this host.",
    ),
    port=Option(
        var.STREAMLIT_PORT,
        "--port",
        "-p",
        help="Bind socket to this port.",
    ),
    loglevel=Option(
        var.LogLevel.info,
        "--loglevel",
        "-l",
        help="Logging level.",
    ),
    attach=Option(
        False,
        "--attach",
        "-a",
        is_flag=True,
        help="Attach output and error streams",
    ),
    no_daemon=Option(
        False,
        "--no-daemon",
        is_flag=True,
        help="Do not run as a daemon process",
    ),
)

Start dashboard service.

Parameters:

Name Type Description Default
host str, default

The address where the server will listen for client and browser connections. Use this if you want to bind the server to a specific address. If set, the server will only be accessible from this address, and not from any aliases (like localhost).

Option(var.STREAMLIT_HOST, '--host', '-h', help='Bind socket to this host.')
port int, default

The port where the server will listen for browser connections.

Option(var.STREAMLIT_PORT, '--port', '-p', help='Bind socket to this port.')
loglevel var.LogLevel

Level of logging.

'debug'
attach bool, default

Attach output and error streams.

Option(False, '--attach', '-a', is_flag=True, help='Attach output and error streams')
no_daemon bool, default

Do not run as a daemon process.

Option(False, '--no-daemon', is_flag=True, help='Do not run as a daemon process')
Source code in src/trecover/app/cli/dashboard.py
@cli.command(name='start', help='Start service')
def dashboard_start(host: str = Option(var.STREAMLIT_HOST, '--host', '-h', help='Bind socket to this host.'),
                    port: int = Option(var.STREAMLIT_PORT, '--port', '-p', help='Bind socket to this port.'),
                    loglevel: var.LogLevel = Option(var.LogLevel.info, '--loglevel', '-l', help='Logging level.'),
                    attach: bool = Option(False, '--attach', '-a', is_flag=True,
                                          help='Attach output and error streams'),
                    no_daemon: bool = Option(False, '--no-daemon', is_flag=True, help='Do not run as a daemon process')
                    ) -> None:
    """
    Start dashboard service.

    Parameters
    ----------
    host : str, default=ENV(STREAMLIT_HOST) or 'localhost'
        The address where the server will listen for client and browser connections.
        Use this if you want to bind the server to a specific address. If set, the server
        will only be accessible from this address, and not from any aliases (like localhost).
    port : int, default=ENV(STREAMLIT_PORT) or 8000
        The port where the server will listen for browser connections.
    loglevel : {'debug', 'info', 'warning', 'error', 'critical'}, default='info'
        Level of logging.
    attach : bool, default=False
        Attach output and error streams.
    no_daemon : bool, default=False
        Do not run as a daemon process.

    """

    from subprocess import run

    from trecover.config import log
    from trecover.app import dashboard
    from trecover.utils.cli import start_service

    argv = ['streamlit',
            'run', dashboard.__file__,
            '--server.address', host,
            '--server.port', str(port),
            '--logger.level', loglevel,
            '--global.suppressDeprecationWarnings', 'True',
            '--theme.backgroundColor', '#FFFFFF',
            '--theme.secondaryBackgroundColor', '#EAEAF2',
            '--theme.primaryColor', '#FF8068',
            '--theme.textColor', '#48466D'
            ]

    if no_daemon:
        run(argv)
    else:
        start_service(argv, name='dashboard', logfile=log.DASHBOARD_LOG, pidfile=var.DASHBOARD_PID)

        if attach:
            dashboard_attach(live=False)

dashboard_stop

dashboard_stop()

Stop dashboard service.

Source code in src/trecover/app/cli/dashboard.py
@cli.command(name='stop', help='Stop service')
def dashboard_stop() -> None:
    """ Stop dashboard service. """

    from trecover.utils.cli import stop_service

    stop_service(name='dashboard', pidfile=var.DASHBOARD_PID, logfile=log.DASHBOARD_LOG)

dashboard_status

dashboard_status()

Display dashboard service status.

Source code in src/trecover/app/cli/dashboard.py
@cli.command(name='status', help='Display service status')
def dashboard_status() -> None:
    """ Display dashboard service status. """

    from trecover.utils.cli import check_service

    check_service(name='dashboard', pidfile=var.DASHBOARD_PID)

dashboard_attach

dashboard_attach(
    live=Option(
        False,
        "--live",
        "-l",
        is_flag=True,
        help="Stream only fresh log records",
    )
)

Attach local output stream to a running dashboard service.

Parameters:

Name Type Description Default
live bool, Default

Stream only fresh log records

Option(False, '--live', '-l', is_flag=True, help='Stream only fresh log records')
Source code in src/trecover/app/cli/dashboard.py
@cli.command(name='attach', help='Attach local output stream to a service')
def dashboard_attach(live: bool = Option(False, '--live', '-l', is_flag=True,
                                         help='Stream only fresh log records')
                     ) -> None:
    """
    Attach local output stream to a running dashboard service.

    Parameters
    ----------
    live : bool, Default=False
        Stream only fresh log records

    """

    from trecover.config import log
    from trecover.utils.cli import stream

    with log.project_console.screen():
        for record in stream(('dashboard', log.DASHBOARD_LOG), live=live):
            log.project_console.print(record)

    log.project_console.clear()