0

Using Python boto3 library, I am not able to fetch ec2 instance(irrespective of Linux or windows OS) usage of "ebs volume". I am not able to authorize to install any agents on all ec2 instance as it is owned by different product team. How to get this information without login to EC2 instance? If it is not possible then please suggest better way to fetch this information in automated way.

I have tried using boto3 library using python to fetch details, but unable to find out the way to get used space of ebs volume attached on EC2 instance.

    import boto3
    if __name__ == '__main__':
        session = boto3.session.Session(profile_name="default")
        ec2 = session.resource(service_name='ec2', region_name='us-east-2')
        instance = ec2.Instance('-----------')
        volumes = instance.volumes.all()
        for v in volumes:
            print(v.id, v.size, v.state, v.kms_key_id, v.availability_zone, v.volume_type, v.encrypted, v.iops, v.snapshot_id, v.create_time)

Please help me to find out to get ec2 instance metric report of ebs volume usage on automation way, as I have task to get ebs volume size of ec2 instance and compare threshold, after compare then i need to fire event such as email notification, increase of size etc.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
user3845198
  • 1
  • 2
  • 3

2 Answers2

1

To get the information of EBS volume, swap you can use scripts or a cloudwatch agent. Below is the example of scripts .

./mon-get-instance-stats.pl --recent-hours=12
Instance metric statistics for the last 12 hours.
CPU Utilization
    Average: 1.06%, Minimum: 0.00%, Maximum: 15.22%
Memory Utilization
    Average: 6.84%, Minimum: 6.82%, Maximum: 6.89%
Swap Utilization
    Average: N/A, Minimum: N/A, Maximum: N/A
Disk Space Utilization on /dev/xvda1 mounted as /
    Average: 9.69%, Minimum: 9.69%, Maximum: 9.69%

Below links will help you to setup the same.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html

mahendra rathod
  • 1,438
  • 2
  • 15
  • 23
0

Thanks we have setup this on Linux and answer for setting up on custom metric on cloudwatch easily available. However, we do have difficulty to get %CPU Usgae, %Memory Usage and % DIsk space usage for windows EC2 Instance.

Please see below question ask on stack overflow below: Configure custom metric of AWS CloudWatch Agent for Windows EC2 Instance [%CPU,%Memory,%DiskSpace]

We need config.json file of custom metric of CloudWatch which shows %CPU usage, %Memory Usage and %DIsk Space.

user3845198
  • 1
  • 2
  • 3