diff --git a/metrics-collector/README.md b/metrics-collector/README.md index ab6bc70..975eebf 100644 --- a/metrics-collector/README.md +++ b/metrics-collector/README.md @@ -29,19 +29,25 @@ This project is built with Poetry for dependency management. To get started: 3. Alternatively, you can use pip with the provided `requirements.txt`: `pip install -r requirements.txt` -The install might take a couple of minutes because of the dependencies. +The install might take a couple of minutes because of the dependencies. ## 🏃‍♂️ Usage Run the metrics collector with a single command: ```bash +# Scan all regions python -m metrics_collector.utilization_example --start-time 2025-02-19 +# Scan only a specific region +python -m metrics_collector.utilization_example --start-time 2025-02-19 --region us-east-1 +``` + Options: --start-time: Specify the start time for metric collection (ISO8601 format) --end-time: Specify the end time (defaults to current time if not provided) +--region: AWS region to scan (if not specified, all regions will be scanned) --config: Path to a custom configuration file --output: Custom name for the output CSV file ``` @@ -161,9 +167,9 @@ This configuration flexibility allows you to tailor the metrics collection to yo There is a companion project in the making where we will simplify metric visualization. Stay tuned for future updates! -Want to turn your CSV data into stunning visualizations? Check out our companion project DynamoDB Metrics Visualizer to create interactive dashboards and charts! +Want to turn your CSV data into stunning visualizations? Check out our companion project DynamoDB Metrics Visualizer to create interactive dashboards and charts! -The current report will present data in csv +The current report will present data in csv | Region | Table Name | Read Utilization | Write Utilization | |--------|------------|------------------|-------------------| @@ -196,4 +202,4 @@ We welcome contributions! Please see our Contributing Guide for more details. This project is licensed under the MIT License - see the [LICENSE](../LICENSE) file for details. -Built with ❤️ by DynamoDB Specialist Solutions Architects. \ No newline at end of file +Built with ❤️ by DynamoDB Specialist Solutions Architects. \ No newline at end of file diff --git a/metrics-collector/metrics_collector/collector.py b/metrics-collector/metrics_collector/collector.py index ed15dba..5824735 100644 --- a/metrics-collector/metrics_collector/collector.py +++ b/metrics-collector/metrics_collector/collector.py @@ -129,13 +129,14 @@ async def get_tables_and_metrics(self, region, start_time, end_time): table_metrics = await asyncio.gather(*tasks) return region, provisioned_tables, table_metrics - async def collect_all_metrics(self, start_time, end_time): + async def collect_all_metrics(self, start_time, end_time, specific_region=None): """ - Collect metrics for all provisioned DynamoDB tables across all regions. + Collect metrics for all provisioned DynamoDB tables across all regions or a specific region. Args: start_time (datetime): The start time for metric collection. end_time (datetime): The end time for metric collection. + specific_region (str, optional): If provided, only collect metrics for this region. Returns: tuple: A tuple containing all metrics and low utilization tables. @@ -143,9 +144,13 @@ async def collect_all_metrics(self, start_time, end_time): all_metrics = {} low_utilization_tables = {} - logger.info("Fetching all AWS regions...") - regions = await self.get_all_regions() - logger.info(f"Found {len(regions)} regions.") + if specific_region: + logger.info(f"Collecting metrics for specific region: {specific_region}") + regions = [specific_region] + else: + logger.info("Fetching all AWS regions...") + regions = await self.get_all_regions() + logger.info(f"Found {len(regions)} regions.") logger.info("Identifying provisioned tables in each region...") total_provisioned_tables = 0 @@ -153,7 +158,7 @@ async def collect_all_metrics(self, start_time, end_time): provisioned_tables = await self.get_provisioned_tables(region) total_provisioned_tables += len(provisioned_tables) - logger.info(f"Found {total_provisioned_tables} provisioned tables across all regions.") + logger.info(f"Found {total_provisioned_tables} provisioned tables across {'all regions' if not specific_region else specific_region}.") logger.info("Collecting metrics for provisioned tables...") region_tasks = [self.get_tables_and_metrics(region, start_time, end_time) for region in regions] diff --git a/metrics-collector/metrics_collector/utilization_example.py b/metrics-collector/metrics_collector/utilization_example.py index 573506b..9272614 100644 --- a/metrics-collector/metrics_collector/utilization_example.py +++ b/metrics-collector/metrics_collector/utilization_example.py @@ -132,6 +132,11 @@ async def main(): parser = argparse.ArgumentParser(description="Collect DynamoDB metrics") parser.add_argument("--start-time", type=str, help="Start time in ISO8601 format") parser.add_argument("--end-time", type=str, help="End time in ISO8601 format") + parser.add_argument( + "--region", + type=str, + help="AWS region to scan (if not specified, all regions will be scanned)", + ) parser.add_argument( "--storage", choices=["disk", "memory"], @@ -170,7 +175,7 @@ async def main(): logger.info(f"Collecting metrics from {start_time} to {end_time}") - all_metrics, low_utilization_tables = await collector.collect_all_metrics(start_time, end_time) + all_metrics, low_utilization_tables = await collector.collect_all_metrics(start_time, end_time, args.region) logger.info("Metrics collected and stored successfully.")