Monitor Bandwidth Usage per Process – NetHogs

nethogs is a very helpful tool to find out which PID is taking high bandwidth and the trouble with your network traffic as it groups bandwidth by process instead of breaking the traffic down per protocol or per subnet, like most tools, do. Monitor Bandwidth Usage per Process using Nethogs depends on ncurses for the text-based interface and libpcap for user-level packet capture.

If there’s suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this. This is very helpful for a system administrator to troubleshoot.

Features,

  • Shows TCP download- and upload-speed per process
  • Supports both Ethernet and PPP
  • Supports both IPv4 and IPv6

 

Install Nethogs Tool on a RHEL or CentOS or Fedora Linux

First, update EPEL repo and type the following yum command to install nethogs package:

yum install epel-release -y

Install NetHogs

yum install nethogs -y
Loaded plugins: fastestmirror, remove-with-leaves
apporbit-base | 2.9 kB 00:00:00
apporbit-c3 | 2.9 kB 00:00:00
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 14 kB 00:00:00
epel | 4.7 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): apporbit-c3/primary_db | 112 kB 00:00:00
(2/3): epel/x86_64/updateinfo | 847 kB 00:00:00
(3/3): epel/x86_64/primary_db | 6.1 MB 00:00:00
Loading mirror speeds from cached hostfile
 * base: centos.aol.com
 * epel: mirror.solarvps.com
 * updates: ftp.osuosl.org
Resolving Dependencies
--> Running transaction check
---> Package nethogs.x86_64 0:0.8.5-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
 nethogs x86_64 0.8.5-1.el7 epel 38 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total download size: 38 k
Installed size: 71 k
Is this ok [y/d/N]: y
Downloading packages:
nethogs-0.8.5-1.el7.x86_64.rpm | 38 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : nethogs-0.8.5-1.el7.x86_64 1/1
 Verifying : nethogs-0.8.5-1.el7.x86_64 1/1

Installed:
 nethogs.x86_64 0:0.8.5-1.el7

Complete!

Install Nethogs Tool n a Debian or Ubuntu Linux

Type the following apt-get command/apt-get command

sudo apt-get install nethogs

 

Once you successfully installed, Run the following command to see the bandwidth results.

# nethogs

bandwidth usage checker

For more details.

 

[[email protected]]# nethogs -h

usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device …]]]
-V : prints version.
-h : prints this help.
-b : bughunt mode – implies tracemode.
-d : delay for update refresh rate in seconds. default is 1.
-v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0.
-c : number of updates. default is 0 (unlimited).
-t : tracemode.
-p : sniff in promiscious mode (not recommended).
-s : sort output by sent column.
-a : monitor all devices, even loopback/stopped ones.
device : device(s) to monitor. default is all interfaces up and running excluding loopback

nethogs running, press:
q: quit
s: sort by SENT traffic
r: sort by RECEIVE traffic
m: switch between total (KB, B, MB) and KB/s mode

 

 

 

 

SysBench- Benchmark CPU, File I/O and Memory in CentOS

SysBench is a modular, cross-platform and multi-threaded benchmark tool for evaluating OS parameters that are important for a system running a database under intensive load. Benchmark CPU, File I/O and Memory in CentOS Server.

Current features allow to test the following system parameters:

  • file I/O performance
  • scheduler performance
  • memory allocation and transfer speed
  • POSIX threads implementation performance
  • database server performance

Install SysBench on CentOS 7

# yum install epel-release -y
# yum install sysbench -y
sysbench-options

sysbench-options

General syntax
The general syntax for SysBench is as follows:

sysbench [common-options] --test=name [test-options] command

CPU workload

You can benchmark your CPU performance as follows, The benchmark can be configured with the number of simultaneous threads and the maximum number to verify if it is a prime.

# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time



Prime numbers limit: 20000

Initializing worker threads...

Threads started!



General statistics:
total time: 10.0018s
total number of events: 3652

Latency (ms):
min: 2.67
avg: 2.74
max: 13.85
95th percentile: 2.81
sum: 10000.00

Threads fairness:
events (avg/stddev): 3652.0000/0.00
execution time (avg/stddev): 10.0000/0.00

Verify the the Total time statistics.

 

File IO workload

Before you do the file IO benchmark, you should confirm your drive and mount it if it is additional drive. Here using fileio, you will need to create a set of test files to work on. It is recommended that the size is larger than the available memory to ensure that file caching does not influence the workload too much.

# time sysbench --test=fileio --file-total-size=48G --file-num=24 prepare
sysbench 1.0.6 (using system LuaJIT 2.0.4)

24 files, 2097152Kb each, 49152Mb total
Creating files for the test...
Extra file open flags: 0
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Creating file test_file.3
Creating file test_file.4
Creating file test_file.5
Creating file test_file.6
Creating file test_file.7
Creating file test_file.8
Creating file test_file.9
Creating file test_file.10
Creating file test_file.11
Creating file test_file.12
Creating file test_file.13
Creating file test_file.14
Creating file test_file.15
Creating file test_file.16
Creating file test_file.17
Creating file test_file.18
Creating file test_file.19
Creating file test_file.20
Creating file test_file.21
Creating file test_file.22
Creating file test_file.23
51539607552 bytes written in 594.02 seconds (82.74 MiB/sec).

real 9m54.175s
user 0m0.162s
sys 0m51.073s

 

You can tell the sysbench which kind of workload you want to run: sequential reads, writes or random reads, writes, or a combination.

We are going to use random read/write is used (rndrw) for example testing. Once you generated the files using above command, try to run the following commands.

# sysbench fileio --file-total-size=48G --file-num=24 --file-test-mode=rndrw --time=1800 --file-rw-ratio=1 --threads=16 --max-requests=0 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 16
Initializing random number generator from current time



Extra file open flags: 0
24 files, 2GiB each
48GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.00
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...

Threads started!



File operations:
reads/s: 233.63
writes/s: 233.63
fsyncs/s: 112.14

Throughput:
read, MiB/s: 3.65
written, MiB/s: 3.65

General statistics:
total time: 1800.0621s
total number of events: 1042957

Latency (ms):
min: 0.00
avg: 27.61
max: 300.08
95th percentile: 101.13
sum: 28798434.80

Threads fairness:
events (avg/stddev): 65184.8125/349.16
execution time (avg/stddev): 1799.9022/0.02

 

Once completed, you can check the “Throughput” and “File operations” result to get the details.

After the benchmark, you can delete the 50GB test file from the server using the below command.

#sysbench --test=fileio --file-total-size=50G cleanup

You can also do some workload using sysbench.

the memory workload
the mutex workload
the threads workload

 

 

libguestfs – Manage virtual machine disk images

libguestfs is a C library tool for creating, accessing and modifying virtual machine disk images. You can look inside the disk images, modify the files they contain, create them from scratch, resize them, and much more.

The easy way to modify files in a VM’s disk image without powering on the VM, you could “mount” the disk image. You then would be able to modify the content of the disk image before unmounting it. libguestfs works with any disk image, including ones created in VMware, KVM, qemu, VirtualBox, Xen, and many other hypervisors, and ones which you have created from scratch.

Manage virtual machine disk images

Overview of libguestfs

There are many tools which use libguestfs:

guestfish – Interactive and scriptable shell.

guestmount – Mount filesystems from any guest or disk image on the host.

guestunmount – unmount guest filesystem

virt-alignment – scan Check alignment of partitions in guests.

virt-builder – quick image builder

virt-cat – Display a file from a guest.

virt-copy-in – Copy files and directories into a guest.

virt-copy-out – Copies files and directories out of a virtual machine disk image or named libvirt domain.

virt-customize – customize virtual machines

virtdf Display – disk usage of a guest.

virt-diff – Differences between files in two virtual machines

virt-edit – Edit a file in a guest.

virtfilesystems – Display the partitions, filesystems, logical volumes etc. in a guest.

virt-inspector – Inspect a guest and produce a report detailing the operating system, version, applications installed and more.

virt-format – erase and make blank disks

virt-ls – List files and directories in a guest.

virt-log – display log files

virt-make-fs – Make a new filesystem.

virt-rescue – Rescue mode for guests.

virt-resize – Resize a guest.

virt-sparsify – Make a disk sparse.

virtsysprep – Reset a guest to “factory configuration”.

virt-tar-in – Copy files from a tarball into a guest.

virt-tar-out – Copy files out of a guest into a tarball.

virt-win-reg – Export and merge Windows Registry entries from a Windows guest

libguestfs-test-tool — test libguestfs

libguestfs-make-fixed-appliance — make libguestfs fixed appliance

BoxGrinder & Oz Projects that can create guests from scratch.

OpenStack Uses libguestfs to inject files into guests.

virt-manager Uses libguestfs to display icons and applications in guests.

virt-v2v & virt-p2v Migrate between physical machines and different hypervisors

 

How to install libguestfs toolset on Linux

On Debian-based system:

# sudo apt-get install libguestfs-tools

On Red Hat-based system:

# sudo yum install libguestfs-tools

 

Example:

To mount qcow2 image volume at localfolder.

guestmount -a /path/to/qcow2/image -m <device> /local_path

The “-m <device>” option is used to specify a partition within the disk image.

run the following command.

#guestmount -a /images/testcentos.qcow2 -m /dev/sda1 /mnt

By default, the disk image is mounted in “read-write” mode. So you can modify any file in /mnt after mounting it.