Showing posts with label Flume. Show all posts
Showing posts with label Flume. Show all posts

Monday, August 7, 2017

How to cleanup flume checkpoints

Instruction on how to cleanup flume checkpoints:

1. stop flume
2. check the process and make sure it is stopped (ps -eaf | grep flume )
3. clean logs or move them to backup-log directory
4. delete checkpoint files from /data/dcm0[1-5]/flume directory
                find . -type f -print | xargs rm -rf
5. start flume service
6. monitor flume logs 

Wednesday, November 9, 2016

Flume Opentsdb config

flume config for opentsdb with kafka topic:
===============================
opentsdbflume.sources = kafka-source
opentsdbflume.channels = http-channel
opentsdbflume.sinks = http-sink

opentsdbflume.sources.kafka-source.type = org.apache.flume.source.kafka.KafkaSource
opentsdbflume.sources.kafka-source.zookeeperConnect = 135.250.193.178:2181
opentsdbflume.sources.kafka-source.topic = airtel_ims_entity_cpu_opentsdb
opentsdbflume.sources.kafka-source.batchSize = 100
opentsdbflume.sources.kafka-source.batchDurationMillis = 200
opentsdbflume.sources.kafka-source.channels = http-channel

opentsdbflume.channels.http-channel.type = memory
opentsdbflume.channels.http-channel.transactionCapacity = 1000000
opentsdbflume.channels.http-channel.capacity = 10000000

opentsdbflume.sinks.http-sink.channel = http-channel
opentsdbflume.sinks.http-sink.type = org.apache.flume.sink.HttpSink
opentsdbflume.sinks.http-sink.endpoint = http://135.250.193.178
opentsdbflume.sinks.http-sink.port = 4241
opentsdbflume.sinks.http-sink.resource = /api/put

Flume Master HA

http://archive.cloudera.com/cdh/3/flume/UserGuide/#_running_in_distributed_mode

Running in Distributed Mode:
-------------------------------------------
Distributed mode runs the Flume Master on several machines. Therefore the configuration described below should be done on every Master machine, except where noted. **

Running the Flume Master in distributed mode provides better fault tolerance than in standalone mode, and scalability for hundreds of nodes.

Configuring machines to run as part of a distributed Flume Master is nearly as simple as standalone mode. As before, flume.master.servers needs to be set, this time to a list of machines:


flume.master.servers
masterA,masterB,masterC

How many machines do I need? The distributed Flume Master will continue to work correctly as long as more than half the physical machines running it are still working and haven’t crashed. Therefore if you want to survive one fault, you need three machines (because 3-1 = 2 > 3/2). For every extra fault you want to tolerate, add another two machines, so for two faults you need five machines. Note that having an even number of machines doesn’t make the Flume Master any more fault-tolerant - four machines only tolerate one failure, because if two were to fail only two would be left functioning, which is not more than half of four. Common deployments should be well served by three or five machines.

The final property to set is not the same on every machine - every node in the Flume Master must have a unique value for flume.master.serverid.

Note. flume.master.serverid is the only Flume Master property that must be different on every machine in the ensemble. *

masterA.


flume.master.serverid
0

masterB.


flume.master.serverid
1

masterC.


flume.master.serverid
2


The value for flume.master.serverid for each node is the index of that node’s hostname in the list in flume.master.ensemble, starting at 0. For example masterB has index 1 in that list. The purpose of this property is to allow each node to uniquely identify itself to the other nodes in the Flume Master.

This is all the configuration required to start a three-node distributed Flume Master. To test this out, we can start the Master process on all three machines:

[flume@masterA] flume master

[flume@masterB] flume master

[flume@masterC] flume master
Each Master process will initially try and contact all other nodes in the ensemble. Until more than half (in this case, two) nodes are alive and contactable, the configuration store will be unable to start, and the Flume Master will not be able to read or write configuration data.

You can check the current state of the ensemble by inspecting the web page for any of the Flume Master machines which by default will be found at, for example, http://masterA:35871.

Flume Custome interceptor


flume1.sources = kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.channels = memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.sinks  = hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi


# For each source, channel, and sink, set standard properties
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.type = org.apache.flume.source.kafka.KafkaSource
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.zookeeperConnect = 135.250.193.206:2181
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.topic = airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.batchSize = 5
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.batchDurationMillis = 200
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.channels = memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi


flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.interceptors = i2
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.interceptors.i2.type = flume.interceptor.CustomInterceptor$Builder
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.selector.type = multiplexing
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.selector.mapping.US = memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.sources.kafka-source-airtel_ims_p1360com_cpqhocpuutiltable_kpi.selector.default = memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi

# Other properties are specific to each type of source, channel, or sink. In this case, we specify the capacity of the memory channel.
flume1.channels.memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi.type = memory
flume1.channels.memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi.capacity = 10000
flume1.channels.memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi.transactionCapacity = 10000

flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.channel = memory-channel-airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.type = hdfs
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.useLocalTimeStamp = false
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.path =  hdfs://135.250.193.206:8020/user/hive/warehouse/spm_database.db/spm_kpi_data/customername=%{customer}/networkid=%{networkid}/subnetwork=%{subnetwork}/entity_type=%{product}/year=%{year}/month=%{month}/day=%{day}
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.filePrefix = airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.maxOpenFiles=150
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.rollSize = 0
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.rollCount = 0
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.rollInterval = 30
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.writeFormat=Text
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.inUsePrefix=_
flume1.sinks.hdfs-sink-airtel_ims_p1360com_cpqhocpuutiltable_kpi.hdfs.fileType = DataStream

=================================
package alu.spm.flume.interceptor;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

/**
 * @author  Sangala Shakhar Reddy
 *
 */
public class CustomInterceptor implements Interceptor {


private final String yearheader = "year";
private final String monthheader = "month";
private final String dayheader = "day";

private final String customer = "customer";
private final String networkid = "networkid";
private final String subnetwork = "subnetwork";
private final String product = "product";

@Override
public Event intercept(Event event) {

String customerval = null;
String networkidrval = null;
String productVal = null;
String subnetworkval = null;
String yearheaderval = null;
String monthheaderval = null;
String dayheaderval = null;

byte[] eventBody = event.getBody();
try {

String body = new String(eventBody);
// 2015-02-13 00:01:09;00:01:09;-05:00;PT300S;PT300S;comSubscriberPmPerIpTable;1;nltcom01;1;4;10;6;1;1234.06;4321.04;KA;2015-02-13 00:01:09$Airtel$IMS_1$1360COM;last_hour_cpu_utilization_kpi;100
String[] strs = body.split(";");
String res = strs[strs.length - 3];
String[] p = res.split("#");


String aDate = p[0];
// String aDate = "2012-04-13 sdfsd00:00:00";
// String aDate = "2012-4-13";
Pattern datePattern = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2})");
Matcher dateMatcher = datePattern.matcher(aDate);
if (dateMatcher.find()) {
yearheaderval = dateMatcher.group(1);
monthheaderval = dateMatcher.group(2);
dayheaderval = dateMatcher.group(3);
}

customerval = p[1];
networkidrval = p[2];
subnetworkval = p[3];
productVal = p[4];
// event.setBody("test insert".getBytes());
} catch (Exception e) {
e.printStackTrace();
}
// depeen 95602 63623

Map headers = event.getHeaders();
headers.put(customer, customerval);
headers.put(networkid, networkidrval);
headers.put(subnetwork, subnetworkval);
headers.put(product, productVal);
headers.put(yearheader, yearheaderval);
headers.put(monthheader, monthheaderval);
headers.put(dayheader, dayheaderval);

event.setHeaders(headers);
return event;
}

@Override
public void close() {
// TODO Auto-generated method stub

}

@Override
public void initialize() {
// TODO Auto-generated method stub

}

@Override
public List intercept(List events) {
for (Iterator iterator = events.iterator(); iterator.hasNext();) {
Event next = intercept((Event) iterator.next());
if (next == null) {
iterator.remove();
}
}
return events;
}

public static class Builder implements Interceptor.Builder {
@Override
public void configure(Context context) {
// TODO Auto-generated method stub
}

@Override
public Interceptor build() {
return new CustomInterceptor();
}
}

}

Flume Elastic Search config

flume1.sources = source1
flume1.channels = channel1
flume1.sinks = k1

flume1.channels.channel1.type = memory
flume1.channels.channel1.capacity = 10000000
flume1.channels.channel1.transactionCapacity = 1000

# For each source, channel, and sink, set standard properties
flume1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
flume1.sources.source1.zookeeperConnect = 135.250.193.206:2181
flume1.sources.source1.topic = airtel_ims_p1360com_cpqhocpuutiltable_kpi
flume1.sources.source1.batchSize = 5
flume1.sources.source1.batchDurationMillis = 200
flume1.sources.source1.channels = channel1


flume1.sinks.k1.channel = channel1
flume1.sinks.k1.type = elasticsearch
flume1.sinks.k1.batchSize = 100
flume1.sinks.k1.hostNames = 135.250.193.206:9300
flume1.sinks.k1.indexName = p1360com_cpqhocpuutiltable_index
flume1.sinks.k1.indexType = p1360com_cpqhocpuutiltable_type
flume1.sinks.k1.clusterName = spmdevteam
flume1.sinks.k1.serializer = org.apache.flume.sink.elasticsearch.ElasticSearchDynamicSerializer

Flume - Sannpy and create tmp file with prefix _

flume1.sources = kafka-source-ip_cardstatus_kpi
flume1.channels = memory-channel-ip_cardstatus_kpi
flume1.sinks  = hdfs-sink-ip_cardstatus_kpi

# For each source, channel, and sink, set standard properties
flume1.sources.kafka-source-ip_cardstatus_kpi.type = org.apache.flume.source.kafka.KafkaSource
flume1.sources.kafka-source-ip_cardstatus_kpi.zookeeperConnect = 135.250.193.206:2181
flume1.sources.kafka-source-ip_cardstatus_kpi.topic = ip_cardstatus_kpi_enriched
flume1.sources.kafka-source-ip_cardstatus_kpi.batchSize = 5
flume1.sources.kafka-source-ip_cardstatus_kpi.batchDurationMillis = 200
flume1.sources.kafka-source-ip_cardstatus_kpi.channels = memory-channel-ip_cardstatus_kpi

flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors = i1
flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors.i1.type=regex_extractor
flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors.i1.regex = (\d\d\d\d-\d\d-\d\d)
flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors.i1.serializers = s1
flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors.i1.serializers.s1.type = org.apache.flume.interceptor.RegexExtractorInterceptorMillisSerializer
flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors.i1.serializers.s1.name = timestamp
flume1.sources.kafka-source-ip_cardstatus_kpi.interceptors.i1.serializers.s1.pattern =yyyy-MM-dd

# Other properties are specific to each type of source, channel, or sink. In this case, we specify the capacity of the memory channel.
flume1.channels.memory-channel-ip_cardstatus_kpi.type = memory
flume1.channels.memory-channel-ip_cardstatus_kpi.capacity = 10000
flume1.channels.memory-channel-ip_cardstatus_kpi.transactionCapacity = 10000

flume1.sinks.hdfs-sink-ip_cardstatus_kpi.channel = memory-channel-ip_cardstatus_kpi
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.type = hdfs
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.useLocalTimeStamp = false
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.path =  hdfs://135.250.193.206:8020/user/hive/warehouse/spm_database.db/ip_cardstatus_kpi/year=%Y/month=%m/day=%d
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.filePrefix = ip_cardstatus_kpi
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.maxOpenFiles=150
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.rollSize = 0
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.rollCount = 0
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.rollInterval = 30
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.writeFormat=Text
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.inUsePrefix=_
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.fileType = CompressedStream
flume1.sinks.hdfs-sink-ip_cardstatus_kpi.hdfs.codeC=snappy

Static flume interceptor

 tier1.sources  = source1
 tier1.channels = channel1
 tier1.sinks = sink1

 tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
 tier1.sources.source1.zookeeperConnect = 135.250.193.206:2181
 tier1.sources.source1.topic = flum_test
 tier1.sources.source1.groupId = flume
 tier1.sources.source1.channels = channel1

 tier1.sources.source1.interceptors = i1
 tier1.sources.source1.interceptors.i1.type = static
 tier1.sources.source1.interceptors.i1.key = one
 tier1.sources.source1.interceptors.i1.value = 1

 tier1.channels.channel1.type = memory
 tier1.channels.channel1.capacity = 10000
 tier1.channels.channel1.transactionCapacity = 1000

 tier1.sinks.sink1.type = hdfs
 #tier1.sinks.sink1.hdfs.path = /tmp/kafka/%{topic}/%y-%m-%d
 tier1.sinks.sink1.hdfs.path =hdfs://135.250.193.206:8020/user/hive/warehouse/spm_database.db/%{topic}/%{one}
 tier1.sinks.sink1.hdfs.rollInterval = 5
 tier1.sinks.sink1.hdfs.rollSize = 0
 tier1.sinks.sink1.hdfs.rollCount = 0
 tier1.sinks.sink1.hdfs.fileType = DataStream
 tier1.sinks.sink1.channel = channel1

Flume config - without source


agent1.sinks = sink1
agent1.channels = channel1

# Describe channel here
agent1.channels.channel1.type = org.apache.flume.channel.kafka.KafkaChannel
agent1.channels.channel1.brokerList = 135.250.193.206:9092
agent1.channels.channel1.topic = flum_test
agent1.channels.channel1.zookeeperConnect = 135.250.193.206:2181
agent1.channels.channel1.parseAsFlumeEvent=false
                                                                                                                                                                             
agent1.channels.channel1.transactionCapacity = 1000000
agent1.channels.channel1.checkpointInterval = 30000
agent1.channels.channel1.maxFileSize = 2146435071
agent1.channels.channel1.capacity= 10000000

agent1.sinks.sink1.channel = channel1

# Describe sink1                                                                                                                                                                                                                          
agent1.sinks.sink1.type = hdfs
agent1.sinks.sink1.hdfs.path =  hdfs://135.250.193.206:8020/user/hive/warehouse/spm_database.db/flum_test/year=%Y/month=%m/day=%d
agent1.sinks.sink1.hdfs.useLocalTimeStamp = true
agent1.sinks.sink1.hdfs.filePrefix = LogCreateTest

agent1.sinks.sink1.hdfs.rollInterval = 600
agent1.sinks.sink1.hdfs.rollSize = 0
agent1.sinks.sink1.hdfs.rollCount = 10000
agent1.sinks.sink1.hdfs.batchSize = 10000
agent1.sinks.sink1.hdfs.txnEventMax = 40000
agent1.sinks.sink1.hdfs.fileType = DataStream
agent1.sinks.sink1.hdfs.maxOpenFiles=50
agent1.sinks.sink1.hdfs.appendTimeout = 10000
agent1.sinks.sink1.hdfs.callTimeout = 10000
agent1.sinks.sink1.hdfs.threadsPoolSize=100
agent1.sinks.sink1.hdfs.rollTimerPoolSize = 1

Steps to install flume

service iptables stop
service ip6tables stop
sudo yum install flume-ng flume-ng-agent flume-ng-doc
sudo yum install flume-ng-agent
sudo yum install flume-ng-doc


If flume not comming up then run below commands:
sudo service cloudera-scm-agent hard_stop
service cloudera-scm-agent start