filetrace.v1.FiletraceService, that reports the agent’s status, lists the file transfers it holds and streams transfer activity as it is recorded. This page shows how to turn the API on, who may connect, how to call it with grpcurl and buf curl, how filters and streams behave, and how to generate a client. The gRPC API reference describes every message and field.
Turn on the API
1
Enable the API in the configuration file
Add the
[grpc] section to /etc/filetrace/config.toml:2
Restart the agent
serving the gRPC API on unix:/run/filetrace/api.sock.Listen address and access
listen is either unix: followed by a socket path, or a numeric address and port. Who may connect depends on the form:
The agent creates the Unix socket with mode
0600, rejects any other user that connects (and logs rejected an API client that is neither root nor the agent's user), and removes the socket file when it stops. With an address and port, the agent logs a warning when it starts that the API is open to whoever can connect. localhost stands for 127.0.0.1; no other host name is resolved.
Under the packaged systemd service the file system is read-only to the agent except for its runtime directory /run/filetrace, and /tmp is private to the service, so keep the socket in /run/filetrace.
Methods
The schema
The server speaks gRPC over HTTP/2 without TLS and without server reflection, so a client names the schema itself. The service is defined inproto/filetrace/v1/filetrace.proto in the Filetrace repository. The examples below run from a clone of the repository, where proto is the import path:
Call the API
The examples usesudo because the default socket admits only root and the agent’s user.
Status of the agent:
/data, as it happens, with buf curl:
"METHOD_SENDFILE", 64-bit numbers appear as strings, and fields at their zero value are left out of the output.
Filters
ListTransfers and WatchTransfers take a filter. Every field that is set narrows the result; a field left at zero or empty does not filter.
A filter that cannot be applied, such as a
remote that is neither an address nor a network, or a port above 65535, ends the call with INVALID_ARGUMENT and a message that names the field. Filters describes the matching rules the command-line options share with the API.
ListTransfers
ListTransfers returns the transfers the agent holds, each covering its whole observed lifetime, most recently active first. The request takes, besides the filter:
observed_since_unix_nano, the time from which the agent has observed (nothing earlier is known to it), and lost_events, the events the agent has lost so far. Above zero, the list may be incomplete, and each transfer that was in progress while events were lost has incomplete set.
A response that would exceed 4 MB fails with RESOURCE_EXHAUSTED and the message The result is too large. Narrow it with a filter or a limit.
WatchTransfers
WatchTransfers streams transfer activity from the moment the call starts; it sends nothing from before. Each message carries one TransferEvent: the file bytes attributed to one socket during one collection interval of the agent, the same records that filetrace events --type file_transfer prints.
- The stream runs until the caller cancels it or the agent stops.
confidenceis that of the whole association so far, andCONFIDENCE_UNSPECIFIEDwhile the association is still below the reporting thresholds. Aconfidencefilter selects only events that have that level.- A watcher that reads too slowly is not sent what it cannot take: once more than 1 MB is waiting unread, further events are left out. The next message the watcher receives carries
missed, the number of events left out before it. - The agent serves at most 16 watchers at a time. Another
WatchTransferscall fails withRESOURCE_EXHAUSTEDandToo many watchers.
Errors and limits
The server serves up to 16 connections at a time, with up to 32 concurrent calls on each. A request whose content type is not
application/grpc is answered with HTTP status 415.
Generate a client
The schema is a plain proto3 file, so any protobuf and gRPC toolchain can generate a client from it. With Buf, copyfiletrace/v1/filetrace.proto into a proto directory of your project, keeping its path, and add a buf.gen.yaml that names the plugins of your language; for Python, for example:
listen, without TLS.