|
|
|
|
@ -1,12 +1,16 @@
|
|
|
|
|
import os
|
|
|
|
|
import io
|
|
|
|
|
import csv
|
|
|
|
|
import time
|
|
|
|
|
import itertools
|
|
|
|
|
import requests
|
|
|
|
|
import numpy as np
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_telemetry_error_last_ts = 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pack_elems(names, file_types, *elems):
|
|
|
|
|
if len(names) != len(file_types) or len(names) != len(elems):
|
|
|
|
|
raise ValueError('Длин массивов имен и типов файлов и не совпадает с количество элементов для сохранения')
|
|
|
|
|
@ -49,7 +53,6 @@ def send_data(data, localhost, localport, endpoint):
|
|
|
|
|
if response.status_code == 404 and fallback_port and str(localport) != str(fallback_port):
|
|
|
|
|
response_fb, url_fb = _post(fallback_port)
|
|
|
|
|
if response_fb.status_code == 200:
|
|
|
|
|
#print("Данные успешно отправлены и приняты!", url_fb)
|
|
|
|
|
return
|
|
|
|
|
print("Ошибка при отправке данных:", response_fb.status_code, url_fb)
|
|
|
|
|
return
|
|
|
|
|
@ -59,6 +62,37 @@ def send_data(data, localhost, localport, endpoint):
|
|
|
|
|
print(str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_telemetry(data, host, port, endpoint='telemetry', timeout_sec=0.30):
|
|
|
|
|
"""
|
|
|
|
|
Best-effort отправка телеметрии на отдельный telemetry-server.
|
|
|
|
|
Ошибки намеренно не пробрасываются, чтобы не влиять на основной детект/аларм поток.
|
|
|
|
|
"""
|
|
|
|
|
global _telemetry_error_last_ts
|
|
|
|
|
|
|
|
|
|
host = '' if host is None else str(host).strip()
|
|
|
|
|
port = '' if port is None else str(port).strip()
|
|
|
|
|
endpoint = str(endpoint or 'telemetry').strip().lstrip('/')
|
|
|
|
|
|
|
|
|
|
if not host or not port:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
url = f"http://{host}:{port}/{endpoint}"
|
|
|
|
|
response = requests.post(url, json=data, timeout=float(timeout_sec))
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
now = time.time()
|
|
|
|
|
if now - _telemetry_error_last_ts >= 10.0:
|
|
|
|
|
print(f"telemetry http error: {response.status_code} {url}")
|
|
|
|
|
_telemetry_error_last_ts = now
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
now = time.time()
|
|
|
|
|
if now - _telemetry_error_last_ts >= 10.0:
|
|
|
|
|
print(f"telemetry send failed: {exc}")
|
|
|
|
|
_telemetry_error_last_ts = now
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_data(path_to_save, freq, *args):
|
|
|
|
|
"""
|
|
|
|
|
Сохранение данных в csv файл. Используется для сохранения метрик и медиан сигнала на каналах с датой и временем
|
|
|
|
|
|