AWS
-
[ AWS ] Python boto3를 이용하여 EC2 CPU 사용율 구하기AWS Infra 2023. 2. 2. 18:41
Python boto3를 이용하여 EC2 인스턴스의 CPU 사용율 구하기 import boto3 from datetime import datetime from datetime import timedelta client = boto3.client('cloudwatch') def CPUUtilization_Ec2(isinstance_id): response = client.get_metric_statistics( Namespace='AWS/EC2', MetricName='CPUUtilization', Dimensions=[ { 'Name': 'InstanceId', 'Value': isinstance_id }, ], StartTime=datetime.today() - timedelta(days=1) , En..
-
[ Python ] paramiko를 이용한 pem-key SSH 접속 (자동화 작업)AWS Infra 2021. 11. 30. 18:18
key 인증을 이용하여 접속시 parakimo 사용 import paramiko key = paramiko.RSAKey.from_private_key_file("pemfilepath") conn = paramiko.SSHClient() conn.set_missing_host_key_policy(paramiko.AutoAddPolicy()) conn.connect(hostname = " ", username = "", pkey = key ) stdin, stdout, stderr = conn.exec_command('echo "hello"') stdin.close() for line in stdout.read().splitlines(): print(line.decode()) conn.close() ----..