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