perf: use two-second minimum Raspberry Pi collection cadence
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "pigway-agent",
|
||||
"name": "PIGWay Raspberry Pi Agent",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.1",
|
||||
"protocol_version": 1,
|
||||
"entrypoint": "worker.py",
|
||||
"runtime": "python3",
|
||||
@@ -40,6 +40,6 @@
|
||||
},
|
||||
"legacy_connection_fields": true,
|
||||
"collection": {
|
||||
"interval_seconds": 1
|
||||
"interval_seconds": 2
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -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', []),
|
||||
|
||||
@@ -21,9 +21,14 @@ class MetricsTests(unittest.TestCase):
|
||||
self.assertEqual(values['network_rx_bytes_per_second'],0)
|
||||
self.assertEqual(values['network_tx_bytes_per_second'],1234)
|
||||
self.assertEqual(next(m['observed_at'] for m in result['metrics'] if m['key']=='network_tx_bytes_per_second'),120)
|
||||
self.assertEqual(result['collection']['interval_seconds'],1)
|
||||
self.assertEqual(result['collection']['interval_seconds'],2)
|
||||
self.assertTrue(result['alerts_complete'])
|
||||
|
||||
def test_collection_minimum_and_slower_device(self):
|
||||
self.assertEqual(worker.collection_interval({'collection':{'interval_seconds':1}}),2)
|
||||
self.assertEqual(worker.collection_interval({'collection':{'interval_seconds':5}}),5)
|
||||
self.assertEqual(worker.collection_interval({'collection':{'interval_seconds':True}}),2)
|
||||
|
||||
def test_absent_or_boolean_fields_not_invented(self):
|
||||
value={'system': {'cpu_percent': True}, 'machine':{}, 'network': {'link_speed_mbps': None, 'rx_bytes_per_second':float('nan'), 'tx_bytes_per_second':True}}
|
||||
with patch.object(worker,'request',return_value=value): result=worker.collect({})
|
||||
|
||||
Reference in New Issue
Block a user