Flume主要有以下集中監(jiān)控方式:
1.JMX監(jiān)控
配置 {$FLUME_HOME}/flume-env.sh
cd $FLUME_HOME
vi flume-env.sh
JAVA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.port=54321 \
-Dcom.sun.management.jmxremote.rmi.port=54322
-Djava.rmi.server.hostname=192.168.16.214"
之后啟動(dòng)flume
bin/flume-ng agent -c . -f conf/exec-tail.conf -n a1 -Dflume.root.logger=INFO,console
在圖形界面的系統(tǒng)(windows、mac、linux圖形)和jdk的環(huán)境下啟動(dòng)jconsole
jconsole
可以看到flume應(yīng)用所使用的內(nèi)存莫换、線(xiàn)程拉岁、類(lèi)喊暖、CPU等使用情況撕瞧。
2.HTTP監(jiān)控
Flume可以通過(guò)HTTP以JSON形式報(bào)告metrics,啟用HTTP監(jiān)控巩掺,F(xiàn)lume需要配置一個(gè)端口。
配置一個(gè)簡(jiǎn)單的打印conf文件
vi conf/exec-tail.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.channels = c1
a1.sources.r1.command = tail -F /tmp/test
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
啟動(dòng)flume并指定http監(jiān)控形式和端口
bin/flume-ng agent -c . -f conf/exec-tail.conf -n a1 -Dflume.root.logger=INFO,console -Dflume.monitoring.type=http -Dflume.monitoring.port=1234
查看metric監(jiān)控
用瀏覽器或者GET方式打開(kāi)
http://ip:1234/metrics
獲得數(shù)據(jù)如下:
CURL方式:
http://localhost:1234/metrics 2>/dev/null|sed -e 's/([,])\s*/\1\n/g' -e 's/[{}]/\n/g' -e 's/[“,]//g'
獲得數(shù)據(jù)如下:
"CHANNEL.c1":
"ChannelCapacity":"1000"
"ChannelFillPercentage":"0.0"
"Type":"CHANNEL"
"EventTakeSuccessCount":"10"
"ChannelSize":"0"
"EventTakeAttemptCount":"12"
"StartTime":"1476166839656"
"EventPutAttemptCount":"10"
"EventPutSuccessCount":"10"
"StopTime":"0"
"SOURCE.r1":
"EventReceivedCount":"10"
"AppendBatchAcceptedCount":"0"
"Type":"SOURCE"
"AppendReceivedCount":"0"
"EventAcceptedCount":"10"
"StartTime":"1476166840159"
"AppendAcceptedCount":"0"
"OpenConnectionCount":"0"
"AppendBatchReceivedCount":"0"
"StopTime":"0"
3.Ganglia監(jiān)控
Flume也可以報(bào)告metrics到Ganglia 3或者是Ganglia 3.1的metanodes独令。要將metrics報(bào)告到Ganglia,必須在啟動(dòng)的時(shí)候就支持Flume Agent冲呢。這個(gè)Flume Agent使用flume.monitoring作為前綴碗硬,通過(guò)下面的參數(shù)啟動(dòng)瓢颅。當(dāng)然也可以在flume-env.sh中設(shè)置:
如果要支持Ganglia挽懦,可以通過(guò)如下命令啟動(dòng)。
bin/flume-ng agent --conf-file example.conf --name a1 -Dflume.monitoring.type=ganglia -Dflume.monitoring.hosts=com.example:1234,com.example2:5455
4.自定義監(jiān)控
自定義的監(jiān)控需要實(shí)現(xiàn)org.apache.flume.instrumentation.MonitorService
接口冀偶。例如有一個(gè)HTTP的監(jiān)控類(lèi)叫HttpReporting进鸠,我可以通過(guò)如下方式啟動(dòng)這個(gè)監(jiān)控客年。
bin/flume-ng agent --conf-file example.conf --name a1 -Dflume.monitoring.type=com.example.reporting.HTTPReporting -Dflume.monitoring.node=com.example:332
報(bào)告metrics我們也可以自定義組件漠吻,不過(guò)一定要繼承org.apache.flume.instrumentation.MonitoredCounterGroup
虛擬類(lèi)途乃。Flume已經(jīng)實(shí)現(xiàn)的類(lèi),如下圖:
根據(jù)上面的規(guī)范就可以開(kāi)發(fā)自定義的監(jiān)控組件了烫饼。