Skip to content

Commit

Permalink
use dimension value for EC2 uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
stolarczyk committed Apr 28, 2022
1 parent b3ac3ef commit c69806e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cloudwatcher/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ def main():
)

if args.uptime:
if not args.dimension_value.startswith("i-"):
_LOGGER.error(
"Uptime is only available for EC2 instances. "
"Please provide an EC2 instance ID as the dimension value."
)
sys.exit(1)
try:
seconds_run = metric_watcher.get_ec2_uptime(
days=max(
15, args.days
), # metrics with a period of 60 seconds are available for 15 days
hours=args.hours,
minutes=args.minutes,
ec2_instance_id=args.dimension_value,
)
if seconds_run is not None:
_LOGGER.info(f"Instance uptime is {int(seconds_run)} seconds")
Expand Down

0 comments on commit c69806e

Please sign in to comment.