Dashboard
Dashboard holds everything one process shows on its dashboard. Most applications use the module-level functions below, which work on a default dashboard started by dachshund.init().
import dachshund
from dachshund.widgets import TimeSeriesChart
dachshund.init("Ada", description="Code Society's Matrix bot")
with dachshund.row():
dachshund.add(TimeSeriesChart("latency"))
dachshund.emit("latency", value=96)
dachshund.registry
Dashboard
Dashboard(name=None, *, description=None, host=DEFAULT_HOST, port=DEFAULT_PORT, path=DEFAULT_PATH, storage=None, context=None, authorize=None, login_url=None, login=None, timezone='UTC')
Everything one process shows on its dashboard: pages, widgets, actions, and the server drawing them.
Most applications use the module-level API instead, which works on a
default dashboard started by dachshund.init().
Example
dashboard = Dashboard("Ada", description="Code Society's Matrix bot")
with dashboard.row():
dashboard.add(TimeSeriesChart("latency"))
dashboard.start()
Options
name(str) - Shown at the top of every page. Defaults to"Dashboard".description(str) - Shown under the name. Defaults toNone.host(str) - The interface served on. Defaults to"127.0.0.1","0.0.0.0"serves every interface.port(int) - The port served on. Defaults to1212.path(str) - The SQLite file keeping raw events. Defaults to"dachshund.db".storage(Storage) - Where persisted widget state is saved, see Storage. Defaults toNone.context(dict) - Passed asctxto every action and table loader. Defaults to{}.authorize(Callable) - Called with a request for anything that isn'tpublic, sync or async, returning whether to let it in. See Authentication. Defaults toNone, everything is public.login_url(str) - Where a denied page redirects, with the page's URL asnext. Defaults toNone, a denied page asks for a password.login(dict) - Login handlers served by the dashboard, for an application with no web server of its own: aiohttp handlers by name, each at/_auth/<name>, public. A denied page redirects to/_auth/login, so"login"is required. Can't be combined withlogin_url. Defaults toNone.timezone(str) - The IANA zone, like"America/Toronto", where"day","week"and"month"windows and daily buckets start. See Aggregating. Defaults to"UTC".
Source code in dachshund/registry.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
name
instance-attribute
name = name
description
instance-attribute
description = description
started_at
instance-attribute
started_at = datetime.now(tz=UTC)
path
instance-attribute
path = path
widgets
instance-attribute
widgets = {}
actions
instance-attribute
actions = {}
pages
instance-attribute
pages = {}
placements
instance-attribute
placements = {}
events
instance-attribute
events = EventStore(self._connection, self._executor)
storage
instance-attribute
storage = storage
context
instance-attribute
context = dict(context) if context else {}
authorize
instance-attribute
authorize = authorize
timezone
instance-attribute
timezone = ZoneInfo(timezone)
login_url
instance-attribute
login_url = login_url
login
instance-attribute
login = dict(login or {})
queue
instance-attribute
queue = EventQueue()
host_loop
instance-attribute
host_loop = None
url
property
url
The address the dashboard is reachable at.
is_running
property
is_running
Whether the dashboard is being served.
start
start()
Serve the dashboard.
Called from a running event loop, that loop becomes host_loop and async
action handlers run on it.
Source code in dachshund/registry.py
140 141 142 143 144 145 146 147 148 149 150 151 152 | |
stop
stop()
Stop serving the dashboard. start() serves it again.
Source code in dachshund/registry.py
154 155 156 157 158 159 | |
close
close()
Stop serving and close the raw events file.
The dashboard can't be started again. storage is left open.
Source code in dachshund/registry.py
161 162 163 164 165 166 167 | |
action
action(name, *, label=None, confirm=False, public=False)
Register an action, called from a button on the dashboard.
The handler's first parameter must be ctx, it receives the dashboard's
context. See Actions.
Example
@dashboard.action("block_user", label="Block", confirm=True)
def block_user(ctx, user_id: str) -> None: ...
Options
name(str) - The name widgets list inactions. Required.label(str) - The button's text. Defaults toname.confirm(bool) - Asks before running. Defaults toFalse.public(bool) - Runs without the dashboard'sauthorize, see Authentication. Defaults toFalse.
Source code in dachshund/registry.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
emit
emit(source, /, **fields)
Emit an event on the dashboard.
Example
dashboard.emit("latency", value=96)
dashboard.emit("command", name="/ban", issuer="tomcat")
Source code in dachshund/registry.py
209 210 211 212 213 214 215 216 217 218 219 | |
include
include(page)
Put a page, with its tabs, widgets and actions, on the dashboard.
Nothing is added if a name is already taken. Including a page the dashboard already holds does nothing. An included page can't be registered on.
Example
page = Page("errors", title="Errors")
with page.row():
page.add(BarChart("errors", x="code"))
dashboard.include(page)
Source code in dachshund/registry.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
page
page(name, *, title=None, public=None)
Declare a page, or retitle one already declared.
A dashboard that declares no page shows every widget on one "default"
page.
Example
dashboard.page("errors", title="Errors")
Options
title(str) - Shown in the navigation. Defaults toname, underscores as spaces.public(bool) - Shown without the dashboard'sauthorize, see Authentication. Defaults toFalse.
Source code in dachshund/registry.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
row
row(*, page=DEFAULT_PAGE)
Open a row on page, see Page.row.
Example
with dashboard.row():
dashboard.add(Number("errors"))
dashboard.add(TimeSeriesChart("latency"))
Source code in dachshund/registry.py
303 304 305 306 307 308 309 310 311 312 313 314 | |
column
column(*, span=None, page=DEFAULT_PAGE)
Open a column inside a row on page, see Page.column.
Source code in dachshund/registry.py
316 317 318 319 320 | |
add
add(widget, *, page=DEFAULT_PAGE)
Put a widget in the row or column open on page.
See Page.add.
Options
page(str) - The page it goes on. Defaults to"default".
Source code in dachshund/registry.py
322 323 324 325 326 327 328 329 330 331 | |
layout
layout(page=DEFAULT_PAGE)
page's rows, in display order.
Example
dashboard.layout("requests")
# [Row([Column(["errors", "users"], span=4), Column(["latency"])])]
Source code in dachshund/registry.py
333 334 335 336 337 338 339 340 341 342 343 344 345 | |
default
default(*, path=DEFAULT_PATH, storage=None)
The dashboard the module-level API works on, created on first use.
path only applies to that first call. storage applies to the first call
that gives one, which may come later.
Source code in dachshund/registry.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
init
init(name=None, *, description=None, host=DEFAULT_HOST, port=DEFAULT_PORT, path=DEFAULT_PATH, storage=None, context=None, authorize=None, login_url=None, login=None, timezone=None)
Start the dashboard alongside your application.
Widgets, pages and actions registered before the call are kept. Called again while running, it does nothing.
Example
import dachshund
dachshund.init("Ada", description="Code Society's Matrix bot", context={"bot": bot})
Options
Takes the options of Dashboard. context is merged
into the context already set.
Source code in dachshund/registry.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
shutdown
shutdown()
Stop the dashboard started by init(). Its widgets are kept.
Source code in dachshund/registry.py
542 543 544 545 546 547 548 549 | |
include
include(page)
Put a page on the default dashboard.
Takes what Dashboard.include does.
Example
import dachshund
page = dachshund.Page("errors")
dachshund.include(page)
Source code in dachshund/registry.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
action
action(name, **kwargs)
Register an action, on the default dashboard.
Takes what Dashboard.action does.
Example
import dachshund
@dachshund.action("block_user", label="Block", confirm=True)
def block_user(ctx: dachshund.Context, user_id: str) -> None: ...
Source code in dachshund/registry.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
emit
emit(source, /, **fields)
Emit an event, on the default dashboard.
Example
import dachshund
dachshund.emit("latency", value=96)
Source code in dachshund/registry.py
589 590 591 592 593 594 595 596 597 598 599 600 | |
page
page(name, **options)
Declare a page, on the default dashboard.
Takes what Dashboard.page does.
Example
import dachshund
dachshund.page("errors", title="Errors")
Source code in dachshund/registry.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
row
row(**options)
Open a row, on the default dashboard.
Takes what Dashboard.row does.
Example
import dachshund
from dachshund.widgets import Number, TimeSeriesChart
with dachshund.row():
dachshund.add(Number("errors"))
dachshund.add(TimeSeriesChart("latency"))
Source code in dachshund/registry.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
column
column(**options)
Open a column inside a row, on the default dashboard.
Takes what Dashboard.column does.
Source code in dachshund/registry.py
638 639 640 641 642 643 | |
add
add(widget, **options)
Put a widget in the open row or column, on the default dashboard.
Takes what Dashboard.add does.
Example
import dachshund
from dachshund.widgets import Number
with dachshund.row():
dachshund.add(Number("errors"))
Source code in dachshund/registry.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |