#metrics-exporter #metrics #tcp #telemetry

metrics-exporter-tcp

A metrics-compatible exporter that outputs metrics to clients over TCP

18 releases (10 breaking)

0.11.0 Oct 12, 2024
0.10.0 May 27, 2024
0.9.0 Dec 24, 2023
0.8.0 Apr 16, 2023
0.1.0-alpha.2 Jul 27, 2020

#656 in Debugging

Download history 363/week @ 2024-07-29 551/week @ 2024-08-05 451/week @ 2024-08-12 651/week @ 2024-08-19 506/week @ 2024-08-26 292/week @ 2024-09-02 508/week @ 2024-09-09 588/week @ 2024-09-16 682/week @ 2024-09-23 417/week @ 2024-09-30 520/week @ 2024-10-07 328/week @ 2024-10-14 443/week @ 2024-10-21 242/week @ 2024-10-28 388/week @ 2024-11-04 523/week @ 2024-11-11

1,601 downloads per month
Used in dydx

MIT license

150KB
2.5K SLoC

metrics-exporter-tcp

conduct-badge downloads-badge release-badge docs-badge license-badge

metrics-exporter-tcp is a metrics-compatible exporter that outputs metrics to clients over TCP.

code of conduct

NOTE: All conversations and contributions to this project shall adhere to the Code of Conduct.


lib.rs:

A metrics-compatible exporter that outputs metrics to clients over TCP.

This exporter creates a TCP server, that when connected to, will stream individual metrics to the client using a Protocol Buffers encoding.

Backpressure

The exporter has configurable buffering, which allows users to trade off how many metrics they want to be queued up at any given time. This buffer limit applies both to incoming metrics, as well as the individual buffers for each connected client.

By default, the buffer limit is set at 1024 metrics. When the incoming buffer -- metrics being fed to the exported -- is full, metrics will be dropped. If a client's buffer is full, potentially due to slow network conditions or slow processing, then messages in the client's buffer will be dropped in FIFO order in order to allow the exporter to continue fanning out metrics to clients.

If no buffer limit is set, then te exporter will ingest and enqueue as many metrics as possible, potentially up until the point of memory exhaustion. A buffer limit is advised for this reason, even if it is many multiples of the default.

Encoding

Metrics are encoded using Protocol Buffers. The protocol file can be found in the repository at proto/event.proto.

Usage

The TCP exporter can be constructed by creating a TcpBuilder, configuring it as needed, and calling TcpBuilder::install to both spawn the TCP server as well as install the exporter globally.

If necessary, the recorder itself can be returned so that it can be composed separately, while still installing the TCP server itself, by calling TcpBuilder::build.

// Install the exporter directly:
let builder = TcpBuilder::new();
builder.install().expect("failed to install TCP exporter");

// Or install the TCP server and get the recorder:
let builder = TcpBuilder::new();
let recorder = builder.build().expect("failed to install TCP exporter");

Dependencies

~3–11MB
~121K SLoC