我已经创建了一个cron作业(cron作业每一分钟运行一次)和一个shell脚本,在aws论坛的帮助下将hdfs的使用情况发布到cloudwatch。
我的脚本如下所示:
# !/bin/sh
#
# Prerequisites :
# 1. AWS cloudwatch CLI
# 2. JAVA
# 3. AWS credentials file inside AWS cloudwatch CLI directory
#
export JAVA_HOME=$1
export AWS_CLOUDWATCH_HOME=$2
export AWS_CREDENTIAL_FILE=$AWS_CLOUDWATCH_HOME/credential-file-path.template
export PATH="$PATH:$AWS_CLOUDWATCH_HOME/bin"
echo '['`date`'] INFO : all paths set.'
CLUSTER_NAME=$3
UNIT="Percent"
# 1. Get hdfs report
# 2. Grep for all lines containing dfs used data
# 3. Grep for percentage data
dfs_used_percent=`hadoop dfsadmin -report | grep -m 1 'DFS Used\%' | grep -oE '[[:digit:]]+\.?[[:digit:]]*'`
echo '['`date`'] INFO : Current hdfs usage percent : ' $dfs_used_percent
echo '['`date`'] INFO : Sending data to AWS cloudwatch.'
mon-put-data --metric-name "HdfsUsed" --namespace "MyCustomMetrics" --value $dfs_used_percent --unit $UNIT
echo '['`date`'] INFO : Result of mon-put-data command : ' $?
echo '['`date`'] INFO : Data sent to AWS cloudwatch. Exiting.'
echo '----------------------------------------------------'
通过查看以下日志(echo语句),我可以看到这个脚本正在成功地将自定义度量发送到cloudwatch
$ tail -f hdfs-usage-metric.log
[Wed Oct 29 05:23:03 UTC 2014] INFO : Result of mon-put-data command : 0
[Wed Oct 29 05:23:03 UTC 2014] INFO : Data sent to AWS cloudwatch. Exiting.
----------------------------------------------------
[Wed Oct 29 05:24:01 UTC 2014] INFO : all paths set.
[Wed Oct 29 05:24:03 UTC 2014] INFO : Current hdfs usage percent : 14.36
[Wed Oct 29 05:24:03 UTC 2014] INFO : Sending data to AWS cloudwatch.
[Wed Oct 29 05:24:04 UTC 2014] INFO : Result of mon-put-data command : 0
[Wed Oct 29 05:24:04 UTC 2014] INFO : Data sent to AWS cloudwatch. Exiting.
----------------------------------------------------
[Wed Oct 29 05:25:01 UTC 2014] INFO : all paths set.
[Wed Oct 29 05:25:02 UTC 2014] INFO : Current hdfs usage percent : 14.36
[Wed Oct 29 05:25:02 UTC 2014] INFO : Sending data to AWS cloudwatch.
[Wed Oct 29 05:25:03 UTC 2014] INFO : Result of mon-put-data command : 0
[Wed Oct 29 05:25:03 UTC 2014] INFO : Data sent to AWS cloudwatch. Exiting.
----------------------------------------------------
[Wed Oct 29 05:26:01 UTC 2014] INFO : all paths set.
[Wed Oct 29 05:26:02 UTC 2014] INFO : Current hdfs usage percent : 14.36
[Wed Oct 29 05:26:02 UTC 2014] INFO : Sending data to AWS cloudwatch.
[Wed Oct 29 05:26:03 UTC 2014] INFO : Result of mon-put-data command : 0
[Wed Oct 29 05:26:03 UTC 2014] INFO : Data sent to AWS cloudwatch. Exiting.
但是,即使在运行这个脚本超过2小时之后,这个度量在aws控制台中也不可见。
我看不到这个指标使用 $ mon-list-metrics | grep 'Hdfs'
命令也是。
如果我跑了 mon-get-stats
在运行cron作业的同一台机器上,我得到以下输出
$ mon-get-stats HdfsUsed --namespace AutodeskCustomMetrics --statistics Average
2014-10-29 04:35:00 14.36 Percent
2014-10-29 04:40:00 14.36 Percent
2014-10-29 04:45:00 14.36 Percent
2014-10-29 04:50:00 14.36 Percent
2014-10-29 04:55:00 14.36 Percent
2014-10-29 05:00:00 14.36 Percent
但如果我从同一集群中的其他机器上运行相同的命令,则不会得到任何结果。
有谁能帮我正确地插入和获取自定义指标吗?
1条答案
按热度按时间vnzz0bqm1#
问题已解决。我使用一组凭据发布数据,并使用其他凭据查看aws控制台:(