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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ