#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

#692 in Debugging

Download history 497/week @ 2024-08-23 375/week @ 2024-08-30 468/week @ 2024-09-06 544/week @ 2024-09-13 655/week @ 2024-09-20 496/week @ 2024-09-27 411/week @ 2024-10-04 402/week @ 2024-10-11 445/week @ 2024-10-18 283/week @ 2024-10-25 383/week @ 2024-11-01 469/week @ 2024-11-08 564/week @ 2024-11-15 411/week @ 2024-11-22 497/week @ 2024-11-29 475/week @ 2024-12-06

2,082 downloads per month
Used in dydx

MIT license

155KB
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–12MB
~124K SLoC