22 lines
1.0 KiB
Python
22 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify optional Prometheus scrape and federated OpenSearch PPL query."""
|
|
import json
|
|
import sys
|
|
import urllib.parse
|
|
import urllib.request
|
|
|
|
query = 'cpu_usage_active{cpu="cpu-total"}'
|
|
with urllib.request.urlopen('http://127.0.0.1:9090/api/v1/query?' + urllib.parse.urlencode({'query': query}), timeout=20) as r:
|
|
result = json.load(r)
|
|
if result.get('status') != 'success' or not result['data']['result']:
|
|
sys.exit('No Prometheus CPU samples yet. Wait 60 seconds and check metrics-bridge logs.')
|
|
print('PASS: Prometheus has host CPU samples.')
|
|
payload = {'query': 'source = host_prometheus.cpu_usage_active | head 5'}
|
|
req = urllib.request.Request('http://127.0.0.1:9200/_plugins/_ppl', data=json.dumps(payload).encode(),
|
|
headers={'Content-Type': 'application/json'})
|
|
with urllib.request.urlopen(req, timeout=60) as r:
|
|
result = json.load(r)
|
|
if not result.get('datarows'):
|
|
sys.exit('PPL returned no rows: ' + json.dumps(result))
|
|
print('PASS: OpenSearch queries the Prometheus data source through PPL.')
|