Sensor Data Analytics Application

本案例参考自https://github.com/pranav-shukla/learningelasticstack/tree/master/chapter-10

ELK版本为5.6.12

数据构成

下面是sql的三个表通过关联sensorType得出的数据

sensorType customer department buildingName room floor locationOnFloor latitude longitude
Temperature Abc Labs R & D 222 Broadway 101 Floor1 C-101 40.710936 -74.0085

下面是sensor数据

sensor_id time value
1 1511935948000 21.89

在导入elasticsearch前把上面两种数据进行整合,即一条数据包含上面12个field。

数据模型设计

mysql表数据脚本可以到之前提到的GitHub下载。

POST _template/sensor_data_template
{
"template" : "sensor_data*", # 这里6.0可能不一样
"settings": {
"number_of_replicas": "1",
"number_of_shards": "5"
},
"mappings": {
"doc": {
"properties": {
"sensorId": {
"type": "integer"
},
"sensorType": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"customer": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"department": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"buildingName": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"room": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"floor": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"locationOnFloor": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
"location": {
"type": "geo_point"
},
"time": {
"type": "date"
},
"reading": {
"type": "double"
}
}
}
}
}

Logstash配置

下面logstash配置会从sensor_data_http_input获取数据,然后filter从mysql中拉去信息来补充数据,成为lookupResult field,这需要mutate来展开,最后删除三个多余的fields。

jdbc_streaming插件的安装./bin/logstash-plugin install logstash-filter-jdbc_streaming

input {
http {
host => "localhost"
port => 8080
id => "sensor_data_http_input"
user => "sensor_data"
password => "sensor_data"
}
} filter {
jdbc_streaming {
jdbc_driver_library => "/Users/flyang/Documents/big_data/hive-1.1.0-cdh5.11.2/lib/mysql-connector-java-5.1.46.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/sensor_metadata"
jdbc_user => "root"
jdbc_password => "password"
statement => "select st.sensor_type as sensorType, l.customer as customer, l.department as department, l.building_name as buildingName, l.room as room, l.floor as floor, l.location_on_floor as locationOnFloor, l.latitude, l.longitude from sensors s inner join sensor_type st on s.sensor_type_id=st.sensor_type_id inner join location l on s.location_id=l.location_id where s.sensor_id= :sensor_identifier"
parameters => { "sensor_identifier" => "sensor_id"}
target => lookupResult
} mutate {
rename => {"[lookupResult][0][sensorType]" => "sensorType"}
rename => {"[lookupResult][0][customer]" => "customer"}
rename => {"[lookupResult][0][department]" => "department"}
rename => {"[lookupResult][0][buildingName]" => "buildingName"}
rename => {"[lookupResult][0][room]" => "room"}
rename => {"[lookupResult][0][floor]" => "floor"}
rename => {"[lookupResult][0][locationOnFloor]" => "locationOnFloor"}
add_field => {
"location" => "%{lookupResult[0]latitude},%{lookupResult[0]longitude}"
}
remove_field => ["lookupResult", "headers", "host"]
} } output {
elasticsearch {
hosts => ["localhost:9200"]
index => "sensor_data-%{+YYYY.MM.dd}"
}
}

测试代码

将上面的output换成
output {stdout {} } 发送信息到logstash的监听端口
curl -XPOST -u sensor_data:sensor_data --header "Content-Type:application/json" "http://localhost:8080/" -d '{"sensor_id":1,"time":1512102540000,"reading":16.24}'

搭建好Logstash后通过脚本发送数据到elasticsearch后就可以使用Kibana进行分析了。

Kibana可视化

打开kibana,在management中新增index pattern:sensor_data*,选择Time Filter field name为time。下面是目标:

  • How does the average temperature/humidity change over time?
  • How do temperature change at each location over time?
  • Can I visualize temperature and humidity over a map?(地图精度有限)
  • How are the sensors distributed across buildings?

基于ELK的传感器数据分析练习的更多相关文章

  1. 基于ELK的简单数据分析

    原文链接: http://www.open-open.com/lib/view/open1455673846058.html 环境 CentOS 6.5 64位 JDK 1.8.0_20 Elasti ...

  2. HDInsight-Hadoop现实(两)传感器数据分析

    HDInsight-Hadoop现实(两)传感器数据分析 简要 现在,含传感器非常个人和商用设备收集来自物理世界的信息.例如.大多数手机都有 GPS.健身器材可以跟踪的步骤,你去数,恒温控制器可以监视 ...

  3. 基于ELK进行邮箱访问日志的分析

    公司希望能够搭建自己的日志分析系统.现在基于ELK的技术分析日志的公司越来越多,在此也记录一下我利用ELK搭建的日志分析系统. 系统搭建 系统主要是基于elasticsearch+logstash+f ...

  4. (数据科学学习手札74)基于geopandas的空间数据分析——数据结构篇

    本文对应代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 geopandas是建立在GEOS.GDAL.P ...

  5. (数据科学学习手札75)基于geopandas的空间数据分析——坐标参考系篇

    本文对应代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在上一篇文章中我们对geopandas中的数据结 ...

  6. (数据科学学习手札77)基于geopandas的空间数据分析——文件IO

    本文对应代码和数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在上一篇文章中我们对geopandas中的 ...

  7. (数据科学学习手札78)基于geopandas的空间数据分析——基础可视化

    本文对应代码和数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 通过前面的文章,我们已经对geopanda ...

  8. (数据科学学习手札79)基于geopandas的空间数据分析——深入浅出分层设色

    本文对应代码和数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 通过前面的文章,我们已经对geopanda ...

  9. (数据科学学习手札82)基于geopandas的空间数据分析——geoplot篇(上)

    本文示例代码和数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在前面的基于geopandas的空间数据分 ...

随机推荐

  1. 3W法则-学习Docker

    一.前言       5W1H法则是在一次面试中学习到的,后来在工作也开始使用这种东西,虽然最后没去那家公司,但是也是学习到了,关注开这些东西以后,也发现了一些简化版的3W法则,最近公司也要搞Doce ...

  2. 理解javascript中的Array类型

    引子: 从事前端开发有段时间了,个人观点:想在前端开发这条路上走的更远,不仅要学好HTML&HTML5.CSS&CSS3,最重要的就是要学好javascript了.所以打好javasc ...

  3. java连接mysql数据库中文乱码问题

    private static final String URL="jdbc:mysql://localhost:3306/ziye?useUnicode=true&character ...

  4. HDU 4945 (dp+组合数学)

    2048 Problem Description Teacher Mai is addicted to game 2048. But finally he finds it's too hard to ...

  5. JPA中映射关系详细说明(一对多,多对一,一对一、多对多)、@JoinColumn、mappedBy说明

    JPA中的映射关系 jpa中维护one to one ,one to many, many to one ,many to many 四种映射关系. 在每个关系中,双方中的一方在其表中拥有连接列.那么 ...

  6. 使用谷歌Z生成条形码以及二维码

    下载地址:http://zxingnet.codeplex.com/ zxing.net是.net平台下编解条形码和二维码的工具,使用非常方便. 首先下载二进制dll文件,引入工程: using Sy ...

  7. Linux下汇编语言学习笔记67 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  8. [HDU5306]Gorgeous Sequence(标记回收线段树)

    题意:维护一个序列,支持区间与一个数取min,询问区间最大,询问区间和(序列长度<=1e6) 分析: http://www.shuizilong.com/house/archives/hdu-5 ...

  9. Postgis经常使用函数

    1,基本操作函数 AddGeometryColumn(<schema_name>, <table_name>,<column_name>, <srid> ...

  10. eclipse 开发jsp 智能提示设置

    1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist 改动Auto Activation triggers for java的值为:.a ...