This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ECstats is a Python-based tool for extracting AWS ElastiCache (Redis/Valkey) database metrics via CloudWatch. It's a single-file application that generates Excel reports containing performance metrics and instance information.
- Main execution:
python ecstats.py -c config.ini - With custom config:
python ecstats.py -c <config_file> - With output directory:
python ecstats.py -c config.ini -d <output_dir> - Docker execution:
docker run -v $(pwd):/app -t sumitshatwara/redis-ecstats python3 ecstats.py
python3 -m venv .env && source .env/bin/activate
pip install -r requirements.txt
cp config.ini.example config.ini
# Edit config.ini with your AWS credentials and regions# Run all tests
pytest test_ecstats.py -v
# Run with coverage
coverage run -m pytest test_ecstats.py
coverage report -m# Format code with black
black ecstats.py test_ecstats.py
# Check formatting without making changes
black --check --diff ecstats.py test_ecstats.pydocker build -t ecstats .Single File Application (ecstats.py):
- Main execution flow:
main()→process_aws_account()→ metric collection functions - Configuration parsing: Uses Python
configparserto read multi-section config files - AWS Integration: Boto3 sessions with support for both credentials and IAM roles
- Metric collection: Two metric categories with different collection periods:
get_max_metrics_weekly(): 7-day metrics (configurable viaMETRIC_COLLECTION_PERIOD_DAYS)get_max_metrics_hourly(): Hourly command-based metrics
- Output generation: Excel workbooks with two worksheets (ClusterData, ReservedData)
get_clusters_info(): Discovers ElastiCache instances and reserved instancesget_metric()/get_metric_curr(): CloudWatch metric retrievalget_running_instances_metrics(): Collects and processes all metrics for active instancescreate_workbook(): Generates Excel output structure
- Multi-environment support via config sections (e.g.,
[production],[staging]) - Supports both AWS credentials and IAM role-based authentication
- Environment variable support for metric collection period:
METRIC_COLLECTION_PERIOD_DAYS
boto3: AWS SDK for ElastiCache and CloudWatch APIsopenpyxl: Excel file generationpytest: Testing framework with comprehensive test coverageblack: Code formatter for consistent Python style- Python 3.6+ required (tested on 3.8-3.12)
CloudWatchReadOnlyAccessAmazonElastiCacheReadOnlyAccess
Excel files named {section}-{region}.xlsx containing:
- ClusterData sheet: Instance details with ~45 performance metrics
- ReservedData sheet: Reserved instance information
- Metrics include Redis/Valkey command counts, latencies, memory usage, network stats