Monitoring Disk Usage

Monitoring Disk Usage

The most commonly used command for monitoring disk space usage is /usr/bin/df, which, by default, displays the number of free blocks and files on all currently mounted volumes. Alternatively, many administrators create an alias for df in their shell initialization script (for example, ~/.cshrc for C shell) like df -k, which displays the amount of free disk space in kilobytes. The basic output for df for a SPARC system looks like this:

 # df
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0     245911   30754  190566    14%    /
/dev/dsk/c0t0d0s4    1015679  430787  523952    46%    /usr
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
/dev/dsk/c0t0d0s3     492871  226184  217400    51%    /var
/dev/md/dsk/d1       4119256 3599121  478943    89%    /opt
swap                  256000   43480  212520    17%    /tmp
/dev/dsk/c0t2d0s3    4119256 3684920  393144    91%    /disks/vol1
/dev/md/dsk/d0       17398449 12889927 4334538    75%    /disks/vol2
/dev/md/dsk/d3       6162349 5990984  109742    99%    /disks/vol3
/dev/dsk/c1t1d0s0    8574909 5868862 1848557    77%    /disks/vol4
/dev/dsk/c2t3d0s2    1820189 1551628  177552    90%    /disks/vol5
/dev/dsk/c1t2d0s0    4124422 3548988  575434    87%    /disks/vol6
/dev/dsk/c2t2d0s3    8737664 8281113  456551    95%    /disks/vol7
/dev/md/dsk/d2       8181953 6803556 1296578    84%    /disks/vol8
client:/disks/junior_developers
                     4124560 3469376  613944    85%    /disks/junior_developers

For an Intel system, the output is similar, although disk slices have a different naming convention:

# df
Filesystem            kbytes    used   avail capacity  Mounted on
/proc                      0       0       0     0%    /proc
/dev/dsk/c0d0s0        73684   22104   44212    34%    /
/dev/dsk/c0d0s6       618904  401877  161326    72%    /usr
fd                         0       0       0     0%    /dev/fd
/dev/dsk/c0d0s1        29905    4388   22527    17%    /var
/dev/dsk/c0d0s7      7111598       9 7040474     1%    /export/home
swap                  222516     272  222244     1%    /tmp
/vol/dev/diskette0/unnamed_floppy
                        1423     131    1292    10%    /floppy/unnamed_floppy

df has a number of command-line options that can used to customize the collection and display of information. For example,

# df –a
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0     245911   30754  190566    14%    /
/dev/dsk/c0t0d0s4    1015679  430787  523952    46%    /usr
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
/dev/dsk/c0t0d0s3     492871  226185  217399    51%    /var
/dev/md/dsk/d1       4119256 3599121  478943    89%    /opt
swap                  256000   43480  212520    17%    /tmp
/dev/dsk/c0t2d0s3    4119256 3684920  393144    91%    /disks/vol1
/dev/md/dsk/d0       17398449 12889927 4334538    75%    /disks/vol2
/dev/md/dsk/d3       6162349 5990984  109742    99%    /disks/vol3
/dev/dsk/c1t1d0s0    8574909 5868862 1848557    77%    /disks/vol4
/dev/dsk/c2t3d0s2    1820189 1551628  177552    90%    /disks/vol5
/dev/dsk/c1t2d0s0    4124422 3548988  575434    87%    /disks/vol6
auto_direct          4124560 3469376  613944    85%    /disks/www
auto_direct                0       0       0     0%    /disks/ftp
server:vold(pid329)
                           0       0       0     0%    /vol
/dev/dsk/c2t2d0s3    8737664 8281113  456551    95%    /disks/vol7
/dev/md/dsk/d2       8181953 6803556 1296578    84%    /disks/vol8
client:/disks/junior_developers
                     4124560 3469376  613944    85%    /disks/junior_developers

prints usage data for all file systems, even those that have the “ignore” option set in their entries in /etc/mnttab:

# cat /etc/mnttab
/dev/dsk/c0t0d0s0       /       ufs     rw,suid,dev=800000,largefiles   944543087
/dev/dsk/c0t0d0s4       /usr    ufs     rw,suid,dev=800004,largefiles   944543087
/proc   /proc   proc    rw,suid,dev=29c0000     944543087
fd      /dev/fd fd      rw,suid,dev=2a80000     944543087
/dev/dsk/c0t0d0s3       /var    ufs     rw,suid,dev=800003,largefiles   944543087
/dev/md/dsk/d1  /opt    ufs     suid,rw,largefiles,dev=1540001  944543105
swap    /tmp    tmpfs    ,dev=1 944543105
/dev/dsk/c0t2d0s3       /disks/vol1     ufs     suid,rw,largefiles,dev=800013   944543105
/dev/md/dsk/d0  /disks/vol2    ufs     nosuid,rw,largefiles,quota,dev=1540000  944543105
/dev/md/dsk/d3  /disks/vol3     ufs     nosuid,rw,largefiles,dev=1540003        944543106
/dev/dsk/c1t1d0s0       /disks/vol4 ufs     nosuid,rw,largefiles,dev=800080 944543105
/dev/dsk/c2t3d0s2       /disks/vol5     ufs     nosuid,rw,largefiles,dev=80010a 944543106
/dev/dsk/c1t2d0s0       /disks/vol6 ufs     suid,rw,largefiles,dev=800088   944543106
auto_direct     /disks/www        autofs  ignore,direct,nosuid,dev=2c00001        944543181
auto_direct     /disks/ftp autofs  ignore,direct,nosuid,dev=2c00002        944543181
server:vold(pid329)   /vol    nfs     ignore,noquota,dev=2bc0002      944543192
/dev/dsk/c2t2d0s3       /disks/vol7 ufs     nosuid,rw,largefiles,dev=800103 944548661
/dev/md/dsk/d2  /disks/vol8 ufs     nosuid,rw,largefiles,quota,dev=1540002  944553321
client:/disks/junior_developers   /disks/junior_developers        nfs     
nosuid,dev=2bc0040      944604066

To avoid delays in printing resource information on NFS-mounted volumes, it is also possible to just check local file systems with the following command:

# df –l
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0     245911   30754  190566    14%    /
/dev/dsk/c0t0d0s4    1015679  430787  523952    46%    /usr
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
/dev/dsk/c0t0d0s3     492871  226184  217400    51%    /var
/dev/md/dsk/d1       4119256 3599121  478943    89%    /opt
swap                  256000   43488  212512    17%    /tmp
/dev/dsk/c0t2d0s3    4119256 3684920  393144    91%    /disks/vol1
/dev/md/dsk/d0       17398449 12889901 4334564    75%    /disks/vol2
/dev/md/dsk/d3       6162349 5990984  109742    99%    /disks/vol3
/dev/dsk/c1t1d0s0    8574909 5868862 1848557    77%    /disks/vol4
/dev/dsk/c2t3d0s2    1820189 1551628  177552    90%    /disks/vol5
/dev/dsk/c1t2d0s0    4124422 3548988  575434    87%    /disks/vol6
/dev/dsk/c2t2d0s3    8737664 8281113  456551    95%    /disks/vol7
/dev/md/dsk/d2       8181953 6803556 1296578    84%    /disks/vol8

A block device can be specified on the command line, and its individual usage measured—for example, a slice on controller 1:

# df /dev/dsk/c1d0d2
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c1t1d0s0    8574909 5868862 1848557    77%    /disks/vol4

Users can also check the status of the disks holding their individual user directories and files by using df. For example,

# df /staff/pwatters
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/md/dsk/d0       17398449 12889146 4335319    75%    /disks/vol2

will display the disk space usage for the disk on which the home directory exists for user pwatters, while

# df /tmp/mbox.pwatters
Filesystem            kbytes    used   avail capacity  Mounted on
swap                  256000   45392  210608    18%    /tmp

checks the size of the partition on which the temporary mailbox for the user pwatters was created by the elm mail-reading program.

Tip 

The size of the partition on which the temporary mailbox resides is a good thing to check if you intend sending a lot of mail messages!

Another way of obtaining disk space usage information with more directory-by-directory detail is by using the /usr/bin/du command. This command prints the sum of the sizes of every file in the current directory, and performs the same task recursively for any subdirectories. The size is calculated by adding together all of the file sizes in the directory, where the size for each file is rounded up to the nearest 512-byte block. For example, taking a du of the /etc directory looks like this:

# cd /etc
# du
14      ./default
7       ./cron.d
6       ./dfs
8       ./dhcp
201     ./fs/hsfs
681     ./fs/nfs
1       ./fs/proc
209     ./fs/ufs
1093    ./fs
26      ./inet
127     ./init.d
339     ./lib
37      ./mail
4       ./net/ticlts
2429    .

Thus, /etc and all its subdirectories contain a total of 2429 blocks of data. Of course, this kind of output is fairly verbose, and probably not much use in its current form. The size in kilobytes can be displayed by using df –k.



Part I: Solaris 9 Operating Environment, Exam I