perf: use two-second minimum Raspberry Pi collection cadence

This commit is contained in:
way
2026-10-15 01:00:13 +08:00
parent c947cbe934
commit f5e668d545
3 changed files with 17 additions and 4 deletions
+9 -1
View File
@@ -56,6 +56,14 @@ def request(device, endpoint, method='GET', payload=None, query=None):
raise AdapterError('RESULT_UNKNOWN' if method == 'PUT' else 'DEVICE_UNAVAILABLE') from None
def collection_interval(value):
declaration = value.get('collection', {})
interval = declaration.get('interval_seconds') if isinstance(declaration, dict) else None
if not isinstance(interval, (int, float)) or isinstance(interval, bool) or not math.isfinite(interval) or not 1 <= interval <= 3600:
interval = MANIFEST['collection']['interval_seconds']
return max(MANIFEST['collection']['interval_seconds'], interval)
def collect(device):
value = request(device, '/status')
if not isinstance(value.get('system'), dict) or not isinstance(value.get('machine'), dict):
@@ -88,7 +96,7 @@ def collect(device):
return {'schema_version': 1, 'observed_at': value.get('timestamp'),
'identity': {'reported_name': value['machine'].get('name'), 'category': 'host',
'details': value.get('device', {})},
'collection': value.get('collection', MANIFEST['collection']),
'collection': {'interval_seconds': collection_interval(value)},
'capabilities': MANIFEST['capabilities'], 'metrics': metrics,
'resources': [{'id': 'host', 'type': 'host'}],
'alerts': value.get('display', {}).get('alerts', []),