Flume之JMX监控三种方式

监控作用

  1. 在flume运行期间,我们可以通过监控channel当前容量和已使用容量来调整channel是否需要扩容
  2. 通过source向channel中put成功了多少event和sink从channel中take成功了多少个event,比较数据是否存在积压做出调整(通过sink组,和batchsize参数可增加sink读取速度)

监控原理

通过Java提供的JMX技术(java monitor extension)即 java监控扩展模块,是J2EE定义的14种技术规范之一。

JMX可以帮助我们监控一个java进程中需要了解的参数,可以实时修改java进程中的某个对象的参数 。

具体操作:

  1. 创建MBean(monitor bean):需要监控的参数封装到一个Bean中
  2. 创建 JMX的monitor服务:该服务可以在程序希望获取到MBean参数时来请求服务,该服务可帮我们对Bean中的参数进行读写操作
  3. 客户端:客户端向JMX发送服务请求,返回MBean信息

在flume 中已经为我们编写了MBean和JMX Monitor服务,我们需要启动服务并使用客户端查看

官方文档

monitoring

客户端

方式一:使用Jconsole查看

JMX Reporting

JMX Reporting can be enabled by specifying JMX parameters in the JAVA_OPTS environment variable using flume-env.sh, like

export JAVA_OPTS=”-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5445 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false”

NOTE: The sample above disables the security. To enable Security, please refer http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html

  1. 在fulme的conf/flume-env.sh 中配置上述中 JAVA_OPTS 环境变量(首次配置需要重命名去掉.template后缀)

  2. 运行一个fulme任务

  3. 通过jdk自带 %JAVA_HOME%/bin/jconsole.exe 监控

在这里插入图片描述在这里插入图片描述

方式二:浏览器发送web请求

JSON Reporting

… …

We can start Flume with JSON Reporting support as follows:

$ bin/flume-ng agent --conf-file example.conf --name a1 -Dflume.monitoring.type=http -Dflume.monitoring.port=34545

Metrics will then be available at http://:/metrics webpage. Custom components can report metrics as mentioned in the Ganglia section above.

  1. 在启动flume时候加入 -Dflume.monitoring.type=http -Dflume.monitoring.port=34545 参数运行
  2. 在浏览器 通过 ip地址或host名:34545/metrics 获取json数据

方式三:使用第三方框架,例如Ganglia

2016年已停止更新

Ganglia由gmond、gmetad和gweb三部分组成。

  • gmond(Ganglia Monitoring Daemon)是一种轻量级服务,安装在每台需要收集指标数据的节点主机上。使用gmond,你可以很容易收集很多系统指标数据,如CPU、内存、磁盘、网络和活跃进程的数据等。

  • gmetad(Ganglia Meta Daemon)整合所有信息,并将其以RRD格式存储至磁盘的服务。

  • gweb(Ganglia Web)Ganglia可视化工具,gweb是一种利用浏览器显示gmetad所存储数据的PHP前端。在Web界面中以图表方式展现集群的运行状态下收集的多种不同指标数据。

Ganglia Reporting

Flume can also report these metrics to Ganglia 3 or Ganglia 3.1 metanodes. To report metrics to Ganglia, a flume agent must be started with this support. The Flume agent has to be started by passing in the following parameters as system properties prefixed by flume.monitoring., and can be specified in the flume-env.sh:

Property NameDefaultDescription
typeThe component type name, has to be ganglia
hostsComma-separated list of hostname:port of Ganglia servers
pollFrequency60Time, in seconds, between consecutive reporting to Ganglia server
isGanglia3falseGanglia server version is 3. By default, Flume sends in Ganglia 3.1 format

We can start Flume with Ganglia support as follows:

$ bin/flume-ng agent --conf-file example.conf --name a1 -Dflume.monitoring.type=ganglia -Dflume.monitoring.hosts=com.example:1234,com.example2:5455
  1. 安装

    # 安装httpd服务与php
    sudo yum -y install httpd php
    # 安装其他依赖
    sudo yum -y install rrdtool perl-rrdtool rrdtool-devel
    sudo yum -y install apr-devel
    # 安装ganglia
    sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    sudo yum -y install ganglia-gmetad 
    sudo yum -y install ganglia-web
    sudo yum install -y ganglia-gmond
    
    
  2. 修改配置文件/etc/httpd/conf.d/ganglia.conf 可以接收任意发送的请求

    <Location /ganglia>
      Order deny,allow
      #Deny from all
      Allow from all
      # Allow from 127.0.0.1
      # Allow from ::1
      # Allow from .example.com
    </Location>
    
  3. 修改配置文件/etc/ganglia/gmetad.conf 配置数据源地址

    data_source "dw-node01" 192.168.1.102
    
  4. 修改配置文件/etc/ganglia/gmond.conf

    cluster {
      name = "dw-node01"
      owner = "unspecified"
      latlong = "unspecified"
      url = "unspecified"
    }
    udp_send_channel {
      #bind_hostname = yes # Highly recommended, soon to be default.
                           # This option tells gmond to use a source address
                           # that resolves to the machine's hostname.  Without
                           # this, the metrics may appear to come from any
                           # interface and the DNS names associated with
                           # those IPs will be used to create the RRDs.
      # mcast_join = 239.2.11.71
      host = 192.168.1.102
      port = 8649
      ttl = 1
    }
    udp_recv_channel {
      # mcast_join = 239.2.11.71
      port = 8649
      bind = 192.168.1.102
      retry_bind = true
      # Size of the UDP buffer. If you are handling lots of metrics you really
      # should bump it up to e.g. 10MB or even higher.
      # buffer = 10485760
    }
    
  5. 修改 /etc/selinux/config 调低系统安全级别 开启允许采集系统指标

    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled
    # SELINUXTYPE= can take one of these two values:
    #     targeted - Targeted processes are protected,
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted
    
    

    selinux本次生效关闭必须重启,如果此时不想重启,可以临时生效之:sudo setenforce 0

  6. 启动ganglia

    sudo service httpd start
    sudo service gmetad start
    sudo service gmond start
    

    如果完成以上操作依然出现权限不足错误,请修改/var/lib/ganglia目录的权限

  7. 修改 flume/conf/flume-env.sh 配置

    JAVA_OPTS="-Dflume.monitoring.type=ganglia
    -Dflume.monitoring.hosts=192.168.1.102:8649
    -Xms100m
    -Xmx200m"
    
  8. 启动一个flume任务

  9. 查看web页面http://192.168.1.102/ganglia

客户端开源方案

  • JMX 框架 - JMXTrans
  • 时序数据库 - Infulxdb
  • 可视化框架 - Graffna (运维较多)