Big data in minutes with the ELK Stack
We’ve built a data analysis and dashboarding infrastructure for one of our clients over the past few weeks. They collect about 10 million data points a day. Yes, that’s big data.
My highest priority was to allow them to browse the data they collect so that they can ensure that the data points are consistent and contain all the attributes required to generate the reports and dashboards they need.
ElasticSearch is a schema-less database that has powerful search capabilities and is easy to scale horizontally. Schema-less means that you just throw JSON at it and it updates the schema as you go. It indexes every single field, so you can search anything (with full-text search) and it will aggregate and group the data. Registering a new node to a cluster is a matter of installing ElasticSearch on a machine and editing a config file. ElasticSearch takes care of spreading data around and splitting out requests over multiple servers.
logstash allows you to pipeline data to and from anywhere. This is called an ETL (for Extract, Transform, Load) pipeline in the Business Intelligence and Data warehousing world, and it is what allows us to fetch, transform, and store events into ElasticSearch.
Kibana is a web-based data analysis and dashboarding tool for ElasticSearch. It leverages ElasticSearch’s search capabilities to visualise your (big) data in seconds.
logstash: ETL pipeline made simple
logstash is a simple tool that streams data from one or many inputs, transforms it and outputs it to one or many outputs.
Inputs: read and parse data
Inputs are data sources such as log files (
/var/log/*.log) or data stored in a S3 bucket, RabbitMQ, redis, etc. Once the raw data is read, logstash parses it using codecs such as JSON, key=value, graphite format etc. You can find a full list of inputs and codecs on logstash documentation.
Let’s write a logstash configuration file to load data from an S3 bucket containing text files with one JSON blob per line.
Filters: transform and extend data
We now have data in the logstash pipeline. It’s time to transform it a little. Take this sample input file:
We can get logstash to generate a proper @timestamp field (later used by Kibana) and to add geolocalization using the IP address with the following filters:
Output: load data
The output section is quite similar to the input one. You can output to stdout (handy for debugging purpose or to pipe into another command) as well as storing on S3, loading into a database such as ElasticSearch etc.
Let’s output to stdout using the
and run logstash to ensure that everything is wound up properly:
Nice, all attributes were parsed properly and we now have @timestamp and geoip attributes.
Our final configuration file looks like this:
There is quite a lot going on in just a few lines of code, eh?
On top of this, logstash keeps track of the inputs it has processed. So you can restart it without being concerned of data duplication.
Although logstash is written in Ruby, it is really fast. The packaged version runs on JRuby and it takes advantage of the JVM’s threading capabilities by throwing dozens of threads to parallelize data processing.
ElasticSearch & Kibana
Setting this up in production
There is an excellent chef cookbook to deploy logstash in minutes.
We decided to use a hosted solution to manage the ElasticSearch cluster. The top two seem to be qbox.io and found.no. found.no provides reserved instances and allows you to scale your cluster without any downtime.
Kibana comes as a plugin on all hosted ElasticSearch services, so you just have to tick a checkbox and you’re ready to go!
Performance wise, an ElasticSearch cluster with 4x Amazon EC2 c3.xlarge is sufficient to run Kibana reports on the last 30 days. This is about 300 million data entries.
ELK - to store and visualize huge amounts of data in minutes
logstash enabled us to deliver an ETL pipeline that is highly performant, reliable and easy to maintain in a matter of hours. Elastic Search is a no brainer database that ingests anything you throw at it and scales horizontally when need be. Kibana allows you to make sense of your data and publish dashboards in minutes. I recommend you giving it a try to these powerful and simple tools.
Kibana 4 is on the way, and a final version should be released in the next couple of months. It provides new features to generate business-oriented reports such as unique counts, funnels, etc. Until then, and to report on years of data, we’ve implemented a pipeline to load data into the data warehouse solution Amazon Redshift. But this is a whole other story.
If this is a project you’re working on and would like some help with, reach out for a chat!