注意:如果还未安装Promethues,参考HDFS & Yarn on Promethues + Grafana的监控(一) —— Promethues的安装
一、配置Promethues的数据源
1、下载jmx_prometheus_javaagent-0.13.0.jar包:
wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.13.0/jmx_prometheus_javaagent-0.13.0.jar
2、配置jmx和promethues的连接
(1)创建一个文件夹并在这个文件夹下创建不同jmx的配置yaml(此步骤在各自的节点都要有这个配置文件)
a、创建文件夹
cd /data
mkdir hdfs
b、在/data/hdfs/目录下创建NameNode的JMX配置文件 (此步骤在各自的节点都要有这个配置文件)
vim /data/hdfs/nn.yaml
startDelaySeconds: 0
hostPort: 10.21.0.86:6444
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
c、在/data/hdfs/目录下创建DateNode的JMX配置文件 (此步骤在各自的节点都要有这个配置文件)
vim /data/hdfs/dn.yaml
startDelaySeconds: 0
hostPort: 10.21.0.86:6454
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
d、在/data/hdfs/目录下创建ResourceManager的JMX配置文件 (此步骤在各自的节点都要有这个配置文件)
vim /data/hdfs/rm.yaml
tartDelaySeconds: 0
#master为本机IP(一般可设置为localhost);6464为想设置的jmx端口
hostPort: 10.21.0.86:6464
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
e、在/data/hdfs/目录下创建NodeManager的JMX配置文件 (此步骤在各自的节点都要有这个配置文件)
vim /data/hdfs/nm.yaml
startDelaySeconds: 0
#master为本机IP(一般可设置为localhost);6474为想设置的jmx端口(可设置为未被占>用的端口)
hostPort: 10.21.0.86:6474
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
(2)CDH版本&开源社区版本集群都建议这么弄:
a、修改hadoop的bin/hdfs这个启动命令文件,只需在上方加入下面这个环境变量
cdh的目录在这:/opt/cloudera/parcels/CDH/lib/hadoop-hdfs/bin/hdfs
##hdfs jmx monitor##
#######################
export HADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=6444 -javaagent:/data/hdfs/jmx_prometheus_javaagent-0.13.0.jar=17106:/data/hdfs/nn.yaml $HADOOP_NAMENODE_OPTS"
export HADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=6454 -javaagent:/data/hdfs/jmx_prometheus_javaagent-0.13.0.jar=17107:/data/hdfs/dn.yaml $HADOOP_DATANODE_OPTS"
#######################
b、在/opt/cloudera/parcels/CDH/lib/hadoop-yarn/bin/yarn
##yarn jmx monitor##
#######################
export YARN_RESOURCEMANAGER_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=6464 -javaagent:/data/hdfs/jmx_prometheus_javaagent-0.13.0.jar=17104:/data/hdfs/rm.yaml $YARN_RESOURCEMANAGER_OPTS"
export YARN_NODEMANAGER_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=6474 -javaagent:/data/hdfs/jmx_prometheus_javaagent-0.13.0.jar=17105:/data/hdfs/nm.yaml $YARN_NODEMANAGER_OPTS"
#######################
注意:当然也可以参考其他大佬配置在/etc/hadoop/conf/hadoop-env.sh里添加这些配置,个人不喜欢去改命令,建议添加环境变量即可
(3)在promethues进行配置(我的promethues的目录是在/usr/local下面)
注意:像下面a、b这样的好处是修改target监控的节点是不用重启Promethues的,而直接配置在prometheus.yml是需要重启的
a、在promethues的目录下建个configs目录,再写好target的json配置文件
mkdir configs
cd configs
vim nn.json
--------------------------------------------------
[
{
"targets": ["nn的host:17106"]
}
]
--------------------------------------------------
vim dn.json
--------------------------------------------------
[
{
"targets": ["dn1的host:17107","dn2的host:17107","dn3的host:17107"]
}
]
--------------------------------------------------
vim rm.json
--------------------------------------------------
[
{
"targets": ["rm1host:17104","rm2host:17104"]
}
]
--------------------------------------------------
vim nm.json
--------------------------------------------------
[
{
"targets": ["nm1host:17105","nm2host:17105","nm3host:17105"]
}
]
--------------------------------------------------
b、再在promethues目录下修改prometheus.yml文件
vim prometheus.yml
- job_name: 'yarn-rm'
file_sd_configs:
- files:
- configs/rm.json
- job_name: 'yarn-nm'
file_sd_configs:
- files:
- configs/nm.json
(4)重启prometheus
$ systemctl restart prometheus
二、验证数据源是否配置成功
1、验证是否配置成功,有两种方式:
(1)根据刚才配置target路径访问测试,如果有放回一堆数据,说明配置成功
curl "[http://rm1host:17104/metrics](http://localhost:17107/metrics)"
返回:
# HELP jmx_exporter_build_info A metric with a constant '1' value labeled with the version of the JMX exporter.
# TYPE jmx_exporter_build_info gauge
jmx_exporter_build_info{version="0.13.0",name="jmx_prometheus_javaagent",} 1.0
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 266.8
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.611046723427E9
# HELP process_open_fds Number of open file descriptors.
。。。。**等等 **
(2)或者访问Promethues的9090端口,查看target是否正常。
点击Status再点击Target看是否是绿色,红色则是配置失败
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oKewO9cW-1611311044018)(https://secure-static.wolai.com/static/82j7NqcK7KoNakU8AXuouS/image.png)]
三、配置Grafana
参考我的另外一篇文章 HDFS & Yarn on Promethues + Grafana的监控(三) —— Grafana的Dashboard配置(以 Yarn 为例)