Package invocations :: Package monitoring :: Module CheckDiskSize
[hide private]

Source Code for Module invocations.monitoring.CheckDiskSize

 1  #! /usr/bin/env python 
 2  #------------------------------------------------------------------------------ 
 3  #$Id: CheckDiskSize.py 6322 2009-11-09 22:28:54Z RossCollins $ 
 4  """ 
 5     Shows disk sizes and free space of pixel server disks; disks with special 
 6     rules are marked with '*'. 
 7   
 8     @author: E. Sutorius 
 9     @org:    WFAU, IfA, University of Edinburgh 
10   
11     @newfield contributors: Contributors, Contributors (Alphabetical Order) 
12     @contributors: R.S. Collins 
13  """ 
14  #------------------------------------------------------------------------------ 
15  from   __future__ import division 
16   
17  from   wsatools.CLI         import CLI 
18  import wsatools.CSV             as csv 
19  import wsatools.SystemConstants as sysc 
20  import wsatools.Utilities       as utils 
21  #------------------------------------------------------------------------------ 
22  # Entry point for script. 
23   
24  # Allow module to be imported as well as executed from the command line 
25  if __name__ == "__main__": 
26      validSizes = ("K", "M", "G", "T") 
27      CLI.progOpts += [ 
28        CLI.Option('b', "blocksize", 
29          "the format of the output, one of " + ", ".join(validSizes), 
30          "SYMBOL", "G", isValOK=lambda x: x in validSizes), 
31        CLI.Option('d', "disks", 
32          "a comma separated list of disks", 
33          "LIST")] 
34      cli = CLI("CheckDiskSize", "$Revision: 6322 $", __doc__) 
35   
36      blocksizeFactor = {'K': 1, 
37                         'M': sysc.one_kilobyte(), 
38                         'G': sysc.one_megabyte(), 
39                         'T': sysc.one_gigabyte()}[cli.getOpt("blocksize")] 
40   
41      diskList = (csv.values(cli.getOpt("disks")) if cli.getOpt("disks") else 
42                  sysc.massStorageRaidFileSystem()) 
43   
44      # get free memory on available disks here 
45      spacePerDisk = utils.getDiskSpace(sysc.massStorageRaidFileSystem()) 
46   
47      # Free space to be left on each disk 
48      freeperc = sysc.leaveSpaceOnMSRFS() 
49      specDisks = sysc.developRaidFileSystem() + ["/disk01/wsa"] 
50   
51      fmt = "%14s " + ' '.join(["%15s"]*4) 
52      print(fmt % ("disk", "used", "free", "safe", "usable")) 
53      print(fmt % ("----", "----", "----", "----", "------")) 
54   
55      fmt = "%14s" + ''.join(["%15s" + cli.getOpt("blocksize")]*4) 
56   
57      for disk in sorted(diskList): 
58          size = int(spacePerDisk[disk][0] / blocksizeFactor) 
59          free = int(spacePerDisk[disk][1] / blocksizeFactor) 
60          safe = int(freeperc.get(disk, 0) / blocksizeFactor) 
61          marker = '*' if disk in specDisks else '' 
62          print(fmt % (disk, size, free, safe, free - safe) + marker) 
63   
64  #------------------------------------------------------------------------------ 
65  # Change log: 
66  # 
67  # 18-Apr-2007, ETWS: First version. 
68  # 10-Apr-2009,  RSC: Updated to use the CLI API. 
69