Files
SnarfCode/scripts/check_prom_live_targets.py

30 lines
1.2 KiB
Python

import paramiko
import json
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
def run(cmd):
_, o, e = c.exec_command(cmd)
return o.read().decode().strip()
out = run("kubectl exec deployment/prometheus -- wget -qO- http://localhost:9090/api/v1/targets")
data = json.loads(out)
print("=== ACTIVE TARGETS ===")
for t in data.get('data', {}).get('activeTargets', []):
print(f"[{t.get('health')}] pool: {t.get('scrapePool')} | job: {t.get('labels', {}).get('job')} | instance: {t.get('labels', {}).get('instance')} | url: {t.get('scrapeUrl')}")
if t.get('lastError'):
print(f" ERROR: {t.get('lastError')}")
print("\n=== SAMPLE NODE EXPORTER QUERY ===")
out = run("kubectl exec deployment/prometheus -- wget -qO- 'http://localhost:9090/api/v1/query?query=count(node_cpu_seconds_total{mode=\"idle\"})_by_(instance)'")
print(out)
print("\n=== SAMPLE CADVISOR QUERY ===")
out = run("kubectl exec deployment/prometheus -- wget -qO- 'http://localhost:9090/api/v1/query?query=count(container_cpu_usage_seconds_total)'")
print(out)
c.close()