Skip to main content

DashboardServer

Struct DashboardServer 

Source
pub struct DashboardServer { /* private fields */ }
Expand description

A minimal HTTP server that serves the dashboard HTML and an SSE endpoint.

The server uses a shared Arc<Mutex<DashboardMetrics>> so that an external thread can update the metrics while the server pushes them to connected SSE clients.

Implementations§

Source§

impl DashboardServer

Source

pub fn new( config: DashboardConfig, metrics: Arc<Mutex<DashboardMetrics>>, ) -> Self

Create a new server with the given config and a shared metrics handle.

Source

pub fn metrics_handle(&self) -> Arc<Mutex<DashboardMetrics>> ⓘ

Return a clone of the shared metrics handle so callers can update it.

Source

pub fn run(&self) -> Result<()>

Start listening. This blocks the calling thread.

Each accepted connection is served on its own thread, so a long-lived /events SSE stream (or a half-open client) can never block the accept loop. See Self::run_on for the routing table and the history of issue #36.

Source

pub fn run_on(&self, listener: TcpListener) -> Result<()>

Serve on an already-bound listener. This blocks the calling thread.

Split out from Self::run so tests can bind port 0 and learn the real port via listener.local_addr() before starting the server.

For each incoming connection the server reads the HTTP request line, then either:

  • GET / → responds with the full HTML page
  • GET /events → responds with an SSE stream (pushes metrics JSON every 5 seconds until the client disconnects)
  • anything else → 404

Concurrency model: one thread per connection. The previous design served every connection inline on the accept thread, which meant a single connected SSE client parked the whole server in its push loop, and an interrupted SSE client parked it for up to two 5-second ticks (the first write after a peer FIN succeeds into the send buffer; only the next one observes the RST — and TcpStream::flush is a no-op, so it detects nothing). Meanwhile every other connection sat unaccepted in the kernel backlog showing CLOSE_WAIT, and the dashboard page’s EventSource auto-reconnect turned the pile-up into a permanent hang (issue #36).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.