Skip to content

Sample application to capture MQTT Events from IOT devices and monitors it through ELK

Notifications You must be signed in to change notification settings

RitreshGirdhar/IOT-DeviceMonitoring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

IOT Device Monitoring Sample Application

Sample application to capture Events from IOT devices and monitors it through ELK or store it in events-store or some time-series database for further processing.

Pre-requisite

  • Basic knowledge of Git + Docker + Mqtt + Rabbit MQ

Here i am taking a very basic example of capturing weather temperature city-wise. You could use it for any another event capturing.

Purpose of this application is to give you enough idea to set up your own message broker & device-monitoring.

Below are the most Popular Internet of Things Protocols and standard communication technologies :

  • MQTT
  • DDS
  • AMQP
  • Bluetooth
  • Zigbee

In this tutorial i am using MQTT protocol. To capture events from IOT devices we require mqtt broker to consume the generated events and store it for further processing.

I am using RabbitMQ as MQTT broker (read it)and to simulate behavior of IOT devices event generation i will use mosquitto's publisher.
Refer this to understand basic understanding of RabbitMQ.

Pre-requisites :

  1. Basic understanding of RabbitMQ and ELK.
  2. Install RabbitMQ Server.
  3. Install mosquitto package.
  4. Set up ELK on your machine.

Rabbit MQ Configuration. ** Make sure to enable mqtt plugin in rabbitmq using below command:

rabbitmq-plugins enable rabbitmq_mqtt
  1. Creating Queue: Creating Queue

  2. Binding exchange with Queue by routing Key : Binding Exchange with queue

  3. Publising message Publishing message with routing key

  4. Message received Message recieved

Hope you have installed mosquitto package. Now let's try to send some message through mosquitto_pub.

mosquitto_pub  -h 127.0.0.1 -t weather.mumbai -m "{"temperature":{"min":21,"max":29,"unit":"celsius"},"time":1568881230}" -u guest -P guest -p 1883 -d

Let's check weather events queue in Rabbit MQ.

Message recieved

Start logstash with configuration i.e logstash-rabbitmq.conf. It is a basic configuration,which will read from RabbitMQ and dump events into weather index in Elastic Search.

paste below conf in logstash-rabbitmq.conf file

input {
    rabbitmq {
        host => "localhost"
        port => 15672
        heartbeat => 30
        durable => true
        exchange => "amq.topic"
        exchange_type => "topic"
        key => "weather.*"
    }
}
output {
    elasticsearch {
        hosts => "localhost:9200"
        index => "weather"
    }
    stdout {}
}

Start logstash

logstash -f <path>/logstash-rabbitmq.conf

After logstash startup , you will see logstash queue get created and binded with weather* events in RabbitMQ

Logstash configured

Let's publish some test messages through RabbitMQ GUI

Publish test message

Now let's check kibana dashboard of weather-index. As you could see in below Kibana search that our weather-mumbai event received by Elastic-Search through logstash.

Kibana received Message

Now let's test it through MQTT client/IOT Device (in our case its mosquitto_pub)

$ mosquitto_pub  -h 127.0.0.1 -t weather.mumbai -m '{"temperature":{"min":21,"max":32,"unit":"celsius"},"timestamp":"2019-09-19T18:59:00"}' -u guest -P guest -p 1883 -d

Kibana received Message 1