37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import paramiko
|
|
import time
|
|
|
|
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)
|
|
out = o.read().decode().strip()
|
|
err = e.read().decode().strip()
|
|
return out + ("\nERR: " + err if err else "")
|
|
|
|
with open("homelab-gitops-repo/manifests/aerodrome/prometheus/prometheus.yaml", "r", encoding="utf-8") as f:
|
|
prom_yaml = f.read()
|
|
|
|
stdin, stdout, stderr = c.exec_command("cat > /tmp/prometheus_updated.yaml")
|
|
stdin.write(prom_yaml)
|
|
stdin.close()
|
|
stdout.channel.recv_exit_status()
|
|
|
|
print("Applying Prometheus:")
|
|
print(run("kubectl apply -f /tmp/prometheus_updated.yaml"))
|
|
|
|
print("\nRestarting Prometheus:")
|
|
print(run("kubectl rollout restart deployment/prometheus -n default"))
|
|
print(run("kubectl rollout status deployment/prometheus -n default --timeout=60s"))
|
|
|
|
print("\nWaiting 15 seconds for scrape loop...")
|
|
time.sleep(15)
|
|
|
|
print("\nPrometheus active targets count:")
|
|
print(run("kubectl exec deployment/prometheus -- wget -qO- http://localhost:9090/api/v1/targets | grep -o '\"health\":\"up\"' | wc -l"))
|
|
|
|
c.close()
|
|
|