Is it possible to create and show plotters graphs directly via Axum (without WASM)?

I have created a tool to obtain statistics from node_exporter from multiple sources and show these on the CLI like the linux sar and iostat tools do. The tool optionally can create graphs via the plotters crate.

I am trying to get my head around if I can also make the tool start a webserver (possibly via the Axum crate), and then allow the graphs to be created during data collection of the tool. If so, I would like to know how via a basic example.

The idea is to add a switch to start a a webserver as a thread along with the data collection, so that a browser can be used to see a graph of the data collected as it's being collected.

Why don't you want to serve a WASM frontend from your Axum server? As far as I understood your description, you want "real-time" plotting of the data that is being collected by your program in the background. So there must be some sort of frontend (JS or WASM—potentially using plotters), that will handle the rendering, receiving the data via HTTP or WebSockets from your Axum server, as it becomes available.

1 Like

So far, I got the impression that for WASM, the binary needs to specifically compiled as WASM. I am not that familiar with WASM to make a good judgement, hence my ask.

The basic need for the tool is that it can easily extract the data from the node_exporter endpoints as simple as possible, which for me is an executable compiled that can be run on the CLI. In the same sense of simplicity, the tool will be running ,and therefore, if possible, simply should spawn a thread to serve the performance graph.

It would be great if the website can update the graphs in realtime, but (currently) I would be happy if these are served as static images too, it needs to be as simple as possible, it's not too much of a hassle to press reload to get a newer version.

In case anyone is interested, or want to get an impression: here's the project: GitHub - FritsHoogland/dsar: dsar is a tool to collect statistics via prometheus endpoints for multiple machines

That's correct. You'd need to serve the compiled WASM file from your server to the browser. Depending on how you intent to distribute your application, you could pre-compile the WASM file and package it alongside your binary.

Are you already querying Prometheus from a tokio runtime? In that case, you can simply spawn your webserver as just another tokio task.

Hmm, you could spawn a task or thread that uses plotters with a BitMapBackend updating a static image in an interval you deem sensible. You could then use Axum to serve that file (along with maybe an index.html file where you embed the image) to your browser.

As a side note I recently discovered a cool way to automatically open a browser tab (in the user's preferred browser) to your axum server on linux, via the xdg-open command:


where url is the URL you want to serve, i.e. localhost:8000/performance_graph.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.