source: people/peter.buschman/backup_monitoring/backmon/commands/status/subcommands/dsu.py@ 1273

Last change on this file since 1273 was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 5.9 KB
Line 
1#!/usr/bin/python26
2###
3### backmon.commands.status.dsu
4###
5
6import sys
7import os
8import os.path
9import glob
10import re
11
12from optparse import OptionParser
13from guppy import hpy
14
15from ....lib import *
16
17from backup_monitoring.debug import *
18from backup_monitoring.math import *
19
20from backup_monitoring.parsing.parsers import bpstulist
21from backup_monitoring.parsing.parsers import nbdevquery
22from backup_monitoring.parsing.parsers import bpdbjobs
23
24usage = 'usage: %prog -e environment status dsu'
25
26parser = OptionParser(usage=usage)
27parser.add_option('-s', '--include-staging', action='store_true', default=False, dest='include_staging', help='include staging storage units')
28
29def run(args, kwargs):
30
31 #
32 # add kwargs to local namespace
33 #
34 for key in kwargs.keys():
35
36 if re.compile('^[A-Z][A-Z_]+$').match(key):
37 exec(key + ' = kwargs[\'' + key + '\']')
38
39 (options, args) = parser.parse_args(args)
40
41 master_feeds = ['nbemmcmd_machinealias_getaliases', 'bpstulist', 'nbdevquery_listdv_stype_basicdisk', 'nbdevquery_listdv_stype_advanceddisk', 'nbdevquery_listdv_stype_puredisk', 'bpdbjobs_most_columns']
42 media_feeds = [ ]
43
44 try:
45
46 environments = ENVIRONMENTS.values()
47
48 hp = hpy()
49
50 DEBUG('HEAPSIZE=%s' % (heapsize()))
51
52 for environment in environments:
53 environment.load_feeds(master=master_feeds, media=media_feeds)
54 environment.parse_aliases()
55 environment.parse_stunits()
56 environment.parse_jobs()
57 environment.parse_disk_pools()
58
59 DEBUG('HEAPSIZE=%s' % (heapsize()))
60
61 print('%s %s %s %s %s %s %s %s %s %s' % ('ENVIRONMENT'.center(15), 'DSU'.center(25), 'TYPE'.center(12), 'SERVER'.center(8), 'STATUS'.center(6), 'JOBS'.center(4), '%FUL'.center(4), 'SIZE'.center(10), 'USED'.center(10), 'AVAIL'.center(10)))
62 print('=============== ========================= ============ ======== ====== ==== ==== ========== ========== ==========')
63
64 active_jobs = {}
65
66 for environment in environments:
67
68 #
69 # count active backup jobs per storage unit
70 #
71 for job in environment.jobs:
72
73 if job.stunit is None:
74 continue
75
76 if job.stunit not in active_jobs:
77 active_jobs[job.stunit] = 0
78
79 if job.backup and job.active:
80 active_jobs[job.stunit] += 1
81
82 #
83 # summarize other stunit statistics
84 #
85 for stunit in environment.stunits:
86
87 server = environment.resolve_alias(stunit.host_connection)
88 server = server.replace('-backup', '')
89
90 if server in environment.updates:
91 monitored = True
92 else:
93 monitored = False
94
95 label = stunit.label
96 storage_unit_type = stunit.storage_unit_type
97
98 #
99 # initialize active job counts
100 #
101 if label not in active_jobs:
102 active_jobs[label] = 0
103
104 #
105 # DSU specific
106 #
107 if storage_unit_type in ['Disk']:
108
109 media_subtype = stunit.media_subtype
110 disk_type = ''
111 disk_pool = None
112
113 size = ''
114 used = ''
115 avail = ''
116 pct_full = ''
117 status = ''
118 jobs = ''
119
120 #
121 # skip staging storage units (DSSUs) unless -s option was specified
122 #
123 if not options.include_staging:
124 if media_subtype == 'Basic' and stunit.stage_data == 'yes':
125 continue
126
127 #
128 # metrics from nbdevquery
129 #
130 if( media_subtype == 'Basic' and label in environment.disk_pools):
131
132 disk_pool = environment.disk_pools[label]
133
134 if( media_subtype == 'DiskPool' and stunit.disk_pool in environment.disk_pools):
135
136 disk_pool = environment.disk_pools[stunit.disk_pool]
137
138 if disk_pool:
139
140 disk_type = disk_pool.disk_type
141 size = pp_bytes(int(float(disk_pool.total_capacity_gb) * 1024.0 * 1024.0 * 1024.0))
142 used = pp_bytes(((float(disk_pool.total_capacity_gb) - float(disk_pool.free_space_gb)) * 1024.0 * 1024.0 * 1024.0))
143 avail = pp_bytes(int(float(disk_pool.free_space_gb) * 1024.0 * 1024.0 * 1024.0))
144
145 if( disk_pool.total_capacity_gb > 0.0 ):
146 pct_full = '%01.0f%%' % ((((float(disk_pool.total_capacity_gb) - float(disk_pool.free_space_gb)) / float(disk_pool.total_capacity_gb)) * 100.0))
147 else:
148 pct_full = '%01.0f%%' % (disk_pool.use_pct)
149
150 if( 'AdminUp' in disk_pool.flags and 'InternalUp' in disk_pool.flags ):
151 status = 'UP'
152 else:
153 status = 'DOWN'
154
155 #
156 # get active job count
157 #
158 if label in active_jobs:
159 jobs = '%d' % (active_jobs[label])
160
161 print('%s %s %s %s %s %s %s %s %s %s' % (environment.name.center(15), label.rjust(25), disk_type.rjust(12), server.ljust(8), status.center(6), jobs.rjust(4), pct_full.rjust(4), size.rjust(10), used.rjust(10), avail.rjust(10)))
162
163 except Exception, e:
164
165 #raise BackmonError, e
166 raise
167
Note: See TracBrowser for help on using the repository browser.