106 lines
3.1 KiB
Python
106 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
# monitor-queues.py
|
|
"""
|
|
Überwacht alle Email-Queues und zeigt Statistiken
|
|
"""
|
|
|
|
import boto3
|
|
import json
|
|
from datetime import datetime
|
|
|
|
sqs = boto3.client('sqs', region_name='eu-central-1')
|
|
|
|
DOMAINS = ['andreasknuth.de', 'bizmatch.net']
|
|
|
|
def get_queue_stats(domain):
|
|
"""Zeigt Queue-Statistiken für eine Domain"""
|
|
queue_name = domain.replace('.', '-') + '-queue'
|
|
dlq_name = queue_name + '-dlq'
|
|
|
|
try:
|
|
# Main Queue URL
|
|
queue_url = sqs.get_queue_url(QueueName=queue_name)['QueueUrl']
|
|
|
|
# Queue Attributes
|
|
attrs = sqs.get_queue_attributes(
|
|
QueueUrl=queue_url,
|
|
AttributeNames=['All']
|
|
)['Attributes']
|
|
|
|
# DLQ URL
|
|
dlq_url = sqs.get_queue_url(QueueName=dlq_name)['QueueUrl']
|
|
|
|
# DLQ Attributes
|
|
dlq_attrs = sqs.get_queue_attributes(
|
|
QueueUrl=dlq_url,
|
|
AttributeNames=['ApproximateNumberOfMessages']
|
|
)['Attributes']
|
|
|
|
return {
|
|
'domain': domain,
|
|
'queue': {
|
|
'available': int(attrs.get('ApproximateNumberOfMessages', 0)),
|
|
'in_flight': int(attrs.get('ApproximateNumberOfMessagesNotVisible', 0)),
|
|
'oldest_age': int(attrs.get('ApproximateAgeOfOldestMessage', 0))
|
|
},
|
|
'dlq': {
|
|
'count': int(dlq_attrs.get('ApproximateNumberOfMessages', 0))
|
|
}
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
'domain': domain,
|
|
'error': str(e)
|
|
}
|
|
|
|
|
|
def main():
|
|
print(f"\n{'='*70}")
|
|
print(f"Email Queue Monitoring - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print(f"{'='*70}\n")
|
|
|
|
total_available = 0
|
|
total_in_flight = 0
|
|
total_dlq = 0
|
|
|
|
for domain in DOMAINS:
|
|
stats = get_queue_stats(domain)
|
|
|
|
if 'error' in stats:
|
|
print(f"❌ {domain}: {stats['error']}")
|
|
continue
|
|
|
|
queue = stats['queue']
|
|
dlq = stats['dlq']
|
|
|
|
total_available += queue['available']
|
|
total_in_flight += queue['in_flight']
|
|
total_dlq += dlq['count']
|
|
|
|
status = "✅" if dlq['count'] == 0 else "⚠️"
|
|
|
|
print(f"{status} {domain}")
|
|
print(f" Available: {queue['available']:>5} messages")
|
|
print(f" In Flight: {queue['in_flight']:>5} messages")
|
|
print(f" Oldest Age: {queue['oldest_age']:>5}s")
|
|
print(f" DLQ: {dlq['count']:>5} messages")
|
|
|
|
if dlq['count'] > 0:
|
|
print(f" ⚠️ WARNING: {dlq['count']} failed message(s) in DLQ!")
|
|
|
|
print()
|
|
|
|
print(f"{'='*70}")
|
|
print(f"TOTALS:")
|
|
print(f" Available: {total_available} messages")
|
|
print(f" In Flight: {total_in_flight} messages")
|
|
print(f" Failed: {total_dlq} messages")
|
|
print(f"{'='*70}\n")
|
|
|
|
if total_dlq > 0:
|
|
print(f"⚠️ Action required: {total_dlq} message(s) in Dead Letter Queues!")
|
|
print(f" Run: python check-dlq.py to investigate\n")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |