Skip to content

examples: Add unix-accept-latency#634

Merged
bobrik merged 1 commit intocloudflare:masterfrom
jsitnicki:example-unix-accept-latency
Apr 30, 2026
Merged

examples: Add unix-accept-latency#634
bobrik merged 1 commit intocloudflare:masterfrom
jsitnicki:example-unix-accept-latency

Conversation

@jsitnicki
Copy link
Copy Markdown
Contributor

ebpf_exporter ships examples covering TCP accept queue latency but no equivalent for AF_UNIX. Listener-side accept queue stalls on busy UNIX stream sockets are invisible to the existing examples.

Add an example that measures the time a connection spends on the listener's accept queue and exports it as an exp2 histogram, unix_accept_latency_seconds, labeled by listener path. Track three common server sockets out of the box: /run/dbus/system_bus_socket, /run/systemd/journal/stdout, and /var/run/mysqld/mysqld.sock. Operators are expected to edit the path list to match the host.

Attach an fentry on security_unix_stream_connect() to stamp the server-side newsk in BPF_MAP_TYPE_SK_STORAGE when the listener's unix_sock->addr->name[0].sun_path matches one of the monitored entries. On unix_accept() fexit, look up the stamp on the accepted sk, compute the delta, and feed it into the histogram. Storing the matched path index alongside the timestamp avoids re-walking unix_sock->addr on the accept side; sk_storage presence already proves the socket is monitored.

Latencies are bucketed in milliseconds from 1 ms to 1024 ms. Samples above the top edge are clamped into the last bucket.

@bobrik
Copy link
Copy Markdown
Contributor

bobrik commented Apr 28, 2026

CI is unhappy, presumably because of kernel version mismatch. Can you take a look?

@bobrik
Copy link
Copy Markdown
Contributor

bobrik commented Apr 29, 2026

It was actually #635, so you probably just need to rebase.

ebpf_exporter ships examples covering TCP accept queue latency but no
equivalent for AF_UNIX. Listener-side accept queue stalls on busy UNIX
stream sockets are invisible to the existing examples.

Add an example that measures the time a connection spends on the
listener's accept queue and exports it as an exp2 histogram,
unix_accept_latency_seconds, labeled by listener path. Track three
common server sockets out of the box: /run/dbus/system_bus_socket,
/run/systemd/journal/stdout, and /var/run/mysqld/mysqld.sock. Operators
are expected to edit the path list to match the host.

Attach an fentry on security_unix_stream_connect() to stamp the
server-side newsk in BPF_MAP_TYPE_SK_STORAGE when the listener's
unix_sock->addr->name[0].sun_path matches one of the monitored entries.
On unix_accept() fexit, look up the stamp on the accepted sk, compute
the delta, and feed it into the histogram. Storing the matched path
index alongside the timestamp avoids re-walking unix_sock->addr on the
accept side; sk_storage presence already proves the socket is monitored.

Latencies are bucketed in milliseconds from 1 ms to 1024 ms. Samples
above the top edge are clamped into the last bucket.
@jsitnicki jsitnicki force-pushed the example-unix-accept-latency branch from 3c59db6 to 4157073 Compare April 29, 2026 08:07
care44cubs-max

This comment was marked as spam.

@bobrik bobrik merged commit 8ad7b10 into cloudflare:master Apr 30, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants