Skip to content

Commit

Permalink
expand_socket_monitoring: Add state to socket monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoftsm committed Jan 23, 2024
1 parent 0c04722 commit f3b0d9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions includes/netdata_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ enum socket_counters {
NETDATA_KEY_CALLS_TCP_CONNECT_IPV6,
NETDATA_KEY_ERROR_TCP_CONNECT_IPV6,

NETDATA_KEY_CALLS_TCP_SET_STATE,

// Keep this as last and don't skip numbers as it is used as element counter
NETDATA_SOCKET_COUNTER
};
Expand Down
24 changes: 18 additions & 6 deletions kernel/socket_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ static __always_inline void update_socket_table(struct pt_regs* ctx,
__u64 sent,
__u64 received,
__u32 retransmitted,
__u16 protocol)
__u16 protocol,
__u32 state)
{
__u16 family;
struct inet_sock *is = inet_sk((struct sock *)PT_REGS_PARM1(ctx));
Expand Down Expand Up @@ -400,7 +401,7 @@ int netdata_tcp_sendmsg(struct pt_regs* ctx)

libnetdata_update_global(&tbl_global_sock, NETDATA_KEY_BYTES_TCP_SENDMSG, sent);

update_socket_table(ctx, sent, 0, 0, IPPROTO_TCP);
update_socket_table(ctx, sent, 0, 0, IPPROTO_TCP, 0);

return 0;
}
Expand All @@ -410,7 +411,18 @@ int netdata_tcp_retransmit_skb(struct pt_regs* ctx)
{
libnetdata_update_global(&tbl_global_sock, NETDATA_KEY_TCP_RETRANSMIT, 1);

update_socket_table(ctx, 0, 0, 1, IPPROTO_TCP);
update_socket_table(ctx, 0, 0, 1, IPPROTO_TCP, 0);

return 0;
}

SEC("kprobe/tcp_set_state")
int netdata_tcp_set_state(struct pt_regs* ctx)
{
libnetdata_update_global(&tbl_global_sock, NETDATA_KEY_CALLS_TCP_SET_STATE, 1);
int state = PT_REGS_PARM1(ctx);

update_socket_table(ctx, 0, 0, 1, IPPROTO_TCP, state);

return 0;
}
Expand All @@ -430,7 +442,7 @@ int netdata_tcp_cleanup_rbuf(struct pt_regs* ctx)
__u64 received = (__u64) PT_REGS_PARM2(ctx);
libnetdata_update_global(&tbl_global_sock, NETDATA_KEY_BYTES_TCP_CLEANUP_RBUF, received);

update_socket_table(ctx, 0, (__u64)copied, 1, IPPROTO_TCP);
update_socket_table(ctx, 0, (__u64)copied, 1, IPPROTO_TCP, 0);

return 0;
}
Expand Down Expand Up @@ -535,7 +547,7 @@ int trace_udp_ret_recvmsg(struct pt_regs* ctx)

libnetdata_update_global(&tbl_global_sock, NETDATA_KEY_BYTES_UDP_RECVMSG, received);

update_socket_table(ctx, 0, received, 0, IPPROTO_UDP);
update_socket_table(ctx, 0, received, 0, IPPROTO_UDP, 0);

return 0;
}
Expand Down Expand Up @@ -564,7 +576,7 @@ int trace_udp_sendmsg(struct pt_regs* ctx)

libnetdata_update_global(&tbl_global_sock, NETDATA_KEY_BYTES_UDP_SENDMSG, (__u64) sent);

update_socket_table(ctx, sent, 0, 0, IPPROTO_UDP);
update_socket_table(ctx, sent, 0, 0, IPPROTO_UDP, 0);

return 0;
}
Expand Down

0 comments on commit f3b0d9b

Please sign in to comment.