Get free storage space of a RDS using python

0

Hello,

How to get free storage space of a RDS using python SDK?

Regards,
Kandarp Bhatt

kandarp
질문됨 5년 전1078회 조회
2개 답변
0

Hi,
Here you go. This will print out a list of the Minimum FreeStorageSpace in Bytes for the last 15 minutes (5 minute intervals). You will need to modify the DBInstanceIdentifier Value to match your database instance indentifier...

import boto3
from datetime import datetime,timedelta
import json

# Create CloudWatch client
cloudwatch = boto3.client('cloudwatch')

response = cloudwatch.get_metric_data(
    MetricDataQueries=[
        {
            'Id': 'fetching_FreeStorageSpace',
            'MetricStat': {
                'Metric': {
                    'Namespace': 'AWS/RDS',
                    'MetricName': 'FreeStorageSpace',
                    'Dimensions': [
                        {
                            "Name": "DBInstanceIdentifier",
                            "Value": "database-1"
                        }
                    ]
                },
                'Period': 300,
                'Stat': 'Minimum'
            }
        }
    ],
    StartTime=(datetime.now() - timedelta(seconds=300 * 3)).timestamp(),
    EndTime=datetime.now().timestamp(),
    ScanBy='TimestampDescending'
) 
print(response['MetricDataResults'][0]['Values'])

Hope this helps!
-randy

답변함 5년 전
0

Hi Randy,

Thanks for the reply and worked.

Thanks
Kandarp Bhatt

kandarp
답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠