feat: declare collection cadence and preserve Agent sampling timestamps

This commit is contained in:
way
2026-10-15 00:35:02 +08:00
parent d6df234154
commit 93d5f0cdd7
3 changed files with 14 additions and 3 deletions
+5 -2
View File
@@ -1,7 +1,7 @@
{
"id": "pigway-agent",
"name": "PIGWay Raspberry Pi Agent",
"version": "1.2.2",
"version": "1.3.0",
"protocol_version": 1,
"entrypoint": "worker.py",
"runtime": "python3",
@@ -38,5 +38,8 @@
"contract": "console-ui-v1",
"entrypoint": "ui/index.js"
},
"legacy_connection_fields": true
"legacy_connection_fields": true,
"collection": {
"interval_seconds": 1
}
}
+6
View File
@@ -80,9 +80,15 @@ def collect(device):
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'})
for metric in metrics:
source = value.get('network', {}) if metric['key'].startswith('network_') else value.get('system', {})
at = source.get('observed_at') if metric['key'] != 'uptime_seconds' else value.get('timestamp')
if isinstance(at, (int, float)) and not isinstance(at, bool) and math.isfinite(at) and at > 0:
metric['observed_at'] = at
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']),
'capabilities': MANIFEST['capabilities'], 'metrics': metrics,
'resources': [{'id': 'host', 'type': 'host'}],
'alerts': value.get('display', {}).get('alerts', []),