feat: align wired network card and collect traffic history

This commit is contained in:
way
2026-10-14 23:43:41 +08:00
parent 6a66a48a51
commit f576114db1
6 changed files with 19 additions and 5 deletions
+6
View File
@@ -2,6 +2,7 @@
"""Official Raspberry Pi adapter. This process alone knows Agent endpoints/authentication."""
import concurrent.futures
import json
import math
import sys
import threading
from pathlib import Path
@@ -74,6 +75,11 @@ def collect(device):
speed = value.get('network', {}).get('link_speed_mbps')
if isinstance(speed, (int, float)) and not isinstance(speed, bool):
metrics.append({'resource_id': 'host', 'key': 'network_link_speed_mbps', 'value': speed, 'unit': 'megabits_per_second'})
for field, key in (('rx_bytes_per_second', 'network_rx_bytes_per_second'),
('tx_bytes_per_second', 'network_tx_bytes_per_second')):
rate = value.get('network', {}).get(field)
if isinstance(rate, (int, float)) and not isinstance(rate, bool) and math.isfinite(rate) and rate >= 0:
metrics.append({'resource_id': 'host', 'key': key, 'value': rate, 'unit': 'bytes_per_second'})
return {'schema_version': 1, 'observed_at': value.get('timestamp'),
'identity': {'reported_name': value['machine'].get('name'), 'category': 'host',
'details': value.get('device', {})},