1 #+date: 2018-09-11 21:09:06 +0800
2 #+filetags: Apache Nifi Kafka bigdata streaming
3 #+title: Using Apache Nifi and Kafka - big data tools
5 Working in analytics these days, the concept of big data has been firmly
6 established. Smart engineers have been developing cool technology to
7 work with it for a while now. The [[Apache Software
8 Foundation|https://apache.org]] has emerged as a hub for many of these -
9 Ambari, Hadoop, Hive, Kafka, Nifi, Pig, Zookeeper - the list goes on.
11 While I'm mostly interested in improving business outcomes applying
12 analytics, I'm also excited to work with some of these tools to make
15 Over the past few weeks, I have been exploring some tools, installing
16 them on my laptop or a server and giving them a spin. Thanks to
17 [[Confluent, the founders of Kafka|https://www.confluent.io]] it is
18 super easy to try out Kafka, Zookeeper, KSQL and their REST API. They
19 all come in a pre-compiled tarball which just works on Arch Linux.
20 (After trying to compile some of these, this is no luxury - these apps
21 are very interestingly built...) Once unpacked, all it takes to get
28 I also spun up an instance of
29 [[nifi|https://nifi.apache.org/download.html]], which I used to monitor
30 a (json-ised) apache2 webserver log. Every new line added to that log
31 goes as a message to Kafka.
33 [[Apache Nifi configuration|/pics/ApacheNifi.png]]
35 A processor monitoring a file (tailing) copies every new line over to
36 another processor publishing it to a Kafka topic. The Tailfile monitor
37 includes options for rolling filenames, and what delineates each
38 message. I set it up to process a custom logfile from my webserver,
39 which was defined to produce JSON messages instead of the somewhat
40 cumbersome to process standard logfile output (defined in apache2.conf,
41 enabled in the webserver conf):
44 LogFormat "{ "time":"%t", "remoteIP":"%a", "host":"%V",
45 "request":"%U", "query":"%q", "method":"%m", "status":"%>s",
46 "userAgent":"%{User-agent}i", "referer":"%{Referer}i", "size":"%O" }"
50 All the hard work is being done by Nifi. (Something like
53 tail -F /var/log/apache2/access.log | kafka-console-producer.sh --broker-list localhost:9092 --topic accesslogapache
56 would probably be close to the CLI equivalent on a single-node system
57 like my test setup, with the -F option to ensure the log rotation
58 doesn't break things. Not sure how the message demarcator would need to
61 The above results in a Kafka message stream with every request hitting
62 my webserver in real-time available for further analysis.