Crates.io | tailsrv |
lib.rs | tailsrv |
version | 0.9.0 |
source | src |
created_at | 2022-01-25 08:53:34.91873 |
updated_at | 2024-10-08 06:32:41.569553 |
description | A high-performance file-streaming server |
homepage | |
repository | https://github.com/asayers/tailsrv |
max_upload_size | |
id | 520667 |
size | 53,811 |
tailsrv watches a single file and streams its contents to multiple clients as it grows.
It's like tail -f
, but as a server.
Some implementation details:
If you're interested in how tailsrv compares to Kafka, see here for a comparison.
Let's say you have a machine called webserver
. Pick a port number and
start tailsrv:
$ tailsrv -p 4321 /var/log/nginx/access.log
tailsrv is now watching access.log. You can connect to tailsrv from your laptop and stream the contents of the file:
$ echo "1000" | nc webserver 4321
You will immediately see the contents of access.log, starting from byte 1000, up to the end of the file. The connection remains open, waiting for new data. As soon as nginx writes a line to access.log, it will appear on your laptop. It's more-or-less the same as if you did this:
$ ssh webserver -- tail -f -c+1000 /var/log/nginx/access.log
Rather than using netcat, however, you probably want to connect to tailsrv directly from your log-consuming application.
let sock = TcpStream::connect("webserver:4321")?;
writeln!(sock, "{}", 1000)?;
for line in BufReader::new(sock).lines() {
/* handle log data */
}
The example above is written in rust, but as you can see it's very straightforward: you can to do this from any programming language without the need for a special client library.
The header is just an integer, in ASCII, terminated with a newline. If the integer is positive, it represents the initial byte offset. If the integer is negative, it is interpreted as meaning "counting back from the end of the file". Examples:
0\n
- start from the beginning of the file1000\n
- start from byte 1000-1000\n
- send the last 1000 bytesOnce it receives a header, tailsrv will start sending you file data.
...and that's it as far as the protocol goes. tailsrv will ignore everything you send to it after the newline. When you're done, just close the connection. tailsrv will not terminate the connection unless it is shutting down.
There's no in-band session control: if you want to seek to a different position in the file, close the connection and open a new one.
tailsrv expects a file which will be appended to. If the watched file is deleted or moved, tailsrv will exit. If you modify the middle of the file - well, nothing disasterous will happen, but your clients might get confused.
Enables a dependency on
tracing-journald crate and adds a
new --journald
command-line flag. This will redirect all the tracing output to
the system journald
which gives much richer information than the default
output formatter. Especially useful if you're planning to run tailsrv
as a
systemd service.
Enables a dependency on sd-notify crate.
tailsrv
is going to send a systemd readiness notification once it starts
accepting connections from clients. This is useful combined with a notify
systemd service type.
This software is in the public domain. See UNLICENSE for details.