Aggregated Widget
AggregatedWidget is the base of a widget showing one number of its source, the latest or an aggregate over a window, like Number. See Aggregating.
dachshund.widgets.aggregate.AggregatedWidget
dataclass
AggregatedWidget(name, *, source='', title=None, actions=list(), action_args=dict(), persist=False, y='value', aggregate='last', over=None)
Bases: PersistableWidget
A widget showing one number of its source: the latest, or an aggregate over a window.
Subclass it and write render_value(), which turns the number into the
payload the renderer draws. See Aggregating.
Example
@dataclass
class Gauge(AggregatedWidget):
type: ClassVar[str] = "gauge"
script: ClassVar[Path] = Path(__file__).parent / "gauge.js"
def render_value(self, value):
return {"value": value}
Gauge("latency", aggregate="average", over=timedelta(hours=1))
Options
y(str) - The field read. Defaults to"value".aggregate(str) -"last"for the latest number, or"count","sum","average","min","max"or"distinct"overover. Defaults to"last".over(timedelta | str) - The window: atimedeltaback from now, or the current"day","week"or"month"in the dashboard'stimezone. Defaults toNone, everything stored. Not for"last".persist(bool) - Keeps the latest number across restarts, for"last"only: windows are rebuilt from stored events. Needs the dashboard'sstorage. Defaults toFalse.
y
class-attribute
instance-attribute
y = 'value'
aggregate
class-attribute
instance-attribute
aggregate = 'last'
over
class-attribute
instance-attribute
over = None
kept
class-attribute
instance-attribute
kept = field(default=None, init=False, repr=False, compare=False)
window
window()
aggregate of y over over, None for "last".
Source code in dachshund/widgets/aggregate.py
146 147 148 149 150 151 | |
render_value
render_value(value)
The payload drawn for value, None before there's one to show.
Source code in dachshund/widgets/aggregate.py
153 154 155 | |
render
render(events)
The latest number of y, or None before anything arrives.
A persisting widget reads its own kept reading instead, since that covers more than whatever events are still around to re-read.
Source code in dachshund/widgets/aggregate.py
157 158 159 160 161 162 163 164 165 166 167 168 | |
render_buckets
render_buckets(buckets)
The aggregate over the window's buckets.
Source code in dachshund/widgets/aggregate.py
170 171 172 | |
accumulate
accumulate(event)
Keep the latest reading of y.
Source code in dachshund/widgets/aggregate.py
174 175 176 177 178 179 180 181 | |
snapshot
snapshot()
The kept reading.
Source code in dachshund/widgets/aggregate.py
183 184 185 | |
restore
restore(data)
Pick up where the last persisted snapshot left off.
Source code in dachshund/widgets/aggregate.py
187 188 189 | |