SockStats - file /proc/net/sockstat

The TcpIpStats class implements the parsing of /proc/net/sockstat file, which contains TCP/IP stats of individual layer.

class insights.parsers.sockstat.SockStats(context)[source]

Bases: Parser, dict

Parser for /proc/net/sockstat file.

Sample input is provided in the Examples.

Sample content:

sockets: used 3037
TCP: inuse 1365 orphan 17 tw 2030 alloc 2788 mem 4109
UDP: inuse 6 mem 3
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0

Examples

>>> type(sock_obj)
<class 'insights.parsers.sockstat.SockStats'>
>>> sock_obj.seg_details('tcp')['mem']
'4109'
>>> sock_obj.seg_element_details('tcp', 'mem')
4109
>>> sock_obj.seg_element_details('frag', 'inuse')
0
>>> sock_obj.get('sockets')
{'used': '3037'}
>>> sock_obj.get('sockets').get('used')
'3037'
>>> sock_obj.seg_element_details('tcp', 'abc') is None
True

Resultant Data:

{
    'sockets':
            {
                'used': '3037'
            },
    'tcp':
         {
             'inuse': '1365',
             'orphan': '17',
             'tw': '2030',
             'alloc': '2788',
             'mem': '4109'
         },
    'udp':
         {
             'inuse': '6',
             'mem': '3'
         },
    'udplite':
             {
                'inuse': '0'
             },
    'raw':
         {
            'inuse': '0'
         }
    'frag':
          {
            'inuse': '0',
            'memory': '0'
          }
}
Raises

SkipException -- When contents are empty

parse_content(content)[source]

This method must be implemented by classes based on this class.

seg_details(seg)[source]

Returns (dict): On success, it will return detailed memory consumption done by each segment(TCP/IP layer), on failure it will return None.

seg_element_details(seg, elem)[source]

Returns (int): On success, it will return memory consumption done by each element of the segment(TCP/IP layer), on failure it will return None.

property sock_stats

On On success, it will return detailed memory consumption done by all TCP/IP layer in single data, on failure it will return None

Type

Returns (dict)