feat: unify Raspberry Pi disk presentation and manual discovery
This commit is contained in:
+18
-2
@@ -96,14 +96,27 @@ def collect(device):
|
||||
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
|
||||
resources = [{'id': 'host', 'type': 'host'}]
|
||||
for disk in value['system'].get('storage_inventory', []):
|
||||
rid = 'storage-' + disk['id']
|
||||
resources.append({'id': rid, 'type': 'filesystem' if disk.get('filesystem') else 'disk', 'parent_id': 'host',
|
||||
'name': disk['name'], 'state': disk['state'],
|
||||
'details': {'device': disk.get('device', ''), 'mountpoint': disk.get('mountpoint', ''),
|
||||
'visible': disk.get('visible', True)}})
|
||||
if disk['state'] == 'mounted' and not value['system'].get('storage_inventory_error'):
|
||||
for key, unit in [('capacity_bytes', 'bytes'), ('used_bytes', 'bytes'), ('free_bytes', 'bytes'), ('used_percent', 'percent')]:
|
||||
number = disk.get(key)
|
||||
if isinstance(number, (int, float)) and not isinstance(number, bool) and math.isfinite(number):
|
||||
metrics.append({'resource_id': rid, 'key': key, 'value': number, 'unit': unit,
|
||||
'observed_at': value['system']['storage_inventory_observed_at']})
|
||||
return {'schema_version': 1, 'observed_at': value.get('timestamp'),
|
||||
'identity': {'reported_name': value['machine'].get('name'), 'category': 'host',
|
||||
'details': value.get('device', {})},
|
||||
'collection': {**declaration, 'interval_seconds': collection_interval(value)},
|
||||
'capabilities': MANIFEST['capabilities'], 'metrics': metrics,
|
||||
'resources': [{'id': 'host', 'type': 'host'}],
|
||||
'resources': resources,
|
||||
'alerts': value.get('display', {}).get('alerts', []),
|
||||
'alerts_complete': isinstance(value.get('display', {}).get('alerts'), list) and not storage_plan.get('error',False),
|
||||
'alerts_complete': isinstance(value.get('display', {}).get('alerts'), list) and not storage_plan.get('error',False) and not value['system'].get('storage_inventory_error', False),
|
||||
'view': value}
|
||||
|
||||
|
||||
@@ -118,6 +131,9 @@ def dispatch(method, params):
|
||||
return request(device, '/health')
|
||||
if method == 'device.collect':
|
||||
return collect(device)
|
||||
if method == 'device.refresh':
|
||||
if params.get('group') != 'storage':raise AdapterError('UNSUPPORTED')
|
||||
return request(device, '/storage/scan', 'PUT', {})
|
||||
if method == 'device.logs.query':
|
||||
return request(device, '/logs', query=params.get('query'))
|
||||
if method == 'device.read':
|
||||
|
||||
Reference in New Issue
Block a user