Timelion
Elastic Stack Serverless
要使用 Timelion,您需要通过将函数链接在一起来定义图表,并使用 Timelion 特定的语法。该语法支持经典点序列图表不提供的一些功能,例如将来自不同索引或数据源的数据拉入同一图表。
Timelion 由一个简单的表达式语言驱动,您可以使用它来
- 从一个或多个索引中检索时间序列数据
- 跨两个或多个时间序列执行数学运算
- 可视化结果
Timelion 函数始终以点开头,后跟函数名称,然后是包含该函数所有参数的括号。
.es
(或者如果您喜欢输入长单词,则为 .elasticsearch
)函数从 Elasticsearch 收集数据并随时间绘制数据。 默认情况下,.es 函数只会计算文档数量,从而生成一个图表,显示随时间推移的文档数量。
函数可以有多个参数,.es
函数也是如此。 每个参数都有一个名称,您可以在括号内使用该名称来设置其值。 参数也有顺序,自动完成或文档(使用顶部菜单中的文档按钮显示)会显示该顺序。
如果您没有指定参数名称,timelion 会按照文档中列出的顺序将值分配给参数。
.es 函数的第一个参数是参数 q(表示查询),它是一个查询字符串,用于过滤此序列的数据。 您还可以通过其名称显式引用此参数,并且我始终建议在向函数传递多个参数时立即执行此操作。 因此,以下两个表达式是等效的
多个参数用逗号分隔。.es 函数还有另一个参数,名为 index,可用于为此序列指定数据视图,因此查询不会针对所有索引(或您更改的任何设置)执行。
如果您的参数值包含空格或逗号,则必须将该值放在单引号或双引号中。 否则,您可以省略这些引号。
Kibana 支持多个 y 轴刻度和数据系列范围。
.yaxis()
函数支持以下参数
- yaxis — 用于绘制序列的编号 y 轴。 例如,使用
.yaxis(2)
显示第二个 y 轴。 - min — y 轴范围的最小值。
- max — y 轴范围的最大值。
- position — 单位的位置。 值包括
left
或right
。 - label — 轴的标签。
- color — 轴标签的颜色。
- units — 用于格式化 y 轴标签的函数。 值包括
bits
、bits/s
、bytes
、bytes/s
、currency(:ISO 4217 currency code)
、percent
和custom(:prefix:suffix)
。 - tickDecimals — 刻度小数精度。
示例
.es(index= kibana_sample_data_logs,
timefield='@timestamp',
metric='avg:bytes')
.label('Average Bytes for request')
.title('Memory consumption over time in bytes').yaxis(1,units=bytes,position=left),
.es(index= kibana_sample_data_logs,
timefield='@timestamp',
metric=avg:machine.ram)
.label('Average Machine RAM amount').yaxis(2,units=bytes,position=right)
.yaxis(1,units=bytes,position=left)
— 为第一个数据系列指定第一个 y 轴,并更改左侧的单位。.yaxis(2,units=bytes,position=left)
— 为第二个数据系列指定第二个 y 轴,并更改右侧的单位。
您使用 Metricbeat 从您的操作系统收集了数据,并且您想要在仪表盘上可视化和分析数据。 要创建数据面板,请使用 Timelion 创建时间序列可视化,
设置 Metricbeat,然后创建仪表盘。
- 要设置 Metricbeat,请转到 Metricbeat 快速入门:安装和配置
- 转到 仪表盘 。
- 在 仪表盘 页面上,单击 创建仪表盘 。
打开 Timelion 并更改时间范围。
- 在仪表盘上,单击 所有类型 > 基于聚合 ,然后选择 Timelion。
- 确保 时间过滤器 是 过去 7 天 。
要将用户空间中花费的 CPU 时间的实时百分比与偏移一小时的结果进行比较,请创建一个时间序列可视化。
要跟踪 CPU 的实时百分比,请在 Timelion 表达式 字段中输入以下内容,然后单击 更新
.es(index=metricbeat-*,
timefield='@timestamp',
metric='avg:system.cpu.user.pct')
要比较两个数据集,请添加另一个序列,并将数据向后偏移一个小时,然后单击 更新
.es(index=metricbeat-*,
timefield='@timestamp',
metric='avg:system.cpu.user.pct'),
.es(offset=-1h,
index=metricbeat-*,
timefield='@timestamp',
metric='avg:system.cpu.user.pct')
为了易于区分两个数据集,请添加标签名称,然后单击 更新
.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')
为了让不熟悉的用户更容易理解可视化的目的,请添加标题,然后单击 更新
.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')
要区分当前小时和上一小时,请更改图表线条的外观,然后单击 更新
.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 支持标准颜色名称、十六进制值或分组数据的颜色模式。
要突出显示第一个数据序列,请更改线条颜色,然后单击 更新
.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)
将图例移动到西北位置,并包含两列,然后单击 更新
.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 表达式 字段中输入以下内容,然后单击 更新
.es(index=metricbeat*,
timefield=@timestamp,
metric=max:system.network.in.bytes)
为了便于监控入站流量,绘制值随时间的变化,然后单击 更新
.es(index=metricbeat*,
timefield=@timestamp,
metric=max:system.network.in.bytes)
.derivative()
为出站流量添加类似的计算,然后单击 更新
.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)
.multiply(-1)
将出站网络流量转换为负值,因为出站网络流量正在离开您的机器。.multiply()
将数据序列乘以一个数字、数据序列的结果或数据序列列表。
为了使数据更易于分析,请将数据指标从 bytes
更改为 megabytes
,然后单击 更新
.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)
.divide()
接受与.multiply()
相同的输入,然后将数据序列除以定义的除数。
使用以下函数自定义和格式化可视化,然后单击 更新
.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 条件逻辑,您可以使用以下运算符值来比较您的数据
eq
- equal
ne
- not equal
lt
- less than
lte
- less than or equal to
gt
- greater than
gte
- greater than or equal to
要绘制 system.memory.actual.used.bytes
的最大值,请在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'),
.es(index=metricbeat-*,
timefield='@timestamp',
metric='max:system.memory.actual.used.bytes')
.if(gt,
11300000000,
.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,
11375000000,
.es(index=metricbeat-*,
timefield='@timestamp',
metric='max:system.memory.actual.used.bytes'),
null)
.label('severe')
.color('red')
if()
将每个点与一个数字进行比较。当条件为true
时,调整样式。当条件为false
时,使用默认样式。- Timelion 用于大于运算符的条件逻辑。在此示例中,警告阈值为 11.3GB (
11300000000
),严重阈值为 11.375GB (11375000000
)。如果阈值对于您的机器而言过高或过低,请调整这些值。
要确定趋势,请创建新的数据序列,然后单击更新。
.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,11300000000,
.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,11375000000,
.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)
mvavg()
计算指定时间段内的移动平均值。在此示例中,.mvavg(10)
创建一个窗口大小为 10 个数据点的移动平均值。
使用以下函数自定义和格式化可视化,然后单击 更新
.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,
11300000000,
.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,
11375000000,
.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 条件的更多信息,请参阅 I have but one .condition()。