Kibana的图形化——Tile Map
2016-01-06 15:13
253 查看
简介
当我们查看访问网站的流量的来源时,往往通过awk+sed或其他工具分析日志文件,有没有一种方式可以实时查看并且在地图上直观的表现出来?当然,我们的Kibana就可以做到,下面我们来看看如何配置吧。配置
本文是在http://http://blog.csdn.net/yanggd1987/article/details/50460246博文基础上进行配置,所有的配置文件都可在博文中找到。1.安装GeoIP数据库
cd /usr/local/logstash/etc curl -O "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz" gunzip GeoLiteCity.dat.gz
2.配置logstash使用GeoIP
只需要在原来的logstash.conf中添加filter即可
vim /usr/local/logstash/etc/logstash.conf input { file { path => "/data/nginx/logs/access_java.log" type => "nginx-access" start_position => "beginning" sincedb_path => "/usr/local/logstash/sincedb" codec => "json" } } filter { if [type] == "nginx-access" { geoip { source => "clientip" target => "geoip" database => "/usr/local/logstash/etc/GeoLiteCity.dat" add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] } mutate { convert => [ "[geoip][coordinates]", "float"] } } } output { if [type] == "nginx-access" { elasticsearch { hosts => ["10.10.20.16:9200"] manage_template => true index => "nginx-access-%{+YYYY-MM}" } } }
3.重启logstash即可。
Kibana出图及trouble shooting
访问10.10.10.16:5601,登录kibana1.“Settings”刷新“Index Patterns”
刷新后,我们就可以看到geoip的相关字段了。
2.“Visualize”新建Tile map
3.通过聚合器来创建map
如图:报错“No Compatible Fields: The “[nginx-access-]YYYY-MM” index pattern does not contain any of the following field types: geo_point”
原因:索引格式为[nginx-access-]YYYY-MM的日志文件由logstash输出到Elasticsearch;在 elasticsearch 中,所有的数据都有一个类型,什么样的类型,就可以在其上做一些对应类型的特殊操作。geo信息中的location字段是经纬度,我们需要使用经纬度来定位地理位置;在 elasticsearch 中,对于经纬度来说,要想使用 elasticsearch 提供的地理位置查询相关的功能,就需要构造一个结构,并且将其类型属性设置为geo_point,此错误明显是由于我们的geo的location字段类型不是geo_point。
我们可以通过以下方式验证一下:
curl -XGET http://127.0.0.1:9200/nginx-access-2016-01/_mapping/ {"nginx-access-2016-01":{"mappings":{"nginx-access":{"properties":{"@timestamp":{"type":"date","format":"dateOptionalTime"},"@version":{"type":"string"},"cache_status":{"type":"string"},"clientip":{"type":"string"},"geoip":{"properties":{"area_code":{"type":"long"},"city_name":{"type":"string"},"continent_code":{"type":"string"},"coordinates":{"type":"double"},"country_code2":{"type":"string"},"country_code3":{"type":"string"},"country_name":{"type":"string"},"dma_code":{"type":"long"},"ip":{"type":"string"},"latitude":{"type":"double"},"location":{"type":"double"},"longitude":{"type":"double"},"postal_code":{"type":"string"},"real_region_name":{"type":"string"},"region_name":{"type":"string"},"timezone":{"type":"string"}}},"host":{"type":"string"},"http_host":{"type":"string"},"message":{"type":"string"},"method":{"type":"string"},"path":{"type":"string"},"protocol":{"type":"string"},"referer":{"type":"string"},"status":{"type":"string"},"tags":{"type":"string"},"type":{"type":"string"},"url":{"type":"string"},"useragent":{"type":"string"}}}}}}
其中”location”:{“type”:”double”},字段类型是double,而不是geo_point,因此会报图中的错误。
**解决方法:**Elasticsearch 支持给索引预定义设置和 mapping(前提是你用的 elasticsearch 版本支持这个 API,不过估计应该都支持)。其实ES中已经有一个默认预定义的模板,我们只要使用预定的模板即可,我们在ES中看下模板。
那为什么还会报错呢?因为默认预定义的模板必须只有匹配 logstash-* 的索引才会应用这个模板,由于我们在logstash中使用的是[nginx-access-]YYYY-MM索引方式,因此不会匹配到默认模板,我们只需要改一下索引方式即可,如下:
vim /usr/local/logstash/etc/logstash.conf input { file { path => "/data/nginx/logs/access_java.log" type => "nginx-access" start_position => "beginning" sincedb_path => "/usr/local/logstash/sincedb" codec => "json" } } filter { if [type] == "nginx-access" { geoip { source => "clientip" target => "geoip" database => "/usr/local/logstash/etc/GeoLiteCity.dat" add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] } mutate { convert => [ "[geoip][coordinates]", "float"] } } } output { if [type] == "nginx-access" { elasticsearch { hosts => ["10.10.20.16:9200"] manage_template => true index => "logstash-nginx-access-%{+YYYY-MM}" } } }
将索引改为index => “logstash-nginx-access-%{+YYYY-MM}”即可,重启logstash,登录Kibana刷新后即可。
4.生成图片并保存
ok,每个城市的访问量就在map上显示了。
5.“Dashboard”载入Visual保存的map即可进行图形化展示了。
总结
由于我们的nginx日志格式使用的是json,因此在logstash中的filter中配置比较简单;若nginx日志不是使用的是json,在logstash中的filter中就需要配合grok进行过滤,相对麻烦一些,性能也比json格式的差。相关文章推荐
- 【CSS3】阴影 box-shadow(二)
- android lib下不同的cpu类型 不同的.so文件
- git之管理修改
- 关于有偿提供拼图响应式后台的通知
- java反射讲解实例
- 第0章 计算机概论
- js到处excel
- RAID特性
- ListView的Item中包含RadioButton的使用
- 控制反转与依赖注入
- Sybase数据库的连接,JNDI,Hibernate配置
- ERROR: invalid page header in block 27073 of relation base/21078/45300926
- Linux下的RTC子系统设备驱动
- 用gridview模仿日历并实现签到功能
- Sybase数据库的连接,JNDI,Hibernate配置
- QtDesigner修改了ui文件后,程序运行不是修改后的内容。
- Java 基础之 String、StringBuilder、StringBuffer、CharSequence 区别
- JDK中rt.jar、tools.jar和dt.jar的理解
- BaseAnimation是基于开源的APP,致力于收集各种动画效果(最新版本1.3)
- 抑制话筒自激啸叫的方法