009-Ambari二次开发之添加自定义组件Redis(二)
上一篇我们主要介绍了Ambari添加组件的答题流程并以REDIS为例说明了流程,本篇在上一篇的基础上,进一步完善说明流程并介绍如何给组件添加metric
扫描二维码,关注BearData,获取最新文章
上篇中,我们已经制作出了redis的rpm包,并重新编译了我们修改后的Ambari源代码。我们将打出的RPM包拷贝到我们之前建的HDP的源中,并执行createrepo –update更新源
我们重新安装ambari,安装完后,我们通过界面安装组件时,在选择组件的列表中,看到了redis,我们选择,并安装
配置安装节点
Redis配置信息
安装完后,我们可以在界面看到redis服务
测试并使用redis
Redis添加metrics
metrics获取方式有两种,一种是通过写java插件的方式,另一种是通过写脚本的方式,其实最终的目的是将数据发送到指定端口
我们编写获取metrics的shell脚本
echo $$ >> /var/run/redis/redis_metrics.pid
url=http://$1/ws/v1/timeline/metrics
connected_metrics_name=”redis.connected_clients”
metrics_name=(“redis.connected_clients” “redis.blocked_clients” “redis.used_memory” “redis.mem_fragmentation_ratio”)
metrics_name=(“redis.connected_clients” “redis.blocked_clients” “redis.client_longest_output_list” “redis.client_biggest_input_buf” “redis.used_memory” “redis.used_memory_rss” “redis.used_memory_peak” “redis.used_memory_lua” “redis.total_connections_received” “redis.total_commands_processed” “redis.used_cpu_sys” “redis.used_cpu_user” “redis.used_cpu_sys_children” “redis.used_cpu_user_children”)
appid=”redis”
while [ 1 ]
do
millon_time=(date +%s%N) / 1000000 ))
for name in {name}
arr_name=({arr_name[1]}
str_value=2 -h 4 info |grep {str_value//:/ })
value={value}
json=”{
\”metrics\”: [
{
\”metricname\”: \”{appid}\”,
\”hostname\”: \”{millon_time},
\”starttime\”: {millon_time}\": ${value}
}
}
]
}”
curl -i -X POST -H "Content-Type: application/json" -d "${json}" ${url}
done
sleep $5
添加metrics.json
{
“REDIS_SERVER”: {
“Component”: [
{
“type”: “ganglia”,
“metrics”: {
“default”: {
“metrics/redis/connected_clients”: {
“metric”: “redis.connected_clients”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/blocked_clients”: {
“metric”: “redis.blocked_clients”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/client_longest_output_list”: {
“metric”: “redis.client_longest_output_list”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/client_biggest_input_buf”: {
“metric”: “redis.client_biggest_input_buf”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_memory”: {
“metric”: “redis.used_memory”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_memory_rss”: {
“metric”: “redis.used_memory_rss”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_memory_peak”: {
“metric”: “redis.used_memory_peak”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_memory_lua”: {
“metric”: “redis.used_memory_lua”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/total_connections_received”: {
“metric”: “redis.total_connections_received”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/total_commands_processed”: {
“metric”: “redis.total_commands_processed”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_cpu_sys”: {
“metric”: “redis.used_cpu_sys”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_cpu_user”: {
“metric”: “redis.used_cpu_user”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_cpu_sys_children”: {
“metric”: “redis.used_cpu_sys_children”,
“pointInTime”: true,
“temporal”: true
},
“metrics/redis/used_cpu_user_children”: {
“metric”: “redis.used_cpu_user_children”,
“pointInTime”: true,
“temporal”: true
}
}
}
}
]
}
}
widgets文件:
查看metrics