source: pvrrd/epics2rrd.py @ 236

Last change on this file since 236 was 236, checked in by jemian, 13 years ago

show user@host info more in the logs - we need the reminder

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Author Revision Url Id
File size: 2.5 KB
Line 
1#!/usr/bin/env python
2
3'''
4log EPICS data into RRD files
5'''
6
7########### SVN repository information ###################
8# $Date: 2011-01-19 01:27:35 +0000 (Wed, 19 Jan 2011) $
9# $Author: jemian $
10# $Revision: 236 $
11# $HeadURL$
12# $Id: epics2rrd.py 236 2011-01-19 01:27:35Z jemian $
13########### SVN repository information ###################
14
15#-------------------------------------------------------------
16
17import os
18import time
19import sys
20import rrd_pv       # coordination between EPICS and RRD
21import xmlSupport   # read pvlist.xml and properties.xml files
22
23#-------------------------------------------------------------
24
25svnrev = "$Revision: 236 $".strip("$").split()[1]
26
27message = time.ctime()
28message += " %s (r%s)" % ( sys.argv[0], svnrev )
29message += " PID=" + repr(os.getpid())
30message += " starting on HOST=" + os.environ['HOST']
31message += " by user=" + os.environ['USER']
32print "# ", message
33sys.stdout.flush()
34
35db = {}
36cfg = xmlSupport.readConfigurationXML('/home/joule/WEB33/www/rrd')
37properties = cfg['properties']
38
39pvList = cfg['pvList']
40
41for pvEntry in pvList:
42    name = pvEntry['pv']
43    if not name in db.keys():
44        basedir = properties['rrd_logs_base_dir']
45        rrdpath = properties['subdirs']['rrd_file_dir']
46        rrdfile = pvEntry['fileRoot'] + '.rrd'
47        rrd_database = os.path.join(basedir, rrdpath, rrdfile)
48
49        fileRoot = pvEntry['fileRoot']
50        pvObject = rrd_pv.rrd_pv(name, rrd_database)
51        db[name] = pvObject
52
53# throttle the printing of messages in the main event loop
54nexttime = time.time()
55update_interval_seconds = 10*60  # update every 10 minutes
56
57while 1:
58    pvcount = 0
59    keys = db.keys()
60    keys.sort()
61    notconnected_msgs = []
62    for name in keys:
63        rrdPv = db[name]
64        if rrdPv.pv.connected:
65            pvcount += 1
66            if rrdPv.pv.value == None:
67                rrdPv.pv.get()
68            rrdPv.update()
69            #print rrdPv
70        else:
71            notconnected_msgs.append("Trying to connect: %s" % name)
72            rrd_database = rrdPv.rrd
73            #rrdPv.pv.ch.connect()  # does not seem to connect if initial try failed
74            # replace existing object
75            db[name] = rrd_pv.rrd_pv(name, rrd_database)
76    if (time.time() >= nexttime):
77        # throttle the frequency of this message:
78        if len(notconnected_msgs):
79            for msg in notconnected_msgs:
80                print "# ", msg
81        print "# ", time.ctime()," PID=" + repr(os.getpid()),
82        print os.environ['USER'] + '@' + os.environ['HOST'],
83        print "   %d of %d PVs connected" % (pvcount, len(db))
84        nexttime = time.time() + update_interval_seconds  # set next update time
85    sys.stdout.flush()
86    time.sleep(5)
Note: See TracBrowser for help on using the repository browser.