What are the meanings of /proc/net/route columns? especially Flags column
The flags column is a combination of the RTF_* flags. You can find them in linux/route.h
For the other fields, have a look at fib_route_seq_show
Understanding cat proc/net/udp
It is the other way round: If your application is faster in producing data than the network adapter is in sending it (which is usually the case), then tx_queue
is > 0.
The tx_queue
is the kernel memory currently being used by outgoing packets which have not been sent. They have not yet been sent, because the kernel and the network adapter (not the application) were not able to send them yet, most likely because they were busy sending other stuff.
It is perfectly normal to have a moderate amount of data waiting in this buffer for a very short time.
An application usually does not need to worry at all about any of these numbers.
What does statistics in /proc/net/protocols mean?
It has some statistics for each protocol and the summary methods of each protocol in Linux.
Unfortunatelly man 5 proc
on RHEL 6.5 does not say anything about /proc/net/protocols
. So I took a look at the source: http://lxr.free-electrons.com/source/net/core/sock.c?v=2.6.29#L2202 and http://lxr.free-electrons.com/source/include/net/sock.h#L924.
2169 static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
2170 {
2171 seq_printf(seq, "%-9s %4u %6d %6d %-3s %6u %-3s %-10s "
2172 "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
2173 proto->name,
2174 proto->obj_size,
2175 sock_prot_inuse_get(seq_file_net(seq), proto),
2176 proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1,
2177 proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
2178 proto->max_header,
2179 proto->slab == NULL ? "no" : "yes",
2180 module_name(proto->owner),
2181 proto_method_implemented(proto->close),
2182 proto_method_implemented(proto->connect),
2183 proto_method_implemented(proto->disconnect),
2184 proto_method_implemented(proto->accept),
2185 proto_method_implemented(proto->ioctl),
2186 proto_method_implemented(proto->init),
2187 proto_method_implemented(proto->destroy),
2188 proto_method_implemented(proto->shutdown),
2189 proto_method_implemented(proto->setsockopt),
2190 proto_method_implemented(proto->getsockopt),
2191 proto_method_implemented(proto->sendmsg),
2192 proto_method_implemented(proto->recvmsg),
2193 proto_method_implemented(proto->sendpage),
2194 proto_method_implemented(proto->bind),
2195 proto_method_implemented(proto->backlog_rcv),
2196 proto_method_implemented(proto->hash),
2197 proto_method_implemented(proto->unhash),
2198 proto_method_implemented(proto->get_port),
2199 proto_method_implemented(proto->enter_memory_pressure));
2200 }
So this is information that each protocol provides about itself.
Lets start with the final sections that have lots of "y" and "n".
2164 static char proto_method_implemented(const void *method)
2165 {
2166 return method == NULL ? 'n' : 'y';
2167 }
So it is just information if a particular method is implemented in protocol or not. For example the "cl" column is for close method. For example since TCP has "y" is the "close" column so TCP protocol implements close() and its proto strcut has a non null pointer in 'close' member:
924 struct proto {
925 void (*close)(struct sock *sk,
926 long timeout);
Some of the first columns in the outpit:
- Protocol name
- Size of protocol specific socket structure
- sockets - how many sockets there are now of that type
- memory - Current allocated memory
- press - memory_pressure - it is a flag that indicates working under memory pressure
and so far, you can look at the source yourself
Useful links:
- http://www.tldp.org/LDP/lkmpg/2.4/html/c722.htm
- http://lxr.free-electrons.com/source/net/core/sock.c?v=2.6.29#L2168
- http://lxr.free-electrons.com/source/include/linux/net.h#L128
- http://linuxwarrior.wordpress.com/2008/12/02/add-a-new-protocol-to-linux-kernel/
Parse txBytes,rxBytes,rxPackets,txPackets from /proc/net/dev using c
From your code sample, I wrote the following:
#include <stdio.h>
int main() {
FILE *fp = fopen("/proc/net/dev", "r");
char buf[200], ifname[20];
unsigned long int r_bytes, t_bytes, r_packets, t_packets;
// skip first two lines
for (int i = 0; i < 2; i++) {
fgets(buf, 200, fp);
}
while (fgets(buf, 200, fp)) {
sscanf(buf, "%[^:]: %lu %lu %*lu %*lu %*lu %*lu %*lu %*lu %lu %lu",
ifname, &r_bytes, &r_packets, &t_bytes, &t_packets);
printf("%s: rbytes: %lu rpackets: %lu tbytes: %lu tpackets: %lu\n",
ifname, r_bytes, r_packets, t_bytes, t_packets);
}
fclose(fp);
return 0;
}
This outputs:
lo: rbytes: 22975300 rpackets: 459506 tbytes: 22975300 tpackets: 459506
wlp2s0: rbytes: 2419131107 rpackets: 1820658 tbytes: 109438292 tpackets: 877583
eno1: rbytes: 15984078 rpackets: 55391 tbytes: 3078636 tpackets: 13019
Hope that helps you :)
How can I parse the output of /proc/net/dev into key:value pairs per interface using Python?
this is pretty formatted input and you can easily get columns and data list by splitting each line, and then create a dict of of it.
here is a simple script without regex
lines = open("/proc/net/dev", "r").readlines()
columnLine = lines[1]
_, receiveCols , transmitCols = columnLine.split("|")
receiveCols = map(lambda a:"recv_"+a, receiveCols.split())
transmitCols = map(lambda a:"trans_"+a, transmitCols.split())
cols = receiveCols+transmitCols
faces = {}
for line in lines[2:]:
if line.find(":") < 0: continue
face, data = line.split(":")
faceData = dict(zip(cols, data.split()))
faces[face] = faceData
import pprint
pprint.pprint(faces)
it outputs
{' lo': {'recv_bytes': '7056295',
'recv_compressed': '0',
'recv_drop': '0',
'recv_errs': '0',
'recv_fifo': '0',
'recv_frame': '0',
'recv_multicast': '0',
'recv_packets': '12148',
'trans_bytes': '7056295',
'trans_carrier': '0',
'trans_colls': '0',
'trans_compressed': '0',
'trans_drop': '0',
'trans_errs': '0',
'trans_fifo': '0',
'trans_packets': '12148'},
' eth0': {'recv_bytes': '34084530',
'recv_compressed': '0',
'recv_drop': '0',
'recv_errs': '0',
'recv_fifo': '0',
'recv_frame': '0',
'recv_multicast': '0',
'recv_packets': '30599',
'trans_bytes': '6170441',
'trans_carrier': '0',
'trans_colls': '0',
'trans_compressed': '0',
'trans_drop': '0',
'trans_errs': '0',
'trans_fifo': '0',
'trans_packets': '32377'}}
Related Topics
How to Configure Bash to Handle Crlf Shell Scripts
Identifying Which Linux System Library Contains a Function
How to Fix "Go Not Root Owned"
Why Does the Wc Command Count One More Character Than Expected
Is Stack Memory Contiguous Physically in Linux
Linux. Sol_Netlink Not Defined
Remove File Coding Mark But Preserve Its Coding
Using Ld_Preload Mixed 64Bit/32Bit Environment in Linux
How to Count the Number of Occurrences of a String in an Entire File
How to Use Global Arrays in Bash
Cmake Auto Header File Dependency
Specify the from User When Sending Email Using the Mail Command
Permission Denied When Trying to Append a File to a Root Owned File with Sudo
Matlab Execute Script from Linux Command Line
How to Read Ring Buffer Within Linux Kernel Space
Expand a Possible Relative Path in Bash