0
我已經創建了一個cron作業(cron作業每隔一分鐘運行一次)和一個shell腳本,在的幫助下將HDFS用法發佈到Cloudwatch。AWS 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 '----------------------------------------------------'
我可以看到這個劇本是成功發送自定義指標通過查看以下日誌(print語句)
$ 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
,但如果我從其他目前該機在同一個集羣運行相同的命令我沒有得到任何結果。
任何人都可以請幫助我正確插入和獲取自定義指標?