Resource Usage

From Server Knowledge Base
Jump to navigationJump to search

Disk Usage

Note: If you have a file/files open and your disk space appears full, do a reboot and it will close the open file/s. This is a true indication of disk space then.

To check overall disk usage run:

du -h
df -h

From root (cd /) run one of the following commands to discover the overall usage, please note this can take a while depending on the amount of data you have.

  • Using grep looks down one directory and looks for GB disk usage, use M for MB, K for KB.
  • To dive down more directories change the max depth value.
du -h --max-depth=1 | grep G
du -kh | grep G
du -khs * | grep G

Use the below command to show number of files in target directory:

ls -1 target|wc -l

A useful tool for Ubuntu is called ncdu, to install and run this, do:

apt-get install ncdu
cd /
ncdu

For Inodes:

df -i
find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
cd /directory that is the largest
#run find command again

Empty a file

:> /file/path

This always exits true, but produces no output. Good for large old log files.

More complicated options

  • Changing the second n option specifies the amount of results you want to show.
du --max-depth=1|sort -nr|head -n10 #this prints out the largest value at the top
du --max-depth=1|sort -n|tail -n5 #this prints out the largest value at the bottom

du --max-depth=20|sort -nr|head -n20>diskusage.txt #this outputs the top 20 results into a file

du --max-depth=1|sort -nr|tail -n10 #this prints out the smallest value at the bottom, good for temp directories
du --max-depth=1|sort -n|head -n10 #this prints out the smallest value at the top

du --max-depth=1 -h * |sort -n -k 1 |egrep 'M|G'
du -sh *

http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/

If the server is Windows, you can use Performance monitor which is built into Windows to run on the server to monitor free space along with disk read/writes. You may wish to install http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx as it will provide a greater overview as to what is writing to the server and when.

If there is a program writing to the temporary directory it may be putting the files in there and then removing them once they are finished being used hence the fluctuation.

General Usage

htop FAQ

On Linux:

top
apt-get install htop
#or
yum install htop
#then
htop

On Windows use Task Manager and Performance Monitor.

Memory available

Display the top ten running processes - sorted by memory usage:

ps aux --sort -rss | head

free -m

This shows you the available and currently used memory (RAM) in MB. So 1900-2000 is 1-2GB. On a Shared/VPS environment normally half the Total and you get your Soft Limit (guaranteed), the full amount is your Hard Limit (burstable, not guaranteed).

cat /proc/user_beancounters

You will see something like this:

Version: 2.5

uid        resource         |  held     | maxheld  | barrier               limit                        |      failcnt
328178:    kmemsize         |  4348996  | 4366996  | 16384000              18022400                     |           0
           lockedpages      |  0        |       0  | 4096                  4096                         |           0
           privvmpages      |  68233    |   68262  | 153600                153600                       |       34995

or for example on an 8GB of RAM server:

uid        resource         |  held     | maxheld  barrier               limit                          |    failcnt
506378:    kmemsize         |  62055413 | 62490301 9223372036854775807   9223372036854775807            |         0
           lockedpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0
           privvmpages      |  384054   |  384315  9223372036854775807   9223372036854775807            |         0
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0
           dummy            |  0        |       0  9223372036854775807   9223372036854775807            |         0
           numproc          |  205      |     208  9223372036854775807   9223372036854775807            |         0
           physpages        |  119511   |  119641  9223372036854775807   9223372036854775807            |         0
           vmguarpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0
           oomguarpages     |  119513   |  119643  9223372036854775807   9223372036854775807            |         0
           numtcpsock       |  34       |      36  9223372036854775807   9223372036854775807            |         0
           numflock         |  21       |      23  9223372036854775807   9223372036854775807            |         0
           numpty           |  1        |       1  9223372036854775807   9223372036854775807            |         0
           numsiginfo       |  4        |       5  9223372036854775807   9223372036854775807            |         0
           tcpsndbuf        |  601840   |  648400  9223372036854775807   9223372036854775807            |         0
           tcprcvbuf        |  557056   |  589824  9223372036854775807   9223372036854775807            |         0
           othersockbuf     |  2132376  | 2133680  9223372036854775807   9223372036854775807            |         0
           dgramrcvbuf      |  0        |    2608  9223372036854775807   9223372036854775807            |         0
           numothersock     |  947      |     949  9223372036854775807   9223372036854775807            |         0
           dcachesize       |  3301507  | 3312775  9223372036854775807   9223372036854775807            |         0
           numfile          |  20555    |   20630  9223372036854775807   9223372036854775807            |         0
           numiptent        |  15       |      15  9223372036854775807   9223372036854775807            |         0

Take a look at the numbers left to the first Pipe (|) in the held column: These stand for the actual usage. Right of the last pipe: Failcounts. Having failcounts inidicates that a service is consuming all the ram.