Kibana 用户指南(Timelion入门)

Timelion入门

Timelion使你能够轻松得到如下问题的答案:html

  • 随着时间的推移,每一个惟一的用户会查看多少个页面?
  • 这个星期五和上周五之间的交通量有什么不一样?
  • 今天有多少日本人口来到个人网站?
  • 标准普尔500指数的10日均线是多少?
  • 过去两年收到的全部搜索请求的累计总和是多少?

建立时间序列可视化

本教程将使用Metricbeat的时间序列数据带你浏览Timelion提供的一些函数,首先下载Metricbeat,按照这里的说明在本地获取数据。express

你将建立的第一个可视化将比较在用户空间中花费的CPU时间与一小时的结果偏移量的实时百分比,为了建立这个可视化,咱们须要建立两个Timelion表达式,一个是system.cpu.user.pct的实时平均数,另外一个是1小时的平均偏移量。segmentfault

首先,你须要在第一个表达式中定义indextimefieldmetric,并在Timelion查询栏中输入如下表达式。网络

.es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct')

timelion-create01.png

如今你须要添加另外一个具备前一小时数据的系列,以便进行比较,为此,你必须向.es()函数添加一个offset参数,offset将用日期表达式偏移序列检索。对于本例,你但愿将数据偏移一小时,并使用日期表达式-1h,使用逗号分隔这两个系列,在Timelion查询栏中输入如下表达式:ide

.es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct'), .es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct')

timelion-create02.png

很难区分这两个系列,自定义标签以便于区分它们,你老是能够将.label()函数附加到任何表达式以添加自定义标签,在Timelion查询栏中输入如下表达式来定制标签:函数

.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour'), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour')

timelion-create03.png

保存完整的Timelion工做表做为Metricbeat示例,做为一种最佳实践,你应该在完成本教程的过程当中保存对本工做表所作的任何重要更改。学习

定制和格式化可视化

Timelion有不少定制选项,你几乎可使用可用的函数对图表的每一个方面进行个性化设置,对于本教程,你将执行如下修改。网站

  • 添加一个标题
  • 更改系列类型
  • 改变一个系列的颜色和不透明度
  • 修改图例

在上一节中,你用两个系列建立了一个时间轴图表,让咱们继续定制这个可视化。ui

在进行任何其余修改以前,将title()函数附加到表达式的末尾,以添加具备有意义名称的标题,这将使不熟悉的用户更容易理解可视化目的。对于这个示例,将title('CPU usage over time')添加到原始系列中,在Timelion 查询栏中使用如下表达式:spa

.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour'), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour').title('CPU usage over time')

timelion-customize01.png

为了进一步区分过去一小时系列,你将把图表类型更改成区域图表,为了作到这一点,你须要使用.lines()函数来定制折线图,你将设置fillwidth参数,分别设置折线图的填充和折线宽度。在本例中,你将经过添加.lines(fill=1,width=0.5)将填充级别设置为1,边框宽度设置为0.5,在Timelion查询栏中使用如下表达式:

.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour').lines(fill=1,width=0.5), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour').title('CPU usage over time')

timelion-customize02.png

让咱们给这些系列涂上颜色,使当前的小时系列比过去一个小时系列流行一点,color()函数可用于更改任何系列的颜色,并接受标准颜色名称、十六进制值或分组系列的颜色模式。对于这个示例,你将在过去一个小时使用.color(gray),而在当前小时使用.color(#1E90FF),在Timelion查询栏中输入如下表达式进行调整:

.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour').lines(fill=1,width=0.5).color(gray), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour').title('CPU usage over time').color(#1E90FF)

timelion-customize03.png

最后但并不是最不重要,调整图例,使其占用尽量小的空间,你可使用.legend()函数来设置图例的位置和样式。在本例中,经过将.legend(columns=2, position=nw)两列追加到原始系列,将图例放置在可视化的西北位置,使用如下表达式进行调整:

.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour').lines(fill=1,width=0.5).color(gray), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour').title('CPU usage over time').color(#1E90FF).legend(columns=2, position=nw)

timelion-customize04.png

保存你的更改并继续到下一节学习数学函数。

使用数学函数

在前两部分中,你已经学习了如何建立和样式化Timelion可视化,本节将探索Timelion提供的数学函数。你将继续使用Metricbeat数据为入站和出站网络流量建立新的Timelion可视化,首先,你须要在工做表中添加一个新的Timelion可视化。

在顶部菜单中,单击Add添加第二个可视化,当添加到工做表中时,你会注意到查询栏已经被替换为默认的.es(*)表达式,这是由于查询与你选择的Timelion工做表上的可视化相关联。

timelion-math01.png

要开始跟踪入站/出站网络流量,你的第一个表达式将计算system.network.in.bytes的最大值,将下面的表达式输入到你的Timelion查询栏:

.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes)

timelion-math02.png

在绘制变化率时,监视网络流量更有价值,derivative()函数就是这样作的 - 绘制值随时间的变化,经过在表达式末尾添加.derivative()能够很容易地作到这一点,使用如下表达式来更新你的可视化:

.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes).derivative()

timelion-math03.png

如今是出站流量,你须要为system.network.out.bytes添加相似的计算,因为出站流量将离开你的机器,所以将此指标表示为负数是有意义的,.multiply()函数将系列乘以一个数字,这个数字是系列或系列列表的结果。对于本例,你将使用.multiply(-1)将出站网络流量转换为负值,使用如下表达式来更新你的可视化:

.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes).derivative(), .es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.out.bytes).derivative().multiply(-1)

timelion-math04.png

为了使这个可视化更容易使用,将这个系列从字节转换为兆字节,Timelion有一个.divide()函数可使用,.divide()接受与.multiply()相同的输入,并将这个系列除以所定义的除数,使用如下表达式来更新你的可视化:

.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes).derivative().divide(1048576), .es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.out.bytes).derivative().multiply(-1).divide(1048576)

timelion-math05.png

使用上一节中学习的格式化函数.title().label().color().lines().legend(),让咱们稍微整理一下这个可视化,使用如下表达式来更新你的可视化:

.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes).derivative().divide(1048576).lines(fill=2, width=1).color(green).label("Inbound traffic").title("Network traffic (MB/s)"), .es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.out.bytes).derivative().multiply(-1).divide(1048576).lines(fill=2, width=1).color(blue).label("Outbound traffic").legend(columns=2, position=nw)

timelion-math06.png

保存你的更改并继续到下一节学习条件逻辑和跟踪趋势。

使用条件逻辑和跟踪趋势

在本节中,你将学习如何使用条件逻辑修改时间序列数据,并使用移动平均值建立趋势,这有助于随着时间的推移很容易地发现异常值和模式。

对于本教程,你将继续使用Metricbeat数据添加另外一个监控内存消耗的可视化,首先,使用如下表达式绘制system.memory.actual.used.bytes的最大值。

.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes')

timelion-conditional01.png

让咱们建立两个阈值来监视使用的内存数量,在本教程中,警告阈值为12.5GB,严重阈值为15GB,当使用内存的最大数量超过这些阈值中的任何一个时,将相应地对该系列进行着色。

若是你的计算机的阈值太高或太低,请相应地进行调整。

要配置这两个阈值,可使用Timelion的条件逻辑,在本教程中,你将使用if()将每一个点与一个数字进行比较,若是条件的值为true,则调整样式,若是条件的值为false,则使用默认样式,Timelion提供了如下六个操做符值进行比较。

eq 相等
ne 不相等
lt 小于
lte 小于或等于
gt 大于
gte 大于或等于

因为有两个阈值,所以对它们进行不一样的样式是有意义的,使用gt操做符将警告阈值用.color('#FFCC11')涂成黄色,将严重阈值用.color('red')涂成红色,在Timelion查询栏中输入如下表达式,以应用条件逻辑和阈值样式:

.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').if(gt,12500000000,.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'),null).label('warning').color('#FFCC11'), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').if(gt,15000000000,.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'),null).label('severe').color('red')

timelion-conditional02.png

有关Timelions条件功能的更多信息,请参阅I have but one .condition()的博客文章。

如今你已经定义了阈值来轻松地识别异常值,让咱们建立一个新的系列来肯定真正的趋势是什么,Timelion的mvavg()函数容许计算给定窗口上的移动平均值,这对嘈杂的时间序列特别有用,对于本教程,你将使用.mvavg(10)来建立具备10个数据点窗口的移动平均线,使用如下表达式建立最大内存使用量的移动平均值:

.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').if(gt,12500000000,.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'),null).label('warning').color('#FFCC11'), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').if(gt,15000000000,.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'),null).label('severe').color('red'), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').mvavg(10)

timelion-conditional03.png

如今你已经有了阈值和移动平均值,让咱们格式化可视化,以便更容易使用,和最后一部分同样,使用.color().line().title().legend()函数相应地更新可视化:

.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').label('max memory').title('Memory consumption over time'), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').if(gt,12500000000,.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'),null).label('warning').color('#FFCC11').lines(width=5), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').if(gt,15000000000,.es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes'),null).label('severe').color('red').lines(width=5), .es(index=metricbeat-*, timefield='@timestamp', metric='max:system.memory.actual.used.bytes').mvavg(10).label('mvavg').lines(width=2).color(#5E5E5E).legend(columns=4, position=nw)

timelion-conditional04.png

保存你的Timelion工做表并继续到下一节,将这些新的可视化添加到你的仪表盘。

添加到仪表盘

你已经正式利用了Timelion的功能来建立时间序列可视化,本教程的最后一步是向仪表盘添加你新的可视化,下面,本节将向你展现如何从Timelion工做表中保存可视化,并将其添加到现有的仪表盘中。

要将Timelion可视化保存为仪表盘面板,请执行如下步骤。

  1. 选择要添加到一个(或多个)仪表盘上的可视化视图。
  2. 点击顶部菜单中的Save选项。
  3. 选择Save current expression as Kibana dashboard panel
  4. 命名你的面板并点击Save以做为仪表盘可视化。

timelion-save01.png

如今你能够将这个仪表盘面板添加到任何你想要的仪表盘上,这个可视化如今将在可视化列表中列出,继续并按照你建立的其余可视化效果的相同过程进行操做。

建立一个新的仪表盘或打开一个现有的仪表盘,以添加Timelion可视化,就像其余任何可视化同样。

timelion-save02.png

你还能够从Visualize应用程序中建立时间序列可视化 - 只需选择Timeseries可视化类型,并在expression字段中输入一个Timelion表达式。

内联帮助和文档

不能记住一个函数或搜索一个新的函数?莫老是能够在Timelion中引用内联帮助和文档。

Timelion表达式语言的文档是内置的,单击顶部菜单中的Docs能够查看可用的函数并访问内联引用,当你开始在查询栏中输入函数时,Timelion会实时显示相关参数。

timelion-arg-help.jpg


上一篇:Dashboard

相关文章
相关标签/搜索