Skip to content

Commit

Permalink
Merge pull request #16 from niaid/dev
Browse files Browse the repository at this point in the history
Internal refactoring and fixes
  • Loading branch information
stolarczyk authored Jul 31, 2023
2 parents 6909767 + 9798e82 commit c6b3082
Show file tree
Hide file tree
Showing 25 changed files with 978 additions and 605 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ repos:
"E203,W503,E741", # ignore these rules, to comply with black. See: https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated
"--max-line-length",
"88", # 90-ish is a good choice. See: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
"--exclude",
"argparser.py",
]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
Expand All @@ -27,3 +29,7 @@ repos:
rev: 21.12b0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
2 changes: 1 addition & 1 deletion cloudwatcher/argparser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" Computing configuration representation """

import argparse
from importlib.metadata import version

from cloudwatcher.const import CLI_DEFAULTS, LOG_CMD, METRIC_CMD, SUBPARSER_MESSAGES
from importlib.metadata import version

cloudwatcher_version = version("cloudwatcher")

Expand Down
14 changes: 9 additions & 5 deletions cloudwatcher/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import os
import sys

from rich.logging import RichHandler
from rich.console import Console
from pathlib import Path
from rich.logging import RichHandler

from cloudwatcher.const import LOG_CMD, METRIC_CMD
from cloudwatcher.logwatcher import LogWatcher

from .argparser import build_argparser
from .metricwatcher import MetricWatcher
from .preset import get_metric_watcher_setup, PresetFilesInventory
from .preset import Dimension, PresetFilesInventory, get_metric_watcher_setup


def main():
Expand Down Expand Up @@ -84,7 +83,12 @@ def main():
)

if args.uptime:
if not args.dimension_name == "InstanceId":
dimensions_list = [Dimension.from_cli(dimension_str) for dimension_str in args.dimensions]
for dimension in dimensions_list:
if dimension.Name == "InstanceId":
ec2_instance_id = dimension.Value
break
else:
_LOGGER.error(
"Uptime is only available for EC2 instances. "
"Please provide 'InstanceId' as dimension name and EC2 instance id"
Expand All @@ -98,7 +102,7 @@ def main():
), # metrics with a period of 60 seconds are available for 15 days
hours=args.hours,
minutes=args.minutes,
ec2_instance_id=args.dimension_value,
ec2_instance_id=ec2_instance_id,
)
if seconds_run is not None:
_LOGGER.info(f"Instance uptime is {int(seconds_run)} seconds")
Expand Down
8 changes: 4 additions & 4 deletions cloudwatcher/cloudwatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def __init__(
Args:
service_name (str): The name of the service to use
aws_region_name (Optional[str]): The AWS region name. Defaults to 'us-east-1'
aws_access_key_id (Optional[str]): The AWS access key ID. Defaults to None
aws_secret_access_key (Optional[str]): The AWS secret access key. Defaults to None
aws_session_token (Optional[str]): The AWS session token. Defaults to None
aws_region_name (Optional[str]): The AWS region name.
aws_access_key_id (Optional[str]): The AWS access key ID.
aws_secret_access_key (Optional[str]): The AWS secret access key.
aws_session_token (Optional[str]): The AWS session token.
"""
self.aws_region_name = aws_region_name or "us-east-1"
self.service_name = service_name
Expand Down
7 changes: 0 additions & 7 deletions cloudwatcher/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
METRIC_CMD: "Interact with AWS CloudWatch metrics.",
LOG_CMD: "Interact with AWS CloudWatch logs.",
}
DEFAULT_QUERY_KWARGS = {
"days": 1,
"hours": 0,
"minutes": 0,
"stat": "Maximum",
"period": 5,
}

CLI_DEFAULTS = {
"metric_name": "mem_used",
Expand Down
Loading

0 comments on commit c6b3082

Please sign in to comment.