Initial commit: Add infrastructure and bot project
This commit is contained in:
127
infra/monitoring/check_grafana.py
Normal file
127
infra/monitoring/check_grafana.py
Normal file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Скрипт для проверки статуса Grafana и дашбордов
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
def check_grafana_status():
|
||||
"""Проверка статуса Grafana"""
|
||||
try:
|
||||
response = requests.get("http://localhost:3000/api/health", timeout=5)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"✅ Grafana работает (версия: {data.get('version', 'unknown')})")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Grafana: HTTP {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Grafana: ошибка подключения - {e}")
|
||||
return False
|
||||
|
||||
def check_prometheus_connection():
|
||||
"""Проверка подключения Grafana к Prometheus"""
|
||||
try:
|
||||
# Проверяем, что Prometheus доступен
|
||||
response = requests.get("http://localhost:9090/api/v1/targets", timeout=5)
|
||||
if response.status_code == 200:
|
||||
print("✅ Prometheus доступен для Grafana")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Prometheus: HTTP {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Prometheus: ошибка подключения - {e}")
|
||||
return False
|
||||
|
||||
def check_metrics_availability():
|
||||
"""Проверка доступности метрик"""
|
||||
try:
|
||||
response = requests.get("http://localhost:9091/metrics", timeout=5)
|
||||
if response.status_code == 200:
|
||||
content = response.text
|
||||
if "cpu_usage_percent" in content and "ram_usage_percent" in content:
|
||||
print("✅ Метрики доступны и содержат данные")
|
||||
return True
|
||||
else:
|
||||
print("⚠️ Метрики доступны, но данные неполные")
|
||||
return False
|
||||
else:
|
||||
print(f"❌ Метрики: HTTP {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Метрики: ошибка подключения - {e}")
|
||||
return False
|
||||
|
||||
def check_prometheus_targets():
|
||||
"""Проверка статуса targets в Prometheus"""
|
||||
try:
|
||||
response = requests.get("http://localhost:9090/api/v1/targets", timeout=5)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
targets = data.get('data', {}).get('activeTargets', [])
|
||||
|
||||
print("\n📊 Статус targets в Prometheus:")
|
||||
for target in targets:
|
||||
job = target.get('labels', {}).get('job', 'unknown')
|
||||
instance = target.get('labels', {}).get('instance', 'unknown')
|
||||
health = target.get('health', 'unknown')
|
||||
last_error = target.get('lastError', '')
|
||||
|
||||
status_emoji = "✅" if health == "up" else "❌"
|
||||
print(f" {status_emoji} {job} ({instance}): {health}")
|
||||
|
||||
if last_error:
|
||||
print(f" Ошибка: {last_error}")
|
||||
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Prometheus API: HTTP {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Prometheus API: ошибка подключения - {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""Основная функция проверки"""
|
||||
print(f"🔍 Проверка Grafana и системы мониторинга - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print("=" * 70)
|
||||
|
||||
# Проверяем все компоненты
|
||||
all_ok = True
|
||||
|
||||
if not check_grafana_status():
|
||||
all_ok = False
|
||||
|
||||
if not check_prometheus_connection():
|
||||
all_ok = False
|
||||
|
||||
if not check_metrics_availability():
|
||||
all_ok = False
|
||||
|
||||
if not check_prometheus_targets():
|
||||
all_ok = False
|
||||
|
||||
print("\n" + "=" * 70)
|
||||
if all_ok:
|
||||
print("🎉 Все компоненты работают корректно!")
|
||||
print("\n📋 Доступные адреса:")
|
||||
print(" • Grafana: http://localhost:3000 (admin/admin)")
|
||||
print(" • Prometheus: http://localhost:9090")
|
||||
print(" • Метрики: http://localhost:9091/metrics")
|
||||
print("\n📊 Дашборды должны быть доступны в Grafana:")
|
||||
print(" • Server Monitoring")
|
||||
print(" • Server Monitoring Dashboard")
|
||||
print("\n💡 Если дашборды не видны, используйте ручную настройку:")
|
||||
print(" • См. файл: GRAFANA_MANUAL_SETUP.md")
|
||||
else:
|
||||
print("⚠️ Обнаружены проблемы в системе мониторинга")
|
||||
print(" Проверьте логи и настройки")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user