Monitoring
With the monitoring feature, the engine serves its event stream over gRPC. Point the Crankshaft console at it to watch tasks in a terminal, or write your own client.
Turn it on
The feature needs a protobuf compiler at build time. Follow the protobuf installation guide first (on macOS, brew install protobuf).
cargo add crankshaft --features monitoringThen create the engine with an address to listen on.
use crankshaft::Engine;
let engine = Engine::new_with_monitoring("127.0.0.1:8080".parse()?).await;Everything else is the same as Engine::default(). engine.shutdown() stops the server.
The monitor has no authentication
Anyone who can reach the address can see task names and cancel tasks. Bind to 127.0.0.1 unless the network in front of it is trusted.
The gRPC service
The service is crankshaft.monitor.Monitor, defined in crankshaft-monitor/src/proto/monitor.proto.
| Method | Returns | Use it to |
|---|---|---|
SubscribeEvents | A stream of Event | Follow the event stream live. Each message has a timestamp. |
GetServiceState | Every task and its events so far | Catch up when a client connects mid-run. |
CancelTask(id) | Nothing | Cancel a task by its id. |
The console
crankshaft-console is a terminal UI in this repository. It connects to http://localhost:8080, shows every task and its latest state, and lets you cancel them.
# In one terminal, run an engine with the monitor on.
cargo run --release --bin docker-monitored
# In another, from the repository root, start the console.
cargo run --release -p crankshaft-console| Key | Action |
|---|---|
j or ↓ | Next task |
k or ↑ | Previous task |
t | Tasks view |
c | Cancel the selected task, then y to confirm or n / Esc to back out |
Ctrl+c or Ctrl+d | Quit |
The console always connects to port 8080 on localhost, so start the engine there.
Reference
crankshaft-monitoron docs.rs