feat: follow Agent object plans and daily storage observations
This commit is contained in:
+6
-3
@@ -68,6 +68,9 @@ def collect(device):
|
||||
value = request(device, '/status')
|
||||
if not isinstance(value.get('system'), dict) or not isinstance(value.get('machine'), dict):
|
||||
raise AdapterError('INVALID_RESPONSE')
|
||||
declaration = value.get('collection') if isinstance(value.get('collection'),dict) else {}
|
||||
plans = declaration.get('refresh') if isinstance(declaration.get('refresh'),dict) else {}
|
||||
storage_plan = plans.get('storage') if isinstance(plans.get('storage'),dict) else {}
|
||||
metrics = []
|
||||
units = {'cpu_percent': 'percent', 'memory_percent': 'percent', 'disk_percent': 'percent',
|
||||
'temperature_c': 'celsius', 'cpu_freq_mhz': 'megahertz',
|
||||
@@ -90,17 +93,17 @@ def collect(device):
|
||||
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')
|
||||
at = source.get('storage_observed_at') if metric['key'].startswith('disk_') else 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': {'interval_seconds': collection_interval(value)},
|
||||
'collection': {**declaration, 'interval_seconds': collection_interval(value)},
|
||||
'capabilities': MANIFEST['capabilities'], 'metrics': metrics,
|
||||
'resources': [{'id': 'host', 'type': 'host'}],
|
||||
'alerts': value.get('display', {}).get('alerts', []),
|
||||
'alerts_complete': isinstance(value.get('display', {}).get('alerts'), list),
|
||||
'alerts_complete': isinstance(value.get('display', {}).get('alerts'), list) and not storage_plan.get('error',False),
|
||||
'view': value}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user