Exemple #1
0
def create_sensor_from_meta(sensor_manager, **kwargs):
    sid = kwargs['id']
    sname = kwargs['name'].replace('_', '-')
    sensor = Corr2Sensor.string(
        name='speadmeta-0x{id:04x}-{name}'.format(id=sid, name=sname),
        description=kwargs['description'],
        initial_status=Corr2Sensor.UNKNOWN, manager=sensor_manager)
    return sensor
Exemple #2
0
def setup_sensors(sensor_manager):
    """
    INSTRUMENT-STATE-INDEPENDENT sensors to be reported to CAM
    :param sensor_manager: A SensorManager instance
    :return:
    """
    # Set up a one-worker pool per host to serialise interactions with each host
    host_executors = {
        host.host: futures.ThreadPoolExecutor(max_workers=1)
        for host in sensor_manager.instrument.fhosts +
        sensor_manager.instrument.xhosts
    }
    general_executor = futures.ThreadPoolExecutor(max_workers=1)

    if not sensor_manager.instrument.initialised():
        raise RuntimeError('Cannot set up sensors until instrument is '
                           'initialised.')

    ioloop = getattr(sensor_manager.instrument, 'ioloop', None)
    if not ioloop:
        ioloop = getattr(sensor_manager.katcp_server, 'ioloop', None)
    if not ioloop:
        raise RuntimeError('IOLoop-containing katcp version required. Can go '
                           'no further.')

    sensor_manager.sensors_clear()

    # f-engine received timestamps okay and per-host received timestamps
    sensor_ok = Corr2Sensor.boolean(
        name='feng-rxtime-ok',
        description='Are the times received by f-engines in the system okay',
        initial_status=Corr2Sensor.UNKNOWN,
        manager=sensor_manager, executor=general_executor)
    sensor_values = {}
    for _f in sensor_manager.instrument.fhosts:
        sensor = Corr2Sensor.integer(
            name='%s-feng-rxtime48' % _f.host,
            description='F-engine %s - 48-bit timestamps received from '
                        'the digitisers' % _f.host,
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager)
        sensor_u = Corr2Sensor.integer(
            name='%s-feng-rxtime-unix' % _f.host,
            description='F-engine %s - UNIX timestamps received from '
                        'the digitisers' % _f.host,
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager)
        sensor_values[_f.host] = (sensor, sensor_u)
    ioloop.add_callback(_sensor_cb_feng_rxtime, sensor_ok, sensor_values)

    # f-engine lru
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-lru-ok' % _f.host,
            description='F-engine %s LRU okay' % _f.host,
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_cb_flru, sensor, _f)

    # x-engine lru
    for _x in sensor_manager.instrument.xhosts:
        executor = host_executors[_x.host]
        sensor = Corr2Sensor.boolean(
            name='%s-xeng-lru-ok' % _x.host,
            description='X-engine %s LRU okay' % _x.host,
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_cb_xlru, sensor, _x)

    # x-engine QDR errors
    for _x in sensor_manager.instrument.xhosts:
        executor = host_executors[_x.host]
        sensor = Corr2Sensor.boolean(
            name='%s-xeng-qdr-ok' % _x.host,
            description='X-engine QDR okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_xeng_qdr_okay, sensor, _x)

    # f-engine QDR errors
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-qdr-ok' % _f.host,
            description='F-engine QDR okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_feng_qdr_okay, sensor, _f)

    # x-engine PHY counters
    for _x in sensor_manager.instrument.xhosts:
        executor = host_executors[_x.host]
        sensor = Corr2Sensor.boolean(
            name='%s-xeng-phy-ok' % _x.host,
            description='X-engine PHY okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_xeng_phy, sensor, _x)

    # f-engine PHY counters
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-phy-ok' % _f.host,
            description='F-engine PHY okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_feng_phy, sensor, _f)

    # f-engine PFB counters
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-pfb-ok' % _f.host,
            description='F-engine PFB okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_feng_pfb_okay, sensor, _f)

    # f-engine raw rx - tengbe counters must increment
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-10gbe-rx-ok' % _f.host,
            description='F-engine 10gbe RX okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_fhost_check_10gbe_rx, sensor, _f)

    # f-engine raw tx - tengbe counters must increment
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-10gbe-tx-ok' % _f.host,
            description='F-engine 10gbe TX okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_fhost_check_10gbe_tx, sensor, _f)

    # x-engine raw rx - tengbe counters must increment
    for _x in sensor_manager.instrument.xhosts:
        executor = host_executors[_x.host]
        sensor = Corr2Sensor.boolean(
            name='%s-xeng-10gbe-rx-ok' % _x.host,
            description='X-engine 10gbe RX okay',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_xhost_check_10gbe_rx, sensor, _x)

    # x-engine raw tx - report tengbe counters
    for _x in sensor_manager.instrument.xhosts:
        executor = host_executors[_x.host]
        for gbe in _x.tengbes:
            sensor = Corr2Sensor.integer(
                name='%s-xeng-10gbe-%s-tx-ctr' % (_x.host, gbe.name),
                description='X-engine 10gbe TX counter',
                initial_status=Corr2Sensor.UNKNOWN,
                manager=sensor_manager, executor=executor)
            ioloop.add_callback(_xhost_report_10gbe_tx, sensor, _x, gbe)

    # f-engine rx reorder counters
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-reorder-ok' % _f.host,
            description='F-engine RX okay - reorder counters incrementing'
                        'correctly',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_feng_rx_reorder, sensor, _f)

    # x-engine rx reorder counters
    for _x in sensor_manager.instrument.xhosts:
        executor = host_executors[_x.host]
        sensor = Corr2Sensor.boolean(
            name='%s-xeng-reorder-ok' % _x.host,
            description='X-engine RX okay - reorder counters incrementing'
                        'correctly',
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_xeng_rx_reorder, sensor, _x)

    # f-engine delay functionality
    for _f in sensor_manager.instrument.fhosts:
        executor = host_executors[_f.host]
        sensor = Corr2Sensor.boolean(
            name='%s-feng-delays-ok' % _f.host,
            description='F-engine %s delay functionality' % _f.host,
            initial_status=Corr2Sensor.UNKNOWN,
            manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_cb_fdelays, sensor, _f)

    all_hosts = sensor_manager.instrument.fhosts + \
                sensor_manager.instrument.xhosts

    # tengbe packet-per-second counters
    for _h in all_hosts:
        executor = host_executors[_h.host]
        for tengbe in _h.tengbes:
            sensor = Corr2Sensor.integer(
                name='%s-%s-tx-pps-ctr' % (_h.host, tengbe.name),
                description='%s %s TX packet-per-second counter' % (
                    _h.host, tengbe.name),
                initial_status=Corr2Sensor.UNKNOWN,
                manager=sensor_manager, executor=executor)
            sensor.previous_value = 0
            sensor = Corr2Sensor.integer(
                name='%s-%s-rx-pps-ctr' % (_h.host, tengbe.name),
                description='%s %s RX packet-per-second counter' % (
                    _h.host, tengbe.name),
                initial_status=Corr2Sensor.UNKNOWN,
                manager=sensor_manager, executor=executor)
            sensor.previous_value = 0
            sensor = Corr2Sensor.string(
                name='%s-%s-link-status' % (_h.host, tengbe.name),
                description='%s %s link status' % (
                    _h.host, tengbe.name),
                initial_status=Corr2Sensor.UNKNOWN,
                manager=sensor_manager, executor=executor)
        ioloop.add_callback(_sensor_cb_pps, _h, executor, sensor_manager)

    # read all relevant counters
    for _h in all_hosts:
        executor = host_executors[_h.host]
        host_ctrs = read_all_counters(_h)
        for ctr in host_ctrs:
            sensor = Corr2Sensor.boolean(
                name='%s' % ctr,
                description='Counter on %s, True is changed since '
                            'last read' % _h.host,
                initial_status=Corr2Sensor.UNKNOWN,
                manager=sensor_manager, executor=executor)
            sensor.previous_value = 0
        ioloop.add_callback(_sensor_cb_system_counters,
                            _h, executor, sensor_manager)