#metrics #telemetry #tcp

metrics-exporter-tcp

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

14 unstable releases (6 breaking)

0.7.0 Jul 21, 2022
0.6.0 Jan 15, 2022
0.5.1 Sep 16, 2021
0.5.0 Jul 15, 2021
0.1.0-alpha.2 Jul 27, 2020

#14 in #telemetry

Download history 626/week @ 2022-08-02 549/week @ 2022-08-09 720/week @ 2022-08-16 404/week @ 2022-08-23 722/week @ 2022-08-30 436/week @ 2022-09-06 621/week @ 2022-09-13 581/week @ 2022-09-20 632/week @ 2022-09-27 326/week @ 2022-10-04 366/week @ 2022-10-11 582/week @ 2022-10-18 513/week @ 2022-10-25 320/week @ 2022-11-01 535/week @ 2022-11-08 261/week @ 2022-11-15

1,823 downloads per month

MIT license

120KB
1.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].

# use metrics_exporter_tcp::TcpBuilder;
# fn direct() {
// 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

~2.6–8.5MB
~141K SLoC