Monitoring = (Elasticsearch + Logstash + Kibana ) + Kafka * Flink
Tags: softwareengineering, beats, bigdata, dataprocessing
Published: 2018-02-10 22:35:56

---
title: "Monitoring = (Elasticsearch + Logstash + Kibana ) + Kafka * Flink"
published: true
tags: software-engineering,beats,bigdata,data processing
canonical_url: 
---

I used to be regular business developer. Delphi, then Java. Recently working somewhere, where project was not veery interesting I came to the conclusion: I would like to bring a real business value here.

Then **Elasticsearch** came to my mind…

I was working with it in the previous place, but here, Look! no one using ES. [**Docker**](https://docs.docker.com/)was one of the milestones of this journey. &nbsp;Now, having dozens of applications running on I cannot imagine size of the effort needed to run each of these apps manually. &nbsp;Now? &nbsp;It is a piece of cake.

Using prepared Docker images I was able to build monitoring system, providing **historical** and **real-time analysis**. &nbsp;Let me introduce, what building blocks are there. &nbsp;I shall also provide with some exemplary docker-compose scripts and config file. Undeniable proof of ease of the configuration.

## File and resources are monitored…

**Beats&nbsp;** are listening. &nbsp;This is their task. &nbsp; With their help&nbsp;it is easy to monitor resources like server’s state, files or web applications. Name something, and [they will monitor that](https://www.elastic.co/products/beats). &nbsp;All what I needed could be easily done using beats, like&nbsp;Filebeat and&nbsp;Metricbeat. &nbsp;This small Go-powered apps are carefully watching what is going on somewhere – _input_, and loyally reporting that towards the _output. &nbsp;_Beats can send data directly to heart of ELK system Elasticsearch or indirectly via Logstash. &nbsp;Configuring? In Yaml it can be done that way

```
filebeat.prospectors:
- input_type: log
  paths:
  - /var/log/*.log
output.logstash:
  hosts: ["127.0.0.1:5044"]
```

&nbsp;

## … then parsed…

Messages coming from Filebeat can be parsed using [**grok** expressions](https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html). This is more-or-less similar to the well-known regular expressions. Data is being taken as raw text and produces documents, say JSONs. Then documents can be enriched, f.e. with City name basing on GPS coordinates. Now we are ready to go, we may store it or send further. Following you will find exemplary logstash configuration.

```
input {
  beats {
    port =&gt; 5044
  }
}

output {
  elasticsearch {
    hosts =&gt; "localhost:9200"
    index =&gt; "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type =&gt; "%{[@metadata][type]}"
  }
}
```

This configuration assumes we want to listen to the messages coming directly from Logstash and provide them to Elasticsearch, further on.

## … reaching persistance …

The persistance is [Elasticsearch](https://www.elastic.co/products/elasticsearch). It is not the database in full meaning of the phrase. Elasticsearch is the search engine with Lucene engine underneath. You can easily browse it in near real-time, querying using all riches of full-text search. Running distributed Elasticsearch in docker-ready environment can be easy as this:

```
version: '2'
services:
  elasticsearch1:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.5.0
    container_name: elasticsearch1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.5.0
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet
```

.. and fire `docker-compose up` once.

## … browsing in Kibana!

[Kibana](https://www.elastic.co/products/kibana)is just the GUI tool for all of this. If you are not a big fan of REST querying, via Postmans or other tools, just view it. We are humans. While doing one of the Udacity trainings there was [a great lesson about Data Visualization](http://lukcreates.pl/data-science/data-visualization-is-data-communication/). How important it is to present meaningful information in a way easily understood by men.

## Real time? No problem

In parallel, the whole system takes it into the data stream. Data stream is produced in the very same Filebeat, which pushes it towards the stream of [**Kafka** &nbsp;platform](https://kafka.apache.org/). Then consumer being [**Flink**](https://flink.apache.org/)application collects messages and puts them into window or time-based buckets, sending it then forward toward the alerting machines. Then some logic can be set up, f.e. _when N messages in M seconds occur, alert me._

## Summary

Building all of these blocks without Docker-prepared images would not be so easy. &nbsp;Monitoring systems will gain more and more popularity – in my opinion. &nbsp;Be watchful. &nbsp;And care!