Example #1
0
def main(args):
    c = Client()
    s = c.read_monitor_point('diagnostics/spectra', 'dr%s' % args.beam)
    t = datetime.utcfromtimestamp(s.timestamp)
    s = ImageMonitorPoint(s)
    s.to_file(args.output)
    print(f"Saved spectra from power beam {args.beam} at {t} to {args.output}")
Example #2
0
 def __init__(self, log, id, queue, shutdown_event=None, update_interval=10):
     self.log = log
     self.id = id
     self.queue = queue
     if shutdown_event is None:
         shutdown_event = threading.Event()
     self.shutdown_event = shutdown_event
     self.update_interval = update_interval
     
     self.client = Client(id)
Example #3
0
 def __init__(self, log, id, queue=None, shutdown_event=None, update_interval=10):
     self.log = log
     self.id = id
     self.queue = queue
     if shutdown_event is None:
         shutdown_event = threading.Event()
     self.shutdown_event = shutdown_event
     self.update_interval = update_interval
     
     self.client = Client(id)
     
     self._pid = os.getpid()
     self._state = deque([], 2)
     self._update()
 def __init__(self, log, id, iring, ntime_gulp=1, guarantee=True, core=-1):
     self.log        = log
     self.iring      = iring
     self.ntime_gulp = ntime_gulp
     self.guarantee  = guarantee
     self.core       = core
     
     self.client = Client(id)
     
     self.bind_proclog = ProcLog(type(self).__name__+"/bind")
     self.in_proclog   = ProcLog(type(self).__name__+"/in")
     self.size_proclog = ProcLog(type(self).__name__+"/size")
     self.sequence_proclog = ProcLog(type(self).__name__+"/sequence0")
     self.perf_proclog = ProcLog(type(self).__name__+"/perf")
     
     self.in_proclog.update({'nring':1, 'ring0':self.iring.name})
Example #5
0
 def __init__(self, log, id, directory, quota=None, shutdown_event=None, update_interval=10):
     self.log = log
     self.id = id
     self.directory = directory
     if quota == 0:
         quota = None
     self.quota = quota
     if shutdown_event is None:
         shutdown_event = threading.Event()
     self.shutdown_event = shutdown_event
     self.update_interval = update_interval
     
     self.client = Client(id)
     
     self._files = []
     self._file_sizes = []
    def __init__(self,
                 log,
                 id,
                 directory,
                 queue,
                 filewriter_base,
                 filewriter_kwds=None,
                 shutdown_event=None):
        self.log = log
        self.directory = directory
        self.queue = queue
        self.filewriter_base = filewriter_base
        if filewriter_kwds is None:
            filewriter_kwds = {}
        self.filewriter_kwds = filewriter_kwds
        if shutdown_event is None:
            shutdown_event = threading.Event()
        self.shutdown_event = shutdown_event

        self.client = Client(id)

        for cls in self._commands:
            cls.attach_to_processor(self)
Example #7
0
def main(argv):
    parser = argparse.ArgumentParser(
        description="Data recorder manager for slow/fast visibility data")
    parser.add_argument(
        '-b',
        '--begin-band',
        type=int,
        default=1,
        help='beginning dr_visibility.py band number to manage')
    parser.add_argument(
        '-e',
        '--end-band',
        type=int,
        default=16,
        help='ending dr_visibility.py IP band number to manage')
    parser.add_argument('-l',
                        '--logfile',
                        type=str,
                        help='file to write logging to')
    parser.add_argument('-q',
                        '--quick',
                        action='store_true',
                        help='run in fast visibiltiy mode')
    parser.add_argument('-f',
                        '--fork',
                        action='store_true',
                        help='fork and run in the background')
    args = parser.parse_args()

    # Fork, if requested
    if args.fork:
        stderr = '/tmp/%s_%i.stderr' % (os.path.splitext(
            os.path.basename(__file__))[0], args.port)
        daemonize(stdin='/dev/null', stdout='/dev/null', stderr=stderr)

    # Setup logging
    log = logging.getLogger(__name__)
    logFormat = logging.Formatter('%(asctime)s [%(levelname)-8s] %(message)s',
                                  datefmt='%Y-%m-%d %H:%M:%S')
    logFormat.converter = time.gmtime
    if args.logfile is None:
        logHandler = logging.StreamHandler(sys.stdout)
    else:
        logHandler = LogFileHandler(args.logfile)
    logHandler.setFormatter(logFormat)
    log.addHandler(logHandler)
    log.setLevel(logging.DEBUG)

    log.info("Starting %s with PID %i", os.path.basename(__file__),
             os.getpid())
    log.info("Cmdline args:")
    for arg in vars(args):
        log.info("  %s: %s", arg, getattr(args, arg))

    # Setup the IDs to use/manage
    mcs_id = 'drv'
    if args.quick:
        mcs_id += 'f'
    else:
        mcs_id += 's'
    MANAGE_ID = []
    for band in range(args.begin_band, args.end_band + 1):
        sub_id = mcs_id + str(band)
        MANAGE_ID.append(sub_id)

    # Setup signal handling
    shutdown_event = setup_signal_handling([])

    c = Client(mcs_id)

    for cmd in ('ping', 'sync', 'start', 'stop'):
        cb = CommandCallbackBase(c.client)

        def wrapper(value):
            status = True
            response = {}
            for id in MANAGE_ID:
                s, r = c.send_command(id, cmd, **value)
                status &= s
                response[id] = r
            return status, response

        cb.action = wrapper
        c.set_command_callback(cmd, cb)

    tlast = 0.0
    while not shutdown_event.is_set():
        if time.time() - tlast > 15:
            status = "normal"
            info = ""
            first = True
            for id in MANAGE_ID:
                t0 = time.time()
                svalue = c.read_monitor_point('summary', id=id)
                ivalue = c.read_monitor_point('info', id=id)
                if svalue is None:
                    svalue = MonitorPoint("timeout", timestamp=0)
                if ivalue is None:
                    ivalue = MonitorPoint("timeout", timestamp=0)
                log.info("%s -> %s (%s) at %.0f", id, svalue.value,
                         ivalue.value, svalue.timestamp)

                age = svalue.timestamp - t0
                if age > 120:
                    status = "timeout"
                if status == "error":
                    status = svalue.value
                elif svalue.value == "warning":
                    if status == "normal":
                        status = svalue.value

                if not first:
                    info += "; "
                info += "%s: %s (%s)" % (id, svalue.value, ivalue.value)
                first = False

            ts = time.time()
            c.write_monitor_point('summary', status, timestamp=ts)
            c.write_monitor_point('info', info, timestamp=ts)

            tlast = ts

        time.sleep(2)

    return 0