1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ''' |
---|
4 | create RRD databases in this directory for the PVs named |
---|
5 | ''' |
---|
6 | ########### SVN repository information ################### |
---|
7 | # $Date: 2011-08-21 13:24:14 +0000 (Sun, 21 Aug 2011) $ |
---|
8 | # $Author: jemian $ |
---|
9 | # $Revision: 619 $ |
---|
10 | # $HeadURL$ |
---|
11 | # $Id: rrdCreate.py 619 2011-08-21 13:24:14Z jemian $ |
---|
12 | ########### SVN repository information ################### |
---|
13 | |
---|
14 | #************************************************************************** |
---|
15 | |
---|
16 | import xmlSupport |
---|
17 | import rrdtool |
---|
18 | import os.path |
---|
19 | |
---|
20 | #************************************************************************** |
---|
21 | |
---|
22 | def rrdcreate(rrd, args): |
---|
23 | '''format & execute rrdtool.create() on the argument list''' |
---|
24 | cmd = "rrdtool.create(" |
---|
25 | cmd += "'" + rrd + "'" |
---|
26 | for item in args: |
---|
27 | cmd += ", '" + item.strip() + "'" |
---|
28 | cmd += ")" |
---|
29 | eval(cmd) |
---|
30 | |
---|
31 | #************************************************************************** |
---|
32 | |
---|
33 | def createdb(rrdFile, props, pvEntry): |
---|
34 | '''define the RRD for the given PV''' |
---|
35 | arr = [] |
---|
36 | arr.append('--step') |
---|
37 | arr.append(props['spans']['baseStep']) |
---|
38 | rrd = props['rrd'] |
---|
39 | # use a generic variable name (EPICS) since the file name is descriptive |
---|
40 | str = 'DS:EPICS' |
---|
41 | str += ':' + rrd['DST'] |
---|
42 | str += ':' + rrd['heartbeat'] |
---|
43 | str += ':' + pvEntry['min'] |
---|
44 | str += ':' + pvEntry['max'] |
---|
45 | arr.append(str) |
---|
46 | for item in ('AVERAGE', 'MIN', 'MAX'): |
---|
47 | for spanName in props['spans']['names']: |
---|
48 | span = props['spans'][spanName] |
---|
49 | str = 'RRA' |
---|
50 | str += ':' + item |
---|
51 | for it in ('xff', 'steps', 'rows'): |
---|
52 | str += ':' + span[it] |
---|
53 | arr.append(str) |
---|
54 | rrdcreate(rrdFile, arr) |
---|
55 | |
---|
56 | #************************************************************************** |
---|
57 | |
---|
58 | cfg = xmlSupport.readConfigurationXML('/home/joule/WEB33/www/rrd') |
---|
59 | |
---|
60 | for pvEntry in cfg['pvList']: |
---|
61 | rrd = os.path.join( |
---|
62 | cfg['properties']['subdirs']['rrd_file_dir'], |
---|
63 | pvEntry['fileRoot'] + '.rrd' |
---|
64 | ) |
---|
65 | # only create those RRD files that do not already exist |
---|
66 | if (os.path.exists(rrd) == False): |
---|
67 | print "creating " + rrd |
---|
68 | createdb(rrd, cfg['properties'], pvEntry) |
---|