[uWSGI] gather TCP socket metrics with TCP_INFO?

Roberto De Ioris roberto at unbit.it
Tue Oct 8 11:45:44 CEST 2013


> Hi guys,
>
> I am recently interested in socket programming. I found this gem in kernel
> socket:
>
> http://lxr.free-electrons.com/source/include/uapi/linux/tcp.h#L148
>
> Example code like this:
>
> import socket, struct
> s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect(('www.google.com', 80))
> s.send('GET / HTTP/1.1\r\n\r\n')
> s.recv(1024)
> a=struct.unpack("B"*7+"I"*24, s.getsockopt(socket.SOL_TCP,
> socket.TCP_INFO,
> 104))
> b=['tcpi_state', 'tcpi_ca_state', 'tcpi_retransmits', 'tcpi_probes',
> 'tcpi_backoff', 'tcpi_options', 'tcpi_snd_wscale+tcpi_rcv_wscale',
> 'tcpi_rto', 'tcpi_ato', 'tcpi_snd_mss', 'tcpi_rcv_mss', 'tcpi_unacked',
> 'tcpi_sacked', 'tcpi_lost', 'tcpi_retrans', 'tcpi_fackets',
> 'tcpi_last_data_sent', 'tcpi_last_ack_sent   ', 'tcpi_last_data_recv',
> 'tcpi_last_ack_recv', 'tcpi_pmtu', 'tcpi_rcv_ssthresh', 'tcpi_rtt',
> 'tcpi_rttvar', 'tcpi_snd_ssthresh', 'tcpi_snd_cwnd', 'tcpi_advmss',
> 'tcpi_reordering', 'tcpi_rcv_rtt', 'tcpi_rcv_space',
> 'tcpi_total_retrans',]
> print '\r\n'.join('%s: %s' % x for x in zip(b, a))
>
>
> I find metrics like tcpi_lost, tcpi_retrans, tcpi_rtt, tcpi_rcv_rtt
> potentially very useful to monitor server performance. It would be awesome
> if uWSGI consider adding some of the info to the stats server. (or some
> where better)
>
> What do you guys think?



Hi, TCP_INFO is currently used to get the size of the listen queue:

https://github.com/unbit/uwsgi/blob/master/core/master.c#L180

i do not know which (other) kind of infos could be useful.

We are about to release 1.9.18, soon after we will finally merge the
metric subsystem so if you want to add metrics it should be pretty easy
(you will need to write in c obviously but there will be no more than a
dozens of lines)

-- 
Roberto De Ioris
http://unbit.it


More information about the uWSGI mailing list