【Elastic Stack下】Kibana+logstash+Nginx+Filebeat+Metricbeat入门学习,让你对ELK日志架构不再困惑

课程介绍

  • Nginx日志分析系统
  • Filebeat入门学习
  • Metricbeat入门学习
  • Kibana入门学习
  • Logstash入门学习
  • 综合练习

1、Nginx日志分析系统

1.1、项目需求

Nginx是一款非常优秀的web服务器,往往nginx服务会作为项目的访问入口,那么,nginx的性能保障就变得非常重 要了,如果nginx的运行出现了问题就会对项目有较大的影响,所以,我们需要对nginx的运行有监控措施,实时掌握
nginx的运行情况,那就需要收集nginx的运行指标和分析nginx的运行日志了。

1.2、业务流程

在这里插入图片描述
说明:

  • 通过Beats采集Nginx的指标数据和日志数据
  • Beats采集到数据后发送到Elasticsearch
  • Kibana读取数据进行分析
  • 用户通过Kibana进行查看分析报表

2、部署安装Nginx

tar -xvf nginx-1.11.6.tar.gz
yum -y install pcre-devel zlib-devel
./configure make install
#启动
cd /usr/local/nginx/sbin/
./nginx

#通过浏览器访问页面并且查看日志         
#访问地址:http://192.168.40.133/
tail -f /usr/local/nginx/logs/access.log

在这里插入图片描述

3、Beats 简介

在这里插入图片描述

官网:https://www.elastic.co/cn/products/beats
在这里插入图片描述
Beats系列产品:
在这里插入图片描述

4、Filebeat

在这里插入图片描述

4.1、架构

用于监控、收集服务器日志文件.

在这里插入图片描述

4.2、部署与运行

下载(或使用资料中提供的安装包,版本为:filebeat-6.5.4):https://www.elastic.co/downloads/beats

mkdir /itcast/beats
tar -xvf filebeat-6.5.4-linux-x86_64.tar.gz 
cd filebeat-6.5.4-linux-x86_64

#创建如下配置文件 itcast.yml
filebeat.inputs:
- type: stdin enabled: true
setup.template.settings: index.number_of_shards: 3
output.console: pretty: true enable: true

#启动filebeat
./filebeat -e -c itcast.yml

#输入hello运行结果如下: 
hello
{
"@timestamp": "2019-01-12T12:50:03.585Z",
"@metadata": { #元数据信息"beat": "filebeat",
"type": "doc",
"version": "6.5.4"
},
"source": "", "offset": 0,
"message": "hello",	#输入的内容"prospector": { #标准输入勘探器
"type": "stdin"
},
"input": {	#控制台标准输入"type": "stdin"
},
"beat": { #beat版本以及主机信息"name": "itcast01", "hostname": "itcast01", "version": "6.5.4"
},
"host": {
"name": "itcast01"
}
}

4.3、读取文件

#配置读取文件项 itcast-log.yml
filebeat.inputs:
- type: log enabled: true paths:
- /itcast/beats/logs/ .log setup.template.settings:
index.number_of_shards: 3 output.console:
pretty: true enable: true

#启动filebeat
./filebeat -e -c itcast-log.yml

#/haoke/beats/logs下创建a.log文件,并输入如下内容hello
world

#观察filebeat输出
{
"@timestamp": "2019-01-12T14:16:10.192Z",
"@metadata": { "beat": "filebeat",
"type": "doc",
"version": "6.5.4"
},
"host": {
"name": "itcast01"
},
"source": "/haoke/beats/logs/a.log", "offset": 0,
"message": "hello", "prospector": {
"type": "log"
},
"input": {
"type": "log"
},
"beat": {
"version": "6.5.4",
"name": "itcast01", "hostname": "itcast01"
}

"@timestamp": "2019-01-12T14:16:10.192Z",
"@metadata": { "beat": "filebeat",
"type": "doc",
"version": "6.5.4"
},
"prospector": { "type": "log"
},
"input": {
"type": "log"
},
"beat": {
"version": "6.5.4",
"name": "itcast01", "hostname": "itcast01"
},
"host": {
"name": "itcast01"
},
"source": "/haoke/beats/logs/a.log", "offset": 6,
"message": "world"
}

可以看出,已经检测到日志文件有更新,立刻就会读取到更新的内容,并且输出到控制台。

4.4、自定义字段

#配置读取文件项 itcast-log.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /itcast/beats/logs/ .log
tags: ["web"]  #添加自定义tag,便于后续的处理
fields:    #添加自定义字段
from: itcast-im
fields_under_root: true #true为添加到根节点,false为添加到子节点中
setup.template.settings:
index.number_of_shards: 3
output.console:
pretty: true
enable: true
#启动filebeat
./filebeat -e -c itcast-log.yml

  #/haoke/beats/logs下创建a.log文件,并输入如下内容  
  123

  #执行效果25 {
  "@timestamp": "2019-01-12T14:37:19.845Z",
"@metadata": {
"beat": "filebeat",
"type": "doc",
  "version": "6.5.4"
  },
"offset": 0,
"tags": [
"haoke-im" 
],
"prospector": {
"type": "log" 
},
"beat": {
"name": "itcast01",
"hostname": "itcast01",
  "version": "6.5.4"
  },
"host": {
"name": "itcast01" 
},
  "source": "/itcast/beats/logs/a.log", 
  "message": "123",
"input": {
"type": "log" 
},
      "from": "haoke-im" 
}

4.5、输出到Elasticsearch

# itcast-log.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /itcast/beats/logs/ .log
tags: ["haoke-im"]
fields:
from: haoke-im
fields_under_root: false
setup.template.settings:
index.number_of_shards: 3 #指定索引的分区数
output.elasticsearch: #指定ES的配置
hosts: ["192.168.1.7:9200","192.168.1.7:9201","192.168.1.7:9202"]

在日志文件中输入新的内容进行测试:
在这里插入图片描述
查看数据:

在这里插入图片描述

4.6、Filebeat工作原理

Filebeat由两个主要组件组成:prospectorharvester

  • harvester:

    • 负责读取单个文件的内容。
    • 如果文件在读取时被删除或重命名,Filebeat将继续读取文件。
  • prospector

    • prospector 负责管理harvester并找到所有要读取的文件来源。
    • 如果输入类型为日志,则查找器将查找路径匹配的所有文件,并为每个文件启动一个harvester。
    • Filebeat目前支持两种prospector类型:log和stdin。
  • Filebeat如何保持文件的状态

    • Filebeat 保存每个文件的状态并经常将状态刷新到磁盘上的注册文件中。
    • 该状态用于记住harvester正在读取的最后偏移量,并确保发送所有日志行。
    • 如果输出(例如Elasticsearch或Logstash)无法访问,Filebeat会跟踪最后发送的行,并在输出再次可用时继续读取文件。
    • 在Filebeat运行时,每个prospector内存中也会保存的文件状态信息,当重新启动Filebeat时,将使用注册 文件的数据来重建文件状态,Filebeat将每个harvester在从保存的最后偏移量继续读取。
    • 文件状态记录在data/registry文件中。

启动命令:

./filebeat -e -c itcast.yml
./filebeat -e -c itcast.yml -d "publish" 3
#参数说明
-e: 输出到标准输出,默认输出到syslog和logs下
-c: 指定配置文件
-d: 输出debug信息

   #测试: ./filebeat -e -c itcast-log.yml -d "publish"
  DEBUG   [publish]   pipeline/processor.go:308   Publish event: { 11     "@timestamp": "2019-01-12T15:03:50.820Z",
"@metadata": {
"beat": "filebeat",
"type": "doc",
  "version": "6.5.4"
  },
"offset": 0,
"tags": [
"haoke-im" 20 ],
"input": {
"type": "log" 23  },
"prospector": {
"type": "log" 26  },
"beat": {
"name": "itcast01",
"hostname": "itcast01",
  "version": "6.5.4"
  },
"source": "/haoke/beats/logs/a.log",
"fields": {
"from": "haoke-im" 35 },
"host": {
"name": "itcast01" 38 },
  "message": "456"
  }

4.7、读取Nginx日志文件

# itcast-nginx.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/local/nginx/logs/ .log
tags: ["nginx"]
setup.template.settings:
index.number_of_shards: 3 #指定索引的分区数
output.elasticsearch: #指定ES的配置
  hosts: ["192.168.40.133:9200","192.168.40.134:9200","192.168.40.135:9200"]
#启动
./filebeat -e -c itcast-nginx.yml

在这里插入图片描述
启动后,可以在Elasticsearch中看到索引以及查看数据:

在这里插入图片描述
在这里插入图片描述

可以看到,在message中已经获取到了nginx的日志,但是,内容并没有经过处理,只是读取到原数据,那么对于我们后期的操作是不利的,有办法解决吗?

4.7、Module

前面要想实现日志数据的读取以及处理都是自己手动配置的,其实,在Filebeat中,有大量的Module,可以简化我们的配置,直接就可以使用,如下:

./filebeat modules list 

Enabled: 

Disabled: 
apache2 
auditd 
elasticsearch 
haproxy 
icinga 
iis 
kafka
kibana 
logstash
mongodb 
mysql 
nginx 
osquery 
postgresql 
redis 
suricata 
system 
traefik

可以看到,内置了很多的module,但是都没有启用,如果需要启用需要进行enable操作

./filebeat modules enable nginx #启动 
./filebeat modules disable nginx #禁用 

Enabled: 
nginx 

Disabled: 
apache2 
auditd 
elasticsearch 
haproxy 
icinga 
iis 
kafka
kibana 
logstash
mongodb 
mysql 
osquery 
postgresql 
redis 
suricata 
system 
traefik
`

可以发现,nginx的module已经被启用。

### 4.7.1、nginx module 配置

```yml
- module: nginx 
# Access logs
access:
enabled: true
var.paths: ["/usr/local/nginx/logs/access.log "
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:
# Error logs error:
enabled: true
var.paths: ["/usr/local/nginx/logs/error.log "]

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS. #var.paths:

4.7.2、配置filebeat

#vim itcast-nginx.yml 
filebeat.inputs: 
#- type: log 
# enabled: true 
# paths: 
# - /usr/local/nginx/logs/*.log 
# tags: ["nginx"] 
setup.template.settings: 
index.number_of_shards: 3 
output.elasticsearch: 
hosts: ["192.168.40.133:9200","192.168.40.134:9200","192.168.40.135:9200"] 
filebeat.config.modules: path: ${path.config}/modules.d/*.yml 
reload.enabled: false

4.7.3、测试

./filebeat -e -c itcast-nginx.yml
#启动会出错,如下
ERROR fileset/factory.go:142	Error loading pipeline: Error loading pipeline for fileset nginx/access: This module requires the following Elasticsearch plugins: ingest-user-agent, ingest-geoip. You can install them by running the following commands on all the Elasticsearch nodes:
sudo bin/elasticsearch-plugin install ingest-user-agent
sudo bin/elasticsearch-plugin install ingest-geoip

#解决:需要在Elasticsearch中安装ingest-user-agent、ingest-geoip插件
#在资料中可以找到,ingest-user-agent.tar、ingest-geoip.tar、ingest-geoip-conf.tar 3个文件
#其中,ingest-user-agent.tar、ingest-geoip.tar解压到plugins下#ingest-geoip-conf.tar解压到config下
#问题解决。

在这里插入图片描述
测试发现,数据已经写入到了Elasticsearch中,并且拿到的数据更加明确了:
在这里插入图片描述
当然了,其他的Module的用法参加官方文档:
https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html
在这里插入图片描述


5、Metricbeat

在这里插入图片描述

  • 定期收集操作系统或应用服务的指标数据
  • 存储到Elasticsearch中,进行实时分析

5.1、Metricbeat组成

Metricbeat有2部分组成,一部分是Module,另一部分为Metricset。

  • Module

    • 收集的对象,如:mysql、redis、nginx、操作系统等;
  • Metricset

    • 收集指标的集合,如:cpu、memory、network等;

以Redis Module为例:

5.2、部署与收集系统指标

在这里插入图片描述

tar -xvf metricbeat-6.5.4-linux-x86_64.tar.gz 
cd metricbeat-6.5.4-linux-x86_64
vim metricbeat.yml

metricbeat.config.modules:
path: ${path.config}/modules.d/ .yml reload.enabled: false
setup.template.settings: index.number_of_shards: 1 index.codec: best_compression
setup.kibana: output.elasticsearch:
hosts: ["192.168.40.133:9200","192.168.40.134:9200","192.168.40.135:9200"]
processors:
-add_host_metadata: ~
-add_cloud_metadata: ~

#启动
./metricbeat -e

在ELasticsearch中可以看到,系统的一些指标数据已经写入进去了:

在这里插入图片描述

system module配置:

root@itcast01:modules.d# cat system.yml
# Module: system
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.5/metricbeat-module- system.html
-module: system period: 10s metricsets:
-cpu
-load
-memory
-network
-process
-process_summary #- core
#- diskio #- socket
process.include_top_n:
by_cpu: 5# include top 5 processes by CPU
by_memory: 5# include top 5 processes by memory
-module: system period: 1m metricsets:
-filesystem
-fsstat processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
- module:
- uptime 
#- module: system
# period: 15m 
# metricsets:
# period: 5m metricsets:
#- raid
#raid.mount_point: '/'

5.3、Module

./metricbeat modules list   #查看列表
Enabled:
system #默认启用5
Disabled:
aerospike
apache
ceph
couchbase
docker
dropwizard
elasticsearch
envoyproxy
etcd
golang
graphite
haproxy
http
jolokia
kafka
kibana
kubernetes
kvm
logstash
memcached
mongodb
munin
mysql
nginx
php_fpm
postgresql
prometheus
rabbitmq
redis
traefik
uwsgi
vsphere
windows
zookeeper

5.4、Nginx Module

5.4.1、开启nginx的状态查询

在nginx中,需要开启状态查询,才能查询到指标数据。

#重新编译nginx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module 
make
make install

./nginx -V	#查询版本信息
nginx version: nginx/1.11.6
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module

#配置nginx
vim nginx.conf
location /nginx-status 
{ stub_status on; 
access_log off;
}

测试:
在这里插入图片描述
结果说明:

  • Active connections:正在处理的活动连接数
  • server accepts handled requests
    • 第一个 server 表示Nginx启动到现在共处理了9个连接
    • 第二个 accepts 表示Nginx启动到现在共成功创建 9 次握手
    • 第三个 handled requests 表示总共处理了 21 次请求
    • 请求丢失数 = 握手数 - 连接数 ,可以看出目前为止没有丢失请求
  • Reading: 0 Writing: 1 Waiting: 1
    • Reading:Nginx 读取到客户端的 Header 信息数
    • Writing:Nginx 返回给客户端 Header 信息数
    • Waiting:Nginx 已经处理完正在等候下一次请求指令的驻留链接(开启keep-alive的情况下,这个值等于Active - (Reading+Writing))

5.4.2、配置Nginx Module

#启用redis module
./metricbeat modules enable nginx

#修改redis module配置
vim modules.d/nginx.yml

# Module: nginx
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.5/metricbeat-module- nginx.html

- module: nginx 
#metricsets: # - stubstatus 
period: 10s 
# Nginx hosts 
hosts: ["http://192.168.40.133"] 
# Path to server status. Default server-status 
server_status_path: "nginx-status" 
#username: "user" 
#password: "secret" 

#启动 
./metricbeat -e

测试:

在这里插入图片描述

可以看到,nginx的指标数据已经写入到了Elasticsearch。

更多的Module使用参见官方文档:
https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html


6、Kibana

在这里插入图片描述
Kibana 是一款开源的数据分析和可视化平台,它是Elastic Stack成员之一,设计用于和 Elasticsearch 协作。您可以使用 Kibana 对 Elasticsearch 索引中的数据进行搜索、查看、交互操作。您可以很方便的利用图表、表格及地图对数据进行多元化的分析和呈现。

官网:https://www.elastic.co/cn/products/kibana

6.1、配置安装

#解压安装包
tar -xvf kibana-6.5.4-linux-x86_64.tar.gz

#修改配置文件
vim config/kibana.yml

server.host: "192.168.40.133"	#对外暴露服务的地址
elasticsearch.url: "http://192.168.40.133:9200"	#配置Elasticsearch

#启动
./bin/kibana

#通过浏览器进行访问
http://192.168.40.133:5601/app/kibana

在这里插入图片描述
可以看到kibana页面,并且可以看到提示,导入数据到Kibana。

6.2、功能说明

在这里插入图片描述

6.3、数据探索

首先先添加索引信息:

在这里插入图片描述
即可查看索引数据:
在这里插入图片描述

6.4、Metricbeat 仪表盘

可以将Metricbeat的数据在Kibana中展示。

#修改metricbeat配置
setup.kibana:
host: "192.168.40.133:5601"
#安装仪表盘到Kibana
./metricbeat setup --dashboards

即可在Kibana中看到仪表盘数据:
在这里插入图片描述
查看系统信息:
在这里插入图片描述

6.5、Nginx 指标仪表盘

在这里插入图片描述
在这里插入图片描述

6.6、Nginx 日志仪表盘

#修改配置文件 vim itcast-nginx.yml
filebeat.inputs:
#- type: log
#enabled: true paths:
#- /usr/local/nginx/logs/ .log
#tags: ["nginx"]
setup.template.settings: index.number_of_shards: 3
output.elasticsearch:
hosts: ["192.168.40.133:9200","192.168.40.134:9200","192.168.40.135:9200"]
filebeat.config.modules:
path: ${path.config}/modules.d/ .yml reload.enabled: false
setup.kibana:
host: "192.168.40.133:5601"


#安装仪表盘到kibana
./filebeat -c itcast-nginx.yml setup

可以看到nginx的FileBeat的仪表盘了:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

6.7、自定义图表

在Kibana中,也可以进行自定义图表,如制作柱形图:
在这里插入图片描述
将图表添加到自定义Dashboard中:
在这里插入图片描述

6.8、开发者工具

在Kibana中,为开发者的测试提供了便捷的工具使用,如下:
在这里插入图片描述


7、Logstash

7.1、简介

在这里插入图片描述
用途:
在这里插入图片描述
7.2、部署安装

在这里插入图片描述

#检查jdk环境,要求jdk1.8+
java -version

#解压安装包
tar -xvf logstash-6.5.4.tar.gz

#第一个logstash示例
bin/logstash -e 'input { stdin { } } output { stdout {} }'

执行效果如下:
在这里插入图片描述

7.3、配置详解

Logstash的配置有三部分,如下:

input { #输入
    stdin { ... } #标准输入
}

filter { #过滤,对数据进行分割、截取等处理
...
}

output { #输出
stdout { ... } #标准输出
}

7.3.1、输入

  • 采集各种样式、大小和来源的数据,数据往往以各种各样的形式,或分散或集中地存在于很多系统中。
  • Logstash支持各种输入选择 ,可以在同一时间从众多常用来源捕捉事件。能够以连续的流式传输方式,轻松地从您的日志、指标、Web 应用、数据存储以及各种 AWS 服务采集数据。
    -在这里插入图片描述

7.3.2、过滤

  • 实时解析和转换数据
  • 数据从源传输到存储库的过程中,Logstash过滤器能够解析各个事件,识别已命名的字段以构建结构,并将它们转换成通用格式,以便更轻松、更快速地分析和实现商业价值。
    在这里插入图片描述

7.3.3、输出

Logstash 提供众多输出选择,您可以将数据发送到您要指定的地方,并且能够灵活地解锁众多下游用例。
在这里插入图片描述

7.4、读取自定义日志

前面我们通过Filebeat读取了nginx的日志,如果是自定义结构的日志,就需要读取处理后才能使用,所以,这个时候就需要使用Logstash了,因为Logstash有着强大的处理能力,可以应对各种各样的场景。

7.4.1、日志结构

2019-03-15 21:21:21|ERROR|读取数据出错|参数:id=1002

可以看到,日志中的内容是使用“|”进行分割的,使用,我们在处理的时候,也需要对数据做分割处理。

7.4.2、编写配置文件

#vim itcast-pipeline.conf
input {
	file {
		path => "/itcast/logstash/logs/app.log" 
		start_position => "beginning"
	}
}

filter {
	mutate {
		split => {"message"=>"|"}
	}
}

output {
	stdout { codec => rubydebug }
}

7.4.3、启动测试

#启动
./bin/logstash -f ./itcast-pipeline.conf
#写日志到文件
echo "2019-03-15 21:21:21|ERROR|读取数据出错|参数:id=1002" >> app.log

#输出的结果
{
	"@timestamp" => 2019-03-15T08:44:04.749Z,
		"path" => "/itcast/logstash/logs/app.log", 
	"@version" => "1",
		"host" => "node01", 
		"message" => [
		[0] "2019-03-15 21:21:21",
		[1]"ERROR",
		[2]"读取数据出错", 
		[3] "参数:id=1002"
	]
}

可以看到,数据已经被分割了。

7.4.5、输出到Elasticsearch


input {
file {
path => "/itcast/logstash/logs/app.log"
#type => "system"
start_position => "beginning"
}
}
filter {
mutate {
split => {"message"=>"|"}
}
}

output {
elasticsearch {
hosts => [ "192.168.40.133:9200","192.168.40.134:9200","192.168.40.135:9200"]
}
}


#启动
./bin/logstash -f ./itcast-pipeline.conf

#写入数据
echo "2019-03-15 21:21:21|ERROR|读取数据出错|参数:id=1003" >> app.log

测试:
在这里插入图片描述
在这里插入图片描述


8、综合练习

下面我们将前面所学习到的Elasticsearch + Logstash + Beats + Kibana整合起来做一个综合性的练习,目的就是让学生们能够更加深刻的理解Elastic Stack的使用。

8.1、流程说明

在这里插入图片描述

  • 应用APP生产日志,用来记录用户的操作
    • [INFO] 2019-03-15 22:55:20 [cn.itcast.dashboard.Main] - DAU|5206|使用优惠券|2019-03-15 03:37:20
    • [INFO] 2019-03-15 22:55:21 [cn.itcast.dashboard.Main] - DAU|3880|浏览页面|2019-03-15 07:25:09
  • 通过Filebeat读取日志文件中的内容,并且将内容发送给Logstash,原因是需要对内容做处理
  • Logstash接收到内容后,进行处理,如分割操作,然后将内容发送到ElasticsearchKibana会读取Elasticsearch中的数据,并且在Kibana中进行设计Dashboard,最后进行展示

说明:日志格式、图表、Dashboard都是自定义的。

8.2、APP介绍

APP在生产环境应该是真实的系统,然而,我们现在仅仅的学习,为了简化操作,所以就做数据的模拟生成即可。业务代码如下:

import org.apache.commons.lang3.RandomUtils; import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication public class Main {

    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

    public static final String[] VISIT = new String[]{"浏览页面", "评论商品", "加入收藏", "加入购物车", "提交订单", "使用优惠券", "领取优惠券", "搜索", "查看订单"};
    public static void main(String[] args) throws Exception {
        while(true){
            Long sleep = RandomUtils.nextLong(200, 1000 Thread.sleep(sleep);
            Long maxUserId = 9999L;
            Long userId = RandomUtils.nextLong(1, maxUserId);
            String visit = VISIT[RandomUtils.nextInt(0, VISIT.length)]; DateTime now = new DateTime();
            int maxHour = now.getHourOfDay();
            int maxMillis = now.getMinuteOfHour(); int maxSeconds = now.getSecondOfMinute();
            String date = now.plusHours(-(RandomUtils.nextInt(0, maxHour)))
                    .plusMinutes(-(RandomUtils.nextInt(0, maxMillis)))
                    .plusSeconds(-(RandomUtils.nextInt(0, maxSeconds)))
                    .toString("yyyy-MM-dd HH:mm:ss");

            String result = "DAU|" + userId + "|" + visit + "|" + date; LOGGER.info(result);
        }
    }
}

运行结果:
在这里插入图片描述
** 部署:**

#打包成jar包,在linux上运行
java -jar itcast-dashboard-generate-1.0-SNAPSHOT.jar
#运行之后,就可以将日志写入到/itcast/logs/app.log文件中

8.3、Filebeat

#vim itcast-dashboard.yml
filebeat.inputs:
- type: log enabled: true paths:
- /itcast/logs/ .log setup.template.settings:
index.number_of_shards: 3 output.logstash:
hosts: ["192.168.40.133:5044"]


#启动
./filebeat -e -c itcast-dashboard.yml

8.4、Logstash

#vim itcast-dashboard.conf 
   input {
   beats {
   port => "5044"
   }
   }

   filter {
mutate {
split => {"message"=>"|"}   }


mutate {
add_field => {
"userId" => "%{message[1]}"
"visit" => "%{message[2]}"
  "date" => "%{message[3]}"
  }
  }
mutate {
convert => {
"userId" => "integer"
"visit" => "string"
"date" => "string"  }
  }
  }

#output {
# stdout { codec => rubydebug }     #}

output {
elasticsearch {
  hosts => [ "192.168.40.133:9200","192.168.40.134:9200","192.168.40.135:9200"]
  }
  }

#启动
./bin/logstash -f itcast-dashboard.conf

8.5、Kibana

启动Kibana

#启动
./bin/kibana

#通过浏览器进行访问
http://192.168.40.133:5601/app/kibana

添加Logstash索引到Kibana中:

在这里插入图片描述

8.5.1、时间间隔的柱形图

在这里插入图片描述
说明:x轴是时间,以天为单位,y轴是count数

保存:(my-dashboard-时间间隔的柱形图)

在这里插入图片描述

8.5.2、各个操作的饼图分布
在这里插入图片描述
统计各个操作的数量,形成饼图。

保存:(my-dashboard-各个操作的饼图)
在这里插入图片描述

8.5.3、数据表格

在这里插入图片描述
在数据探索中进行保存,并且保存,将各个操作的数据以表格的形式展现出来。

保存:(my-dashboard-表格)

在这里插入图片描述

8.5.4、制作Dashboard

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值