This is a WASM implementation of a metrics Recorder.
Metrics can be transferred in two ways:
- If the WASM app itself wants access to metrics, it can register an event receiver that will be called whenever a metric is recorded.
- Metrics can be send to a remote server. In this case, asn1 is used to encode the metrics into a space efficient binary format. The encoded metrics are then batched and send with POST requests to the specified server URL.
Unlike normal metrics, the metrics that metrics-wasm-exporter exports also carry a timestamp of when the metric was originally recorded.
Example:
use metrics_exporter_wasm::{WasmRecorder, MetricsHttpSender, HttpPostTransport};
use std::time::Duration;
let recorder = WasmRecorder::builder()
.buffer_size(5)
.build()
.expect("failed to create recorder");
// Send metrics in regular intervals to a server using HTTP POST requests.
// Will backoff and retry as needed.
const ENDPOINT: &str = "/receive-metrics";
let guard = MetricsHttpSender::new(HttpPostTransport::new().endpoint(ENDPOINT))
.send_frequency(Duration::from_secs(1))
.start_with_metrics_recorder(&recorder);
// Run forever
guard.disarm();
metrics::set_global_recorder(recorder).expect("failed to set global recorder");
For how to use compression and how to implement a receiving server handler see the examples at hypervideo/metrics-exporter-wasm.