Dav*_*vid 5 amazon-web-services amazon-cloudwatch amazon-efs
标题几乎说明了一切 - 由于 EFS 计量大小(使用情况)不是我可以在 Cloudwatch 中使用的指标,我需要创建一个自定义指标来观察 EFS 中最后一个计量文件的大小。
有没有可能这样做?或者有没有更好的方法来监控我的 EFS 的大小?
我建议使用 Lambda,每小时运行一次并将数据发送到 CloudWatch。
此代码收集所有 EFS 文件系统并将其大小(以 kb 为单位)与文件系统名称一起发送到 Cloudwatch。修改它以满足您的需求:
import json
import boto3
region = "us-east-1"
def push_efs_size_metric(region):
efs_name = []
efs = boto3.client('efs', region_name=region)
cw = boto3.client('cloudwatch', region_name=region)
efs_file_systems = efs.describe_file_systems()['FileSystems']
for fs in efs_file_systems:
efs_name.append(fs['Name'])
cw.put_metric_data(
Namespace="EFS Metrics",
MetricData=[
{
'MetricName': 'EFS Size',
'Dimensions': [
{
'Name': 'EFS_Name',
'Value': fs['Name']
}
],
'Value': fs['SizeInBytes']['Value']/1024,
'Unit': 'Kilobytes'
}
]
)
return efs_name
def cloudtrail_handler(event, context):
response = push_efs_size_metric(region)
print ({
'EFS Names' : response
})
Run Code Online (Sandbox Code Playgroud)
我还建议阅读下面的参考资料,了解有关创建自定义指标的更多详细信息。
| 归档时间: |
|
| 查看次数: |
909 次 |
| 最近记录: |