-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapfsls.py
84 lines (70 loc) · 2.66 KB
/
apfsls.py
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
# generate xml for autopyfactory SLS reporting
# Peter Love <[email protected]>
import logging
from os.path import getmtime
import sys
import time
from optparse import OptionParser
from XMLdoc import xml_doc
def generateReport():
id = 'PilotFactory_voatlas60'
shortname = 'PilotFactory_voatlas60'
fullname = 'AutoPyFactory monitoring service on voatlas60'
logtime = getmtime('/opt/panda/autopyfactory/var/factory.log')
now = time.time()
age = now - logtime
if int(age) < 300:
availability = 100
elif int(age) < 600:
availability = 75
elif int(age) < 1800:
availability = 25
else:
availability = 0
availabilitydesc = 'Monitor logfile'
availabilityinfo = 'Log file should be fresh < 300s'
refreshperiod = 10
validityduration = 20
notes = "http://apfmon.lancs.ac.uk/mon/"
generator=xml_doc()
generator.set_value('id', id)
generator.set_value('shortname', shortname)
generator.set_value('fullname', fullname)
generator.set_value('availability', availability)
generator.add_availability_threshold('available', 75)
generator.add_availability_threshold('affected', 45)
generator.add_availability_threshold('degraded', 15)
generator.set_value('availabilitydesc', availabilitydesc)
generator.set_value('availabilityinfo', availabilityinfo)
generator.set_value('refreshperiod', refreshperiod)
generator.set_value('validityduration', validityduration)
generator.set_value('notes', notes)
generator.add_data('age', 'Age of log file in seconds', int(age), generator.info['timestamp'])
generator.add_data('njobs', 'Number of jobs this cycle', 123, generator.info['timestamp'])
return generator.print_xml()
def main():
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-q", action="store_true", default=False,
help="quiet mode", dest="quiet")
parser.add_option("-d", action="store_true", default=False,
help="debug mode", dest="debug")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.error("incorrect number of arguments")
return 1
loglevel = 'INFO'
if options.quiet:
loglevel = 'WARNING'
if options.debug:
loglevel = 'DEBUG'
logger = logging.getLogger()
logger.setLevel(logging._levelNames[loglevel])
fmt = '[APF:%(levelname)s %(asctime)s] %(message)s'
formatter = logging.Formatter(fmt, '%T')
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
print generateReport()
if __name__ == "__main__":
sys.exit(main())