2022-11-03 11:39:31 +08:00
|
|
|
#!/bin/bash
|
2023-05-23 13:10:16 +08:00
|
|
|
eval "$(jq -r '@sh "export id=\(.input) asrolearn=\(.asrolearn)"')"
|
|
|
|
eval $(aws sts assume-role --role-arn $asrolearn --role-session-name awscli | jq -cr '"export AWS_ACCESS_KEY_ID=" + .Credentials.AccessKeyId, "export AWS_SECRET_ACCESS_KEY=" + .Credentials.SecretAccessKey, "export AWS_SESSION_TOKEN=" + .Credentials.SessionToken, "export AWS_SESSION_EXPIRATION=" + .Credentials.Expiration')
|
2022-11-03 11:39:31 +08:00
|
|
|
|
|
|
|
aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \
|
|
|
|
--dimensions Name=InstanceId,Value=$id Name=path,Value=/ | \
|
|
|
|
jq '.Metrics[] | .Dimensions[] | select ((.Name=="device") or (.Name=="fstype")) | { (.Name): (.Value)}' | \
|
|
|
|
jq -s 'add // {"device":"unknown", "fstype":"unknown"}'
|
|
|
|
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
DEVICE=$(aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \
|
|
|
|
--dimensions Name=InstanceId,Value=$id Name=path,Value=/ \
|
|
|
|
--query 'Metrics[].Dimensions[?Name==`device`].Value' --output text)
|
|
|
|
|
|
|
|
FSTYPE=$(aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \
|
|
|
|
--dimensions Name=InstanceId,Value=$id Name=path,Value=/ \
|
|
|
|
--query 'Metrics[].Dimensions[?Name==`fstype`].Value' --output text)
|
|
|
|
|
|
|
|
jq -n --arg device "$DEVICE" --arg fstype "$FSTYPE" '{"device":$device,"fstype":$fstype}'
|
|
|
|
|