feat: declare collection cadence and preserve Agent sampling timestamps
This commit is contained in:
@@ -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', []),
|
||||
|
||||
Reference in New Issue
Block a user