def main(): args = get_argparser().parse_args() init_logger_from_args(args) next_poll_time = time.monotonic() while True: time.sleep(max(0, next_poll_time - time.monotonic())) next_poll_time += args.poll_time measurements = [] for server in args.server: try: client = RPCClient(server, 3251, timeout=args.timeout) lasers = client.get_laser_db() for laser in lasers: meas = client.get_freq(laser, age=args.poll_time, priority=3, get_osa_trace=False, blocking=True, mute=False, offset_mode=False) status, freq, _ = meas if status != WLMMeasurementStatus.OKAY: logger.info("{}: measurement error") continue f_ref = lasers[laser]["f_ref"] delta = freq - lasers[laser]["f_ref"] measurements.append({ "measurement": laser, "fields": { "freq": freq, "f_ref": f_ref, "detuning": delta } }) logger.info("{}: freq {} THz, f_ref {} THz, " "detuning {} MHz".format( laser, freq, f_ref, delta)) except OSError: logger.warning("Error querying server {}".format(server)) finally: client.close_rpc() if not measurements: continue try: influx = influxdb.InfluxDBClient(host=args.host_db, database=args.database, username=args.user_db, password=args.password_db) influx.write_points(measurements) finally: influx.close()
def main(): args = get_argparser().parse_args() init_logger_from_args(args) servers = { idx: { "host": ip, "notify": 3250, "control": 3251 } for idx, ip in enumerate(args.server)} while True: measurements = [] for _, server in servers.items(): try: client = RPCClient(server["host"], server["control"]) lasers = client.get_laser_db() for laser in lasers: meas = client.get_freq(laser, age=args.poll_time, priority=3, get_osa_trace=False, blocking=True, mute=False, offset_mode=False) status, freq, _ = meas if status != WLMMeasurementStatus.OKAY: logger.info("{}: measurement error") continue f_ref = lasers[laser]["f_ref"] delta = freq - lasers[laser]["f_ref"] measurements.append({ "measurement": laser, "fields": { "freq": freq, "f_ref": f_ref, "detuning": delta } }) logger.info("{}: freq {} THz, f_ref {} THz, " "detuning {} MHz".format(laser, freq, f_ref, delta)) except OSError: logger.warning("Error querying server {}".format(server)) finally: client.close_rpc() if measurements == []: time.sleep(args.poll_time) continue try: influx = influxdb.InfluxDBClient( host="10.255.6.4", database=args.database, username="******", password="******") influx.write_points(measurements) finally: influx.close() time.sleep(args.poll_time)