/usr/lib/python2.7/dist-packages/arcnagios/plugins/arcce_clean.py is in nordugrid-arc-nagios-plugins 1.9.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | import os, random, time
from arcnagios.arcutils import arcstat, arcclean, J_UNDEFINED
from arcnagios.jobutils import JobNagiosPlugin
from arcnagios.nagutils import OK, WARNING, CRITICAL, ServiceReport, ServiceOK
from arcnagios.utils import counted_adjectives
class Check_arcce_clean(JobNagiosPlugin):
def __init__(self):
JobNagiosPlugin.__init__(self)
ap = self.argparser.add_argument_group('Job Cleaner Options')
ap.add_argument('--timeout', dest = 'timeout',
type = int, default = 120,
help = 'Overall timeout for probe, but currently does not limit '
'scheduled cleanup.')
ap.add_argument('--max-age', dest = 'max_age',
type = int, default = 604800,
help = 'Max age before jobs info is cleaned.')
ap.add_argument('--arcstat-timeout', dest = 'arcstat_timeout',
type = int, default = 5, metavar = 'T',
help = 'Passed to arcstat --timeout.')
ap.add_argument('-w', dest = 'warning_load',
type = float, default = 10,
help = 'Ratio of remaining work to processed work above which \
to issue a warning alert.')
ap.add_argument('-c', dest = 'critical_load',
type = float, default = 20,
help = 'Ratio of remaining work to processed work above which \
to issue a critical alert.')
def time_left(self):
return self.opts.timeout - time.time() + self.t_start
def prune_jobs(self):
active_jobids = self.collect_active_jobids()
t_left = self.time_left()
if t_left < 1:
self.log.warn('Timeout before querying probes to prune.')
return
jobstats = arcstat(log = self.log,
timeout = min(t_left, self.opts.arcstat_timeout),
show_unavailable = True)
jobstats = list(jobstats.iteritems())
random.shuffle(jobstats)
pruned_count = 0
failed_count = 0
rest_count = 0
for jobid, jobstat in jobstats:
t_left = self.time_left()
if jobstat.state == J_UNDEFINED:
if jobid in active_jobids:
self.log.info('Skipping unavailable but active %s.' % jobid)
else:
if t_left < 1:
rest_count += 1
continue
try:
self.log.info('Cleaning unavailable job %s.' % jobid)
arcclean([jobid], timeout = t_left, force = True,
log = self.log)
pruned_count += 1
except Exception, xc:
self.log.warn('Failed to clean unavalible %s: %s'
% (jobid, xc))
failed_count += 1
elif jobstat.submitted:
tm_sub = time.strptime(jobstat.submitted, '%Y-%m-%d %H:%M:%S')
t_sub = time.mktime(tm_sub)
if self.t_start - t_sub > self.opts.max_age:
if t_left < 1:
rest_count += 1
continue
try:
self.log.info('Cleaning %s submitted %s.'
% (jobid, jobstat.submitted))
arcclean([jobid], timeout = t_left, force = True,
log = self.log)
pruned_count += 1
except Exception, xc:
self.log.warn('Failed to clean %s: %s' % (jobid, xc))
failed_count += 1
return (pruned_count, failed_count, rest_count)
def _check_load(self, load, msg):
if load > self.opts.critical_load:
msg += ', critical load!'
return (CRITICAL, msg)
elif load > self.opts.warning_load:
msg += ', high load!'
return (WARNING, msg)
else:
msg += '.'
return (OK, msg)
def check(self):
if not os.path.exists(self.top_workdir):
self.log.info('The work directory is %s.'%self.top_workdir)
return ServiceOK('No jobs to clean since the working directory '
'has not yet been created.')
self.t_start = time.time()
self.require_voms_proxy()
s_ok, s_retry, s_failed, s_postponed = \
self.cleaner.run(self.time_left() * 2 / 3)
j_cleaned, j_failed, j_postponed = \
self.prune_jobs()
s_load = s_postponed / float(s_ok + s_failed + 1)
j_load = j_postponed / float(j_cleaned + j_failed + 1)
s_msg = 'Sched: ' + counted_adjectives(
[(s_ok, 'ok'),
(s_retry, 'to retry'),
(s_failed, 'failed'),
(s_postponed, 'postponed')], if_empty = 'no work')
j_msg = 'Jobfile: ' + counted_adjectives(
[(j_cleaned, 'cleaned'),
(j_failed, 'failed'),
(j_postponed, 'postponed')], if_empty = 'no work')
s_service_state, s_msg = self._check_load(s_load, s_msg)
j_service_state, j_msg = self._check_load(j_load, j_msg)
return ServiceReport(max(s_service_state, j_service_state),
s_msg + ' ' + j_msg)
|