For flume monitoring, only the performance data of the channel needs to be monitored, and the performance of source and sink can be represented from the channel.
Taking Memorychannel as an example, a Org.apache.flume.instrumentation.ChannelCounter object is instantiated in the Memorytransaction constructor
Public memorytransaction (int transcapacity, Channelcounter counter) {putlist = new linkedblockingdeque<event> (transcapacity); Takelist = new linkedblockingdeque<event> (transcapacity); Channelcounter = counter; }
Org.apache.flume.instrumentation.ChannelCounter defines several counters used to record the performance data of the channel.
private static final String counter_channel_size = "Channel.current.size"; The capacity size that has been used private static final String counter_event_put_attempt = "Channel.event.put.attempt"; Source to channel attempt to insert data (whether or not successful) private static final String counter_event_take_attempt = "Channel.event.take.attempt" ; Sink data to be consumed from the channel (whether or not successful) private static final String counter_event_put_success = "channel.event.put.success"; Source to channel successfully inserted data private static final String counter_event_take_success = "channel.event.take.success"; Sink data from the CHANNEL successfully consumed private static final String counter_channel_capacity = "channel.capacity"; Total capacity Size
and encapsulates the relevant methods to manipulate these performance counters:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/17/wKiom1T1w3CynIp-AAFVrItasOA700.jpg "title=" 1.png " alt= "Wkiom1t1w3cynip-aafvritasoa700.jpg"/>
For example, Channel.event.put.attempt is operated by Geteventputattemptcount and Incrementeventputattemptcount:
Public long Incrementeventputattemptcount () {//used to increase the number of 1 return increment (counter_event_put_attempt); The public long Geteventputattemptcount () {///is used to get the value return get (counter_event_put_attempt); }
These methods are used in the relevant operations of the channel:
protected void doput (event event) throws interruptedexception { channelcounter.incrementeventputattemptcount (); // For example, when the operation of inserting data starts, increase the value of Channel.event.put.attempt int eventbytesize = (int) Math.ceil (estimateeventsize (event)/ bytecapacityslotsize); if (! putlist.offer (event)) { throw new channelexception ( "put queue for MemoryTransaction of capacity " + putlist.size () + " full, consider committing more frequently, " + " increasing capacity or increasinG thread count " ); } putbytecounter += eventbytesize; }
Counter register use, take Memorychannel correlation as an example:
Channelcounter extends the Monitoredcountergroup class and implements the Channelcountermbean interface
Monitoredcountergroup is an abstract class whose specific implementation class defines the specific component's performance counters and corresponding encapsulation methods
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5A/17/wKiom1T1w5Oimh3vAAEQLzntWLo002.jpg "title=" 2.png " alt= "Wkiom1t1w5oimh3vaaeqlzntwlo002.jpg"/>
All of the available counter included in the Channelcounter:
private static final string[] ATTRIBUTES = {counter_channel_size, counter_event_put_attempt, Counter_event_take_att Empt, counter_event_put_success, counter_event_take_success, counter_channel_capacity};
The construction method of the Channelcounter method calls Monitoredcountergroup:
public channelcounter (string name) { super ( monitoredcountergroup.type. channel, name, attributes ); // Call the Monitoredcountergroup constructor method }monitoredcountergroup Construction Method:private final map<string, Atomiclong> countermap;.... protected monitoredcountergroup (Type type, String name, string... attrs) { this. type = type; this. name = name; Map<String, Atomiclong> counterinitmap = new hashmap<string, atomiclong> (); // declares an initial hashmap that is used to store counter name to value correspondence // Initialize the counters for (string attribute : attrs) { counterinitmap.put (Attribute, new atomiclong (0L)); //initial value is 0 } countermap = Collections.unmodifiablemap (COUNTERINITMAP); //return hashmap non-changing map view starttime = new atomiclong (0L); stoptime = new atomiclong (0L); }
Here type is an enum type, which is the desired value:
public static enum Type {SOURCE, channel_processor, CHANNEL, Sink_processor, SINK, Interceptor, SERI Alizer, other};
Starting in the Start method in Memorychannel:
Public synchronized void Start () {Channelcounter.start ();//Call the Start method of Monitoredcountergroup Channelcounter.setchann Elsize (Queue.size ()); Channelcounter.setchannelcapacity (Long valueOf (queue.size () + queue.remainingcapacity ())); Super.start (); }
Monitoredcountergroup.start:
public void Start () {register ();//Call the Register method for registering counter, mainly calling Managementfactory. Getplatformmbeanserver (). Registermbean (this, objname); Register an Mbean operation to register the Channelcounter object as an Mbean stoptime.set (0L); For (String Counter:counterMap.keySet ()) {Countermap.get (counter). Set (0L);//Setting value is 0} starttime.set (System. Currenttimemillis ()); Logger.info ("Component type:" + Type + ", Name:" + name + "Started"); }
The monitoring items that can be obtained through JMX
This article is from the "Food and Light Blog" blog, please make sure to keep this source http://caiguangguang.blog.51cto.com/1652935/1617019
Flume Channel Monitor realizes