diff --git a/WebApp/flask_app.py b/WebApp/flask_app.py index 9602178cb2c20c67a93546daa25fe6ac324eab40..9032d9f8700ec2e1146acc6e2c6ef641ac46c17d 100644 --- a/WebApp/flask_app.py +++ b/WebApp/flask_app.py @@ -1,7 +1,10 @@ import time import flask -def RunApp_Flask(address_table, q_read, q_write, q_read_resp, q_write_resp, port="8080", return_html=False): +from gevent.pywsgi import WSGIServer +from gevent.pool import Pool + +def RunApp_Flask(address_table, q_read, q_write, q_read_resp, q_write_resp, port="8080",address="0.0.0.0", return_html=False): app = flask.Flask(__name__) def wait_for_queue(queue): while True: @@ -53,6 +56,9 @@ def RunApp_Flask(address_table, q_read, q_write, q_read_resp, q_write_resp, port return write_request_get try: - app.run(port=int(port)) + pool = Pool(10) + http_server = WSGIServer((address, int(port)), app, spawn=pool) + http_server.serve_forever() + #app.run(port=int(port), host=address, debug=False) except KeyboardInterrupt: return diff --git a/address_table/address_table_kcu1500.json b/address_table/address_table_kcu1500.json index 41c69145e8241df580d77395e8f9b2cf283ddce4..bba28b7f10216d8e637702de019212f64439c2e4 100644 --- a/address_table/address_table_kcu1500.json +++ b/address_table/address_table_kcu1500.json @@ -4,124 +4,124 @@ "registers": { "cdr_stable": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 0, "metric": "gauge" }, "RxByteIsAligned": { "width": 8, - "location": "0x40", + "address": "0x40", "offset": 1, "metric": "gauge" }, "GtPowerGood": { "width": 8, - "location": "0x40", + "address": "0x40", "offset": 9, "metric": "gauge" }, "GtTxResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 17, "metric": "gauge" }, "GtRxResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 18, "metric": "gauge" }, "TxPmaResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 19, "metric": "gauge" }, "RxPmaResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 20, "metric": "gauge" }, "GtResetTxPllDatapath": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 21, "metric": "gauge" }, "GtResetTxDatapath": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 22, "metric": "gauge" }, "GtResetRxDatapath": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 23, "metric": "gauge" }, "InitDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 24, "metric": "gauge" }, "FreqInput": { "width": 32, - "location": "0x44", + "address": "0x44", "offset": 0, "metric": "gauge" }, "FillerOrbitsSeen": { "width": 32, - "location": "0x48", + "address": "0x48", "offset": 0, "metric": "counter" }, "FillerOrbitsDropped": { "width": 32, - "location": "0x4c", + "address": "0x4c", "offset": 0, "metric": "counter" }, "AxiBackpressureSeen": { "width": 1, - "location": "0x50", + "address": "0x50", "offset": 0, "metric": "gauge" }, "OrbitExceedsSize": { "width": 1, - "location": "0x50", + "address": "0x50", "offset": 1, "metric": "gauge" }, "WaitingForOrbitEnd": { "width": 1, - "location": "0x50", + "address": "0x50", "offset": 2, "metric": "gauge" }, "I2CvalueRead": { "width": 8, - "location": "0x50", + "address": "0x50", "offset": 3, "metric": "gauge" }, "Autorealigns": { "width": 32, - "location": "0x54", + "address": "0x54", "offset": 0, "metric": "counter" }, "OrbitLength": { "width": 32, - "location": "0x58", + "address": "0x58", "offset": 0, "metric": "gauge" } } } -} \ No newline at end of file +} diff --git a/address_table/address_table_kcu1500_64shift.json b/address_table/address_table_kcu1500_64shift.json index bf80ad3f342a8b946fc4745b7cb806fb0fcabee2..211c4e54845f302011a7a16e218a14146bbef940 100644 --- a/address_table/address_table_kcu1500_64shift.json +++ b/address_table/address_table_kcu1500_64shift.json @@ -4,124 +4,124 @@ "registers": { "cdr_stable": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 0, "metric": "gauge" }, "RxByteIsAligned": { "width": 8, - "location": "0x40", + "address": "0x40", "offset": 1, "metric": "gauge" }, "GtPowerGood": { "width": 8, - "location": "0x40", + "address": "0x40", "offset": 9, "metric": "gauge" }, "GtTxResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 17, "metric": "gauge" }, "GtRxResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 18, "metric": "gauge" }, "TxPmaResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 19, "metric": "gauge" }, "RxPmaResetDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 20, "metric": "gauge" }, "GtResetTxPllDatapath": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 21, "metric": "gauge" }, "GtResetTxDatapath": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 22, "metric": "gauge" }, "GtResetRxDatapath": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 23, "metric": "gauge" }, "InitDone": { "width": 1, - "location": "0x40", + "address": "0x40", "offset": 24, "metric": "gauge" }, "FreqInput": { "width": 32, - "location": "0x44", + "address": "0x44", "offset": 0, "metric": "counter" }, "FillerOrbitsSeen": { "width": 32, - "location": "0x48", + "address": "0x48", "offset": 0, "metric": "counter" }, "FillerOrbitsDropped": { "width": 32, - "location": "0x4c", + "address": "0x4c", "offset": 0, "metric": "counter" }, "AxiBackpressureSeen": { "width": 1, - "location": "0x50", + "address": "0x50", "offset": 0, "metric": "gauge" }, "OrbitExceedsSize": { "width": 1, - "location": "0x50", + "address": "0x50", "offset": 1, "metric": "gauge" }, "WaitingForOrbitEnd": { "width": 1, - "location": "0x50", + "address": "0x50", "offset": 2, "metric": "counter" }, "I2CvalueRead": { "width": 8, - "location": "0x50", + "address": "0x50", "offset": 3, "metric": "gauge" }, "Autorealigns": { "width": 32, - "location": "0x54", + "address": "0x54", "offset": 0, "metric": "counter" }, "OrbitLength": { "width": 32, - "location": "0x58", + "address": "0x58", "offset": 0, "metric": "counter" } } } -} \ No newline at end of file +} diff --git a/address_table/address_table_kcu1500_64shift_rw.json b/address_table/address_table_kcu1500_64shift_rw.json index b6f67c2b00e6510179aded6c079212afe13be1b0..f22a76cd13268f46e1654f3f1837b0d3b9a4f00a 100644 --- a/address_table/address_table_kcu1500_64shift_rw.json +++ b/address_table/address_table_kcu1500_64shift_rw.json @@ -2,370 +2,386 @@ "kcu1500_ugmt": { "driver": "/dev/wz-xdma0_user", "registers": { - "scoutGmt_cdr_stable_info": { + "link_enable": { + "width": 8, + "address": "0x8", + "offset": 0, + "metric": "gauge", + "writable": true, + "exposable": true + }, + "cdr_stable_info": { "width": 1, "address": "0x40", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_rx_byte_is_aligned_info": { + "rx_byte_is_aligned_info": { "width": 8, "address": "0x40", "offset": 1, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_gt_power_good_info": { + "gt_power_good_info": { "width": 8, "address": "0x40", "offset": 9, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutGmt_gt_tx_reset_done_info": { + "gt_tx_reset_done_info": { "width": 1, "address": "0x40", "offset": 17, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutGmt_gt_rx_reset_done_info": { + "gt_rx_reset_done_info": { "width": 1, "address": "0x40", "offset": 18, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutGmt_tx_pma_reset_done_info": { + "tx_pma_reset_done_info": { "width": 1, "address": "0x40", "offset": 19, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_rx_pma_reset_done_info": { + "rx_pma_reset_done_info": { "width": 1, "address": "0x40", "offset": 20, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_gt_reset_tx_pll_datapath_info": { + "gt_reset_tx_pll_datapath_info": { "width": 1, "address": "0x40", "offset": 21, "metric": "gauge", - "writable": 1, - "exposable": 0 + "writable": true, + "exposable": false }, - "scoutGmt_gt_reset_tx_datapath_info": { + "gt_reset_tx_datapath_info": { "width": 1, "address": "0x40", "offset": 22, "metric": "gauge", - "writable": 1, - "exposable": 0 + "writable": true, + "exposable": false }, - "scoutGmt_gt_reset_rx_datapath_info": { + "gt_reset_rx_datapath_info": { "width": 1, "address": "0x40", "offset": 23, "metric": "gauge", - "writable": 1, - "exposable": 0 + "writable": true, + "exposable": false }, - "scoutGmt_init_done_info": { + "init_done_info": { "width": 1, "address": "0x40", "offset": 24, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutGmt_frequency_input_hertz": { + "frequency_input_hertz": { "width": 32, "address": "0x44", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_filler_orbits_seen_orbits": { + "filler_orbits_seen_orbits": { "width": 32, "address": "0x48", "offset": 0, "metric": "counter", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_filler_orbits_dropped_orbits": { + "filler_orbits_dropped_orbits": { "width": 32, "address": "0x4c", "offset": 0, "metric": "counter", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_axi_backpressure_seen_info": { + "axi_backpressure_seen_info": { "width": 1, "address": "0x50", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_orbit_exceeds_size_info": { + "orbit_exceeds_size_info": { "width": 1, "address": "0x50", "offset": 1, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_waiting_for_orbit_end_info": { + "waiting_for_orbit_end_info": { "width": 1, "address": "0x50", "offset": 2, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutGmt_i2c_value_read_info": { + "i2c_value_read_info": { "width": 8, "address": "0x50", "offset": 3, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_autorealigns_total": { + "autorealigns_total": { "width": 32, "address": "0x54", "offset": 0, "metric": "counter", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutGmt_orbit_length_bxs": { + "orbit_length_bxs": { "width": 32, "address": "0x58", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true } } }, "kcu1500_demux": { "driver": "/dev/wz-xdma0_user", "registers": { - "scoutDemux_zs_threhold_eg_0p5GeV": { + "zs_threhold_eg_0p5GeV": { "width": 9, "address": "0x0", "offset": 0, "metric": "gauge", - "writable": 1, - "exposable": 1 + "writable": true, + "exposable": true }, - "scoutDemux_zs_threhold_jet_0p5GeV": { + "zs_threhold_jet_0p5GeV": { "width": 9, "address": "0x0", "offset": 9, "metric": "gauge", - "writable": 1, - "exposable": 1 + "writable": true, + "exposable": true }, - "scoutDemux_zs_threhold_tau_0p5GeV": { + "zs_threhold_tau_0p5GeV": { "width": 9, "address": "0x4", "offset": 0, "metric": "gauge", - "writable": 1, - "exposable": 1 + "writable": true, + "exposable": true }, - "scoutDemux_zs_threhold_sum_0p5GeV": { + "zs_threhold_sum_0p5GeV": { "width": 9, "address": "0x4", "offset": 9, "metric": "gauge", - "writable": 1, - "exposable": 1 + "writable": true, + "exposable": true }, - "scoutDemux_zs_threhold_empty_0p5GeV": { + "zs_threhold_empty_0p5GeV": { "width": 9, "address": "0x4", "offset": 18, "metric": "gauge", - "writable": 1, - "exposable": 1 + "writable": true, + "exposable": true + }, + "link_enable": { + "width": 8, + "address": "0x8", + "offset": 0, + "metric": "gauge", + "writable": true, + "exposable": true }, - "scoutDemux_cdr_stable_info": { + "cdr_stable_info": { "width": 1, "address": "0x40", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_rx_byte_is_aligned_info": { + "rx_byte_is_aligned_info": { "width": 8, "address": "0x40", "offset": 1, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_gt_power_good_info": { + "gt_power_good_info": { "width": 8, "address": "0x40", "offset": 9, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutDemux_gt_tx_reset_done_info": { + "gt_tx_reset_done_info": { "width": 1, "address": "0x40", "offset": 17, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutDemux_gt_rx_reset_done_info": { + "gt_rx_reset_done_info": { "width": 1, "address": "0x40", "offset": 18, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutDemux_tx_pma_reset_done_info": { + "tx_pma_reset_done_info": { "width": 1, "address": "0x40", "offset": 19, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_rx_pma_reset_done_info": { + "rx_pma_reset_done_info": { "width": 1, "address": "0x40", "offset": 20, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_gt_reset_tx_pll_datapath_info": { + "gt_reset_tx_pll_datapath_info": { "width": 1, "address": "0x40", "offset": 21, "metric": "gauge", - "writable": 1, - "exposable": 0 + "writable": true, + "exposable": false }, - "scoutDemux_gt_reset_tx_datapath_info": { + "gt_reset_tx_datapath_info": { "width": 1, "address": "0x40", "offset": 22, "metric": "gauge", - "writable": 1, - "exposable": 0 + "writable": true, + "exposable": false }, - "scoutDemux_gt_reset_rx_datapath_info": { + "gt_reset_rx_datapath_info": { "width": 1, "address": "0x40", "offset": 23, "metric": "gauge", - "writable": 1, - "exposable": 0 + "writable": true, + "exposable": false }, - "scoutDemux_init_done_info": { + "init_done_info": { "width": 1, "address": "0x40", "offset": 24, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutDemux_frequency_input_hertz": { + "frequency_input_hertz": { "width": 32, "address": "0x44", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_filler_orbits_seen_orbits": { + "filler_orbits_seen_orbits": { "width": 32, "address": "0x48", "offset": 0, "metric": "counter", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_filler_orbits_dropped_orbits": { + "filler_orbits_dropped_orbits": { "width": 32, "address": "0x4c", "offset": 0, "metric": "counter", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_axi_backpressure_seen_info": { + "axi_backpressure_seen_info": { "width": 1, "address": "0x50", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_orbit_exceeds_size_info": { + "orbit_exceeds_size_info": { "width": 1, "address": "0x50", "offset": 1, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_waiting_for_orbit_end_info": { + "waiting_for_orbit_end_info": { "width": 1, "address": "0x50", "offset": 2, "metric": "gauge", - "writable": 0, - "exposable": 0 + "writable": false, + "exposable": false }, - "scoutDemux_i2c_value_read_info": { + "i2c_value_read_info": { "width": 8, "address": "0x50", "offset": 3, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_autorealigns_total": { + "autorealigns_total": { "width": 32, "address": "0x54", "offset": 0, "metric": "counter", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true }, - "scoutDemux_orbit_length_bxs": { + "orbit_length_bxs": { "width": 32, "address": "0x58", "offset": 0, "metric": "gauge", - "writable": 0, - "exposable": 1 + "writable": false, + "exposable": true } } } diff --git a/address_table/addrtab_example.json b/address_table/addrtab_example.json index bcda286f774390882eb1a8b81000428b793b365f..c65c3a475429bdfdc561656e3f5c94070a810d06 100644 --- a/address_table/addrtab_example.json +++ b/address_table/addrtab_example.json @@ -3,17 +3,17 @@ "registers": { "register0": { "width": 10, - "location": "0x00000000", + "address": "0x00000000", "offset": 0 }, "register1": { "width": 20, - "location": "0x00000000", + "address": "0x00000000", "offset": 10 }, "register10": { "width": 16, - "location": "0x00000000", + "address": "0x00000000", "offset": 2 } }, @@ -23,12 +23,12 @@ "registers": { "register0": { "width": 32, - "location": "0x00000000", + "address": "0x00000000", "offset": 0 }, "register1": { "width": 2, - "location": "0x00000004", + "address": "0x00000004", "offset": 30 } }, diff --git a/address_table/addrtab_to_vhdl.py b/address_table/addrtab_to_vhdl.py index ee03522b03db0dcb4435631a36ee2367a9bbad7c..689f67b234044655d2190a7c0d18fda08de8f628 100755 --- a/address_table/addrtab_to_vhdl.py +++ b/address_table/addrtab_to_vhdl.py @@ -23,7 +23,7 @@ def main(addrtab, reg_name): f.write(vhdl_header) for reg in registers: reg_info = registers[reg] - f.write('constant ' + reg + '_addr : natural := ' + str(int(reg_info['location'], 16)//4) + ';\n') + f.write('constant ' + reg + '_addr : natural := ' + str(int(reg_info['address'], 16)//4) + ';\n') f.write('constant ' + reg + '_offset : natural := ' + str(reg_info['offset']) + ';\n') f.write('constant ' + reg + '_width : natural := ' + str(reg_info['width']) + ';\n') f.write(vhdl_trailer) diff --git a/l1scout_monitoring.py b/l1scout_monitoring.py index 6341be37ba2fb872bda670fa75c51037c5e62dcf..163f01a34a705e0aab658e8639d996028f544e07 100644 --- a/l1scout_monitoring.py +++ b/l1scout_monitoring.py @@ -38,54 +38,6 @@ def dump_garbage( ): print(type(x),"\n ", s) return -def update_metric(metric, register, metric_type, value, previous_read_values): - if metric_type =='gauge': - metric.labels(register).set(value) - return 1 - elif metric_type =='counter': - previous_value = 0 - if register in previous_read_values.keys(): - previous_value = previous_read_values[register] - if (value-previous_value)>=0: - metric.labels(register).inc(value-previous_value) - del previous_value - gc.collect() - return 1 - else: - metric.labels(register).inc(value) - del previous_value - gc.collect() - return -1 - else: - return -2 - -def update_history(dictionary, register, value): - dictionary[register] = value - return - -def monitoring_board(config_json, board, metrics, device, previous_read_values, dump=0, verbose=False, logging=None): - for reg in config_json[board]["registers"]: - location = config_json[board]["registers"][reg]["location"] - width = config_json[board]["registers"][reg]["width"] - offset = config_json[board]["registers"][reg]["offset"] - metric = config_json[board]["registers"][reg]["metric"] - read_val = rw.ReadProperty(device, location, offset, width, verbose=verbose, logging=logging) - - logging.info("%s\tloc: %s\toffset: %s\twidth: %s\t--> value: %i (%s)"%(reg,location,offset,width,read_val,bin(read_val))) - if dump: - print("%s\tloc: %s\toffset: %s\twidth: %s\t--> value: %i (%s)"%(reg,location,offset,width,read_val,bin(read_val))) - isUpdate = update_metric(metrics[metric], metric_type=metric, value=read_val, register=reg, previous_read_values=previous_read_values) - - if isUpdate==-2: - logging.warning('Unrecognized metric %s for register %s on board %s. Available metrics: gauge, counter.'%(metric, reg, board)) - elif isUpdate==-1: - logging.info('Counter %s on board %s has been reset'%(reg, board)) - - update_history(dictionary=previous_read_values, register=reg, value=read_val) - del location, width, offset, metric, read_val, isUpdate - gc.collect() - return - def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=10, width=100) @@ -125,36 +77,11 @@ if __name__ == '__main__': dump = args.dump board = args.board del args, parser + metrics_board_dict = {} previous_read_values_board = {} - if board in config_json: - # display only one board - device = str(config_json[board]["driver"]) - logging.info("board %s (driver %s)"%(board, device)) - metrics_dict = {} - for reg in config_json[board]["registers"]: - metric = config_json[board]["registers"][reg]["metric"] - if metric == 'gauge': - metrics_dict[reg] = Gauge(reg, board) - elif metric == 'counter': - metrics_dict[reg] = Counter(reg, board) - metrics_board_dict[board]=metrics_dict - previous_read_values_board[board] = {} - while True: - monitoring_board(config_json, board, metrics_board_dict[board], device, previous_read_values=previous_read_values_board, dump=dump, verbose=verbose, logging=logging) - gc.collect() - if mem_debug: - memory_avg, memory_max= tracemalloc.get_traced_memory() - if memory_avg > memory: - print(datetime.datetime.now()) - print(f"Current memory usage is {memory_avg / 10**6}MB; Peak was {memory_max / 10**6}MB") - memory = memory_avg - - time.sleep(timesleep) - else: - logging.warning("The argument 'board' (-b) has not been specified. The monitoring process will loop over all the boards included in the address ta\ -ble.") - # loop over all the boards: + if board==None: + logging.warning("The argument 'board' (-b) has not been specified. The monitoring process will loop over all the boards included in the address table.") for board in config_json: metrics_dict = {} for reg in config_json[board]["registers"]: @@ -163,19 +90,45 @@ ble.") metrics_dict[reg] = Gauge(reg, board) elif metric == 'counter': metrics_dict[reg] = Counter(reg, board) + metrics_board_dict[board]=metrics_dict previous_read_values_board[board] = {} + else: + metrics_dict = {} + for reg in config_json[board]["registers"]: + metric = config_json[board]["registers"][reg]["metric"] + if metric == 'gauge': + metrics_dict[reg] = Gauge(reg, board) + elif metric == 'counter': + metrics_dict[reg] = Counter(reg, board) + + metrics_board_dict[board]=metrics_dict + previous_read_values_board[board] = {} + + while True: - for board in config_json: - device = str(config_json[board]["driver"]) + # monitoring metrics + if board==None: + for board in config_json: + device = str(config_json[board]["driver"]) + logging.info("board %s (driver %s)"%(board, device)) + prometheus_monitoring.monitoring_board(config_json, board, metrics_board_dict[board], device, + previous_read_values=previous_read_values_board[board], + dump=dump, verbose=verbose, logging=logging) + gc.collect() + else: + device = str(config_json[board]["driver"]) logging.info("board %s (driver %s)"%(board, device)) - monitoring_board(config_json, board, metrics_board_dict[board], device, previous_read_values=previous_read_values_board[board], dump=dump, verbose=verbose, logging=logging) + prometheus_monitoring.monitoring_board(config_json, board, metrics_board_dict[board], device, + previous_read_values=previous_read_values_board[board], + dump=dump, verbose=verbose, logging=logging) gc.collect() + if mem_debug: - memory_avg, memory_max = tracemalloc.get_traced_memory() - if memory_avg >memory: + memory_avg, memory_max= tracemalloc.get_traced_memory() + if memory_avg > memory: print(datetime.datetime.now()) - print(f"Current memory usage is {memory_avg / 10**6}MB; Peak was {memory_max / 10**6}MB") + print("Current memory usage is {memory_avg / 10**6}MB; Peak was {memory_max / 10**6}MB") memory = memory_avg time.sleep(timesleep) diff --git a/l1scout_monitoring_and_control.py b/l1scout_monitoring_and_control.py index 1c290f6544db8517dfa8ca984e8d3931ed6dcc0d..099f4aa72032e78fcb66c832038fac067e8d8287 100644 --- a/l1scout_monitoring_and_control.py +++ b/l1scout_monitoring_and_control.py @@ -44,8 +44,8 @@ def dump_garbage( ): return ###### control app process -def Control_process(address_table, q_read, q_write, q_read_resp, q_write_resp, port="8080"): - return flask_app.RunApp_Flask(address_table, q_read, q_write, q_read_resp, q_write_resp, port="8080") +def Control_process(address_table, q_read, q_write, q_read_resp, q_write_resp, port, address): + return flask_app.RunApp_Flask(address_table, q_read, q_write, q_read_resp, q_write_resp, port=port, address=address) ###### parser formatter def formatter(prog): @@ -64,18 +64,23 @@ if __name__ == '__main__': parser.add_argument('-e', '--errfile', type=str, help="debugfile", required=False) parser.add_argument('-m', '--mem_debug', type=str, help="print memory tracing for debug", required=False, default=0) parser.add_argument('-t', '--timesleep', type=float, help="seconds before updating", required=False, default=5) + parser.add_argument('-p', '--portwebapp', type=str, help="Web App port", required=False, default="8080") + parser.add_argument('-a', '--addresswebapp', type=str, help="Web App address", required=False, default="0.0.0.0") args = parser.parse_args() timesleep = args.timesleep - + port = args.portwebapp + address = args.addresswebapp + dump = args.dump + board = args.board + with open(args.jsonfile, 'r') as jsonfile: + config_json = json.load(jsonfile) if args.logfile: logging.basicConfig(filename=args.logfile, format='%(levelname)s:%(message)s', level=logging.INFO) if args.errfile: logging.basicConfig(filename=args.errfile, format='%(levelname)s:%(message)s', level=logging.DEBUG) - - with open(args.jsonfile, 'r') as jsonfile: - config_json = json.load(jsonfile) + mem_debug = False if args.mem_debug: mem_debug = True @@ -84,12 +89,16 @@ if __name__ == '__main__': memory = 0 verbose = 0 if args.errfile: verbose = 1 - dump = args.dump - board = args.board del args, parser + if board not in list(config_json.keys()) and not board==None: + string_boards = "" + for b in list(config_json.keys()): string_boards +='%s '%(b) + logging.error("Board not recognised. List of available boards: %s"%(string_boards)) + exit() + q_write, q_read, q_read_resp, q_write_resp = mp.Queue(), mp.Queue(), mp.Queue(), mp.Queue() - p = mp.Process(target=Control_process, args=(config_json, q_read, q_write, q_read_resp, q_write_resp,)) + p = mp.Process(target=Control_process, args=(config_json, q_read, q_write, q_read_resp, q_write_resp,port, address,)) p.start() metrics_board_dict = {} @@ -101,9 +110,9 @@ if __name__ == '__main__': for reg in config_json[board]["registers"]: metric = config_json[board]["registers"][reg]["metric"] if metric == 'gauge': - metrics_dict[reg] = Gauge(reg, board) + metrics_dict[reg] = Gauge("%s_%s"%(board, reg), "%s_%s"%(board, reg)) elif metric == 'counter': - metrics_dict[reg] = Counter(reg, board) + metrics_dict[reg] = Counter("%s_%s"%(board, reg), "%s_%s"%(board, reg)) metrics_board_dict[board]=metrics_dict previous_read_values_board[board] = {} @@ -112,30 +121,32 @@ if __name__ == '__main__': for reg in config_json[board]["registers"]: metric = config_json[board]["registers"][reg]["metric"] if metric == 'gauge': - metrics_dict[reg] = Gauge(reg, board) + metrics_dict[reg] = Gauge("%s_%s"%(board, reg), "%s_%s"%(board, reg)) elif metric == 'counter': - metrics_dict[reg] = Counter(reg, board) + metrics_dict[reg] = Counter("%s_%s"%(board, reg), "%s_%s"%(board, reg)) metrics_board_dict[board]=metrics_dict previous_read_values_board[board] = {} + try: while True: # check for reading requests while not q_read.empty(): read_request = q_read.get() status = "request received" - if not config_json[read_request['board']]['registers'][read_request['register']]: - status = "400" - message = "bad request: register not available" + if not read_request['register'] in config_json[read_request['board']]['registers']: + status = "400" + message = "bad request: register not available" + read_val = -1 else: board = read_request['board'] register = read_request['register'] device = config_json[board]["driver"] - location = config_json[board]["registers"][register]["location"] + address = config_json[board]["registers"][register]["address"] width = config_json[board]["registers"][register]["width"] offset = config_json[board]["registers"][register]["offset"] - read_val = rw.ReadProperty(device, location, offset, width, verbose=verbose, logging=logging) + read_val = rw.ReadProperty(device, address, offset, width, verbose=verbose, logging=logging) if read_val==-1: status = "500" message = 'Internal Server Error: an error occurred when trying to perform the ReadProperty function' @@ -146,27 +157,29 @@ if __name__ == '__main__': # check for writing requests while not q_write.empty(): write_request = q_write.get() - if not config_json[write_request['board']]['registers'][write_request['register']]: - status = "400" - message = "bad request: register not available" + if not write_request['register'] in config_json[write_request['board']]['registers']: + status = "400" + message = "bad request: register not available" + write_val = -1 elif not config_json[write_request['board']]['registers'][write_request['register']]['writable']: - status = "400" - message = "bad request: register not writable" + status = "400" + message = "bad request: register not writable" + write_val = -1 else: - board = write_request['board'] - register = write_request['register'] - value = write_request['value'] - device = config_json[board]["driver"] - location = config_json[board]["registers"][register]["location"] - width = config_json[board]["registers"][register]["width"] - offset = config_json[board]["registers"][register]["offset"] - write_val= rw.WriteProperty(device, location, offset, width, int(value), logging=logging) + board = write_request['board'] + register = write_request['register'] + value = write_request['value'] + device = config_json[board]["driver"] + address = config_json[board]["registers"][register]["address"] + width = config_json[board]["registers"][register]["width"] + offset = config_json[board]["registers"][register]["offset"] + write_val = rw.WriteProperty(device, address, offset, width, int(value), logging=logging) if write_val==-1: status = "500" message = 'Internal Server Error: an error occurred when trying to perform the WriteProperty function' else: - status = "200" - message = 'success' + status = "200" + message = 'success' q_write_resp.put({'value':write_request['value'], 'status':status, 'message':message}) # monitoring metrics @@ -188,7 +201,7 @@ if __name__ == '__main__': print(datetime.datetime.now()) print(f"Current memory usage is {memory_avg / 10**6}MB; Peak was {memory_max / 10**6}MB") memory = memory_avg - + time.sleep(timesleep) except KeyboardInterrupt: diff --git a/main.py b/main.py index 6938eb40edfeedb74854f71391131ac0a1d777a3..adbdac27ca342ab9bfeaa301a935f0b29338e709 100644 --- a/main.py +++ b/main.py @@ -46,7 +46,7 @@ if __name__ == '__main__': exit() device = str(config_json[board]["driver"]) - location = config_json[board]["registers"][reg]["location"] + address = config_json[board]["registers"][reg]["address"] offset = config_json[board]["registers"][reg]["offset"] width = config_json[board]["registers"][reg]["width"] action = args.action @@ -70,7 +70,7 @@ if __name__ == '__main__': logging.error("action 'set' requires the optional argument --value (-v).") logging.info("board: %s (driver %s)"%(board, device)) logging.info("register: %s"%(reg)) - logging.info("location: %s"%(location)) + logging.info("address: %s"%(address)) logging.info("offset: %i"%(offset)) logging.info("width: %i"%(width)) logging.info("action: %s"%(action)) @@ -79,10 +79,10 @@ if __name__ == '__main__': nbits_allowed = width # number of allowed bits nbits_write = value.bit_length() # number of bits needed if nbits_write > nbits_allowed: - logging.error("Overflow error! value %s doesn't fit in the allowed memory location."%(args.value)) + logging.error("Overflow error! value %s doesn't fit in the allowed memory address."%(args.value)) logging.info("board: %s (driver %s)"%(board, device)) logging.info("register: %s"%(reg)) - logging.info("location: %s"%(location)) + logging.info("address: %s"%(address)) logging.info("offset: %i"%(offset)) logging.info("width: %i"%(width)) logging.info("action: %s"%(action)) @@ -90,22 +90,22 @@ if __name__ == '__main__': else: writevalue = ctypes.c_uint(value) #unsigned int (32 bits) - output = rw.WriteProperty(device, location, offset, width, writevalue, verbose=verbose, logging=logging) + output = rw.WriteProperty(device, address, offset, width, writevalue, verbose=verbose, logging=logging) if output == -1: logging.error('The value could not be updated.') else: - logging.info('Set register %s from location %s on %s: %i'%(reg, location, board, writevalue.value)) + logging.info('Set register %s from address %s on %s: %i'%(reg, address, board, writevalue.value)) elif action == "get": - output = rw.ReadProperty(device, location, offset, width, verbose=verbose, logging=logging) + output = rw.ReadProperty(device, address, offset, width, verbose=verbose, logging=logging) if output == -1: logging.error('The register could not be read.') else: - logging.info('Get register %s from location %s on %s: %i'%(reg, location, board, output)) + logging.info('Get register %s from address %s on %s: %i'%(reg, address, board, output)) logging.info("board: %s (driver %s)"%(board, device)) logging.info("register: %s"%(reg)) - logging.info("location: %s"%(location)) + logging.info("address: %s"%(address)) logging.info("offset: %i"%(offset)) logging.info("width: %i"%(width)) logging.info("action: %s"%(action)) diff --git a/package/package.spec b/package/package.spec index e58db262de9389fb9e3567012afec0a6d74420b2..12aa3043a76188d481de07afbb709bdb68f42981 100644 --- a/package/package.spec +++ b/package/package.spec @@ -23,22 +23,21 @@ Source: %{name}.tar ExclusiveOs: linux Provides: daq-scone Requires: python36 -#removed: python-beaker (not used) python(2)-ldap, python-jsonschema, flask via flask-debugtoolbar, sqlalchemy, python-sqlalchemy, python-flask-sqlalchemy (obtained with pip3), + Prefix: %{_prefix} %description CMS Hardware Access Layer API application. -%files +%files %defattr(-,root,root,-) %attr(-, scouter, root) %dir %{_prefix} %attr(-, scouter, root) %dir %{_prefix}/logs %attr(-, scouter, root) %dir %{_homedir} %attr(-, scouter, root) %{_homedir}/* - %prep -%setup -c +%setup -c %build @@ -57,14 +56,7 @@ cd $RPM_BUILD_ROOT%{_homedir}/address_table/ %clean [ $RPM_BUILD_ROOT != / ] && rm -rf $RPM_BUILD_ROOT || : - %pre - -# Backup config file if exists +# Backup config file if exists [ -f "%{_configf}" -o -L "%{_configf}" ] && mv "%{_configf}" "%{_configb}.`date +%Y-%m-%dT%T`" || : - %post - - - - diff --git a/package/release_notes.sh b/package/release_notes.sh index 65b7bea583d23f9f7bff0e1038dd82352a1ea124..9cc8e5e95277d4b8ccaa7b362aacfb2ea622edc1 100644 --- a/package/release_notes.sh +++ b/package/release_notes.sh @@ -1,10 +1,10 @@ -#!/bin/bash +#!/bin/bash t2=HEAD tp=`git describe --tags --abbrev=0` t=0 -for t1 in `git tag | tac`; do +for t1 in `git tag | tac`; do c=`git --no-pager log ${t1}..${t2} --pretty=format:"%h %s" | wc -c` diff --git a/requirements.txt b/requirements.txt index 110c3f69fb42267fcde0047ebf9002c56aa8b973..cb70e7a17d49ea6519c0330e9195ec409e32ef53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask==1.1.2 jsonschema==3.2.0 flask-debugtoolbar==0.11.0 - +gevent==21.12.0 +prometheus_client