This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MSStats is a Python tool for extracting Google Cloud MemoryStore (Redis) database metrics using the Google Cloud Monitoring API. It processes Redis databases (single instance and replicated) across multiple GCP service accounts and generates Excel reports with usage statistics.
- Single Python script:
msstats.py- Main application that processes Redis metrics - Batch processing: Shell scripts for bulk operations across multiple GCP projects
- Service account management: Scripts to grant/revoke monitoring permissions
- Output format: Excel files with detailed Redis command statistics and throughput data
- Metric Processing: Categorizes Redis commands by type (Get, Set, Hash, List, etc.) from monitoring data
- Multi-node handling: Aggregates metrics across Redis cluster nodes taking maximum values
- Time series data: Configurable duration (default 7 days) and step intervals (default 60s)
- GCP Integration: Uses Google Cloud Monitoring API with service account authentication
# Create and activate virtual environment
python -m venv .env && source .env/bin/activate
# Install dependencies
pip install -r requirements.txt
# Place service account JSON files in root directory
cp path/to/service_account.json .# Basic usage (7 days, 60s steps)
python msstats.py
# Custom duration and step size
python msstats.py --duration 1800 --step 300
# Specific project
python msstats.py -p project-id# Grant monitoring permissions to service account
./grant_sa_monitoring_viewer.sh service-account@project.iam.gserviceaccount.com
# Run across all accessible projects
./batch_run_msstats.sh
# Remove monitoring permissions
./remove_sa_monitoring_viewer.sh service-account@project.iam.gserviceaccount.com
# Clean up environment
deactivate--duration SECONDS: Time period to analyze (default: 604800 = 7 days)--step SECONDS: Metric sampling interval (default: 60 seconds)-p PROJECT_ID: Target specific GCP project
# Run all tests (unit and integration)
pytest test_msstats.py
# Format code with Black
black *.py
# Check formatting without making changes
black --check *.pyopenpyxl>=3.0.4: Excel file generationgoogle-cloud-monitoring==2.18.0: GCP Monitoring API clientblack>=25.1.0: Code formatterpytest>=8.4.0: Testing frameworkpytest-mock>=3.14.0: Mock utilities for testing- Python 3.9+ required
- Service account JSON files must be placed in repository root
- Tool uses read-only monitoring API access
- Never connects directly to Redis instances
- No impact on database performance or data