我创建了一个cron作业(cron作业每分钟运行一次)和一个shell脚本,以便在this answer in AWS forum的帮助下将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语句),我可以看到此脚本已成功将自定义指标发送到云监视
$ 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'
命令看到此指标。
如果我在运行cron作业的同一台机器上运行mon-get-stats
命令,我会得到以下输出
$ 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
但如果我从同一群集中存在的其他机器运行相同的命令,我就不会得到任何结果。
有人可以帮我正确插入和获取自定义指标吗?
答案 0 :(得分:1)
问题已解决。我使用一组凭据发布数据并使用其他凭据查看AWS控制台。 :(