Capture nethogs output in log file
You can use this command to capture output:
nethogs -d 5 | sed 's/[^[:print:][:cntrl:]]//g' > output.txt
redirecting console output to a file in unix
Possibly the large amount of output is "permission denied" type messages. Redirect errors to the log file by appending 2>&1
.
2 is the stream number for stderr (error messages), 1 is represents the stdout stream (the standard non-error output stream).
find . -iname "MyLog.log" > ./myfile/storeLog.log 2>&1
redirecting console output to a file in unix
Possibly the large amount of output is "permission denied" type messages. Redirect errors to the log file by appending 2>&1
.
2 is the stream number for stderr (error messages), 1 is represents the stdout stream (the standard non-error output stream).
find . -iname "MyLog.log" > ./myfile/storeLog.log 2>&1
ifstat logging bandwidth usage
awk is buffering its output. Normally, most programs use line buffering when stdout is a terminal but switch to larger buffer sizes when stdout is not a terminal, and awk is no exception. If you ran your command for long enough, you'd eventually see the file size grow in chunks of size 4096 or so (possibly more or less) as the buffer fills up and gets flushed.
To force awk to flush its buffer after every line regardless of whether or not stdout is a terminal, add an fflush()
command:
/usr/bin/ifstat -i eth0 -b -n | awk 'NR>2 {print "Download" $1 "upload" $2; fflush()}' > bandwidth.txt
Programmatic resource monitoring per process in Linux
/usr/src/linux/Documentation/accounting/taskstats.txt
Taskstats is a netlink-based interface for sending per-task and
per-process statistics from the kernel to userspace.Taskstats was designed for the following benefits:
- efficiently provide statistics during lifetime of a task and on its exit
- unified interface for multiple accounting subsystems
- extensibility for use by future accounting patches
This interface lets you monitor CPU, memory, and I/O usage by processes of your choosing. You only need to set up and receive messages on a single socket.
This does not differentiate (for example) disk I/O versus network I/O. If that's important to you, you might go with a LD_PRELOAD
interception library that tracks socket operations. Assuming that you can control the startup of the programs you wish to observe and that they won't do trickery behind your back, of course.
I can't think of any light-weight solutions if those still fail, but linux-audit can globally trace syscalls, which seems a fair bit more direct than re-capturing and analyzing your own network traffic.
PHP network monitoring debian
The info you need is in /proc/net/dev
# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 177937 1304 0 0 0 0 0 0 177937 1304 0 0 0 0 0 0
eth0:16268834 14619 0 0 0 10091 0 0 1201136 10555 20 0 0 0 0 0
For the transfer rate you will have to calculate the delta from the previous capture but the value will be approximate.
How to get process or port Network bandwidth usage in linux
As far as I know Linux doesn't offer an alternative interface to pcap for calculating network usage. /proc/<PID>/stat(us)
contains various process information but nothing about network access, only the total I/O usage including disk access.
Similarly, to know the port you have to read at least the IP header. Hence I assume it is not possible to speed this up significantly, because analyzing all packets in user space will always be slow. A kernel module for this task seems to be the only option.
Related Topics
How Does Linux Support More Than 512Gb of Virtual Address Range in X86-64
Udev Rule with Few Parent Device Attributes
How to Pass Env Variables Between Make Targets
Principle of Qemu CPU Emulation
Powershell's Equivalent to Linux's: Ls -Al
Transpose Rows into Column in Unix
How to Translate X11 Keycode Back to Scancode or Hid Usage Id Reliably
What Is The Fastest Way to Display an Image in Qt on X11 Without Opengl
Convert Column to Matrix Format Using Awk
How to Measure Mispredictions for a Single Branch on Linux
Writing a Syscall to Count Context Switches of a Process
How to Execute Shell Builtin from Scala
How to Find The Reason for a Dead Process Without Log File on Unix
How to Connect to Server: Postgresql on Ubuntu in Windows Subsystem for Linux