Metricbeat 参考指南(步骤3:在Elasticsearch中加载索引模板)

news/2024/7/7 7:06:35

步骤3:在Elasticsearch中加载索引模板

在Elasticsearch中,索引模板用于定义设置和映射,以确定如何分析字段。

Metricbeat推荐的索引模板文件是由Metricbeat包安装的,如果你接受metricbeat.yml配置文件中的默认配置,那么Metricbeat在成功连接到Elasticsearch之后会自动加载模板。如果模板已经存在,则不会覆盖它,除非你配置Metricbeat这样做。

通过在Metricbeat配置文件中配置模板加载选项,你可以禁用自动模板加载,或者加载你自己的模板。

你还可以设置选项来更改索引和索引模板的名称。

加载索引模板需要连接到Elasticsearch,如果输出不是Elasticsearch,则必须手动加载模板。

配置模板加载

如果激活了Elasticsearch输出,默认情况下,Metricbeat会自动加载推荐的模板文件fields.yml,你可以将metricbeat.yml配置文件中的默认值更改为:

  • 加载不同的模板
setup.template.name: "your_template_name"
setup.template.fields: "path/to/fields.yml"

如果模板已经存在,则不会覆盖它,除非你配置Metricbeat这样做。

  • 覆盖现有模板
setup.template.overwrite: true
  • 禁用自动模板加载
setup.template.enabled: false

如果禁用自动模板加载,则需要手动加载模板。

  • 更改索引名称

默认情况下,Metricbeat将事件写入名为metricbeat-6.4.2-yyyy.MM.dd的索引,yyyy.MM.dd是事件被索引的日期,要使用不同的名称,可以在Elasticsearch输出中设置index选项。你指定的值应该包括索引的根名称加上版本和日期信息,你还需要配置setup.template.namesetup.template.pattern选项以匹配新名称,例如:

output.elasticsearch.index: "customname-%{[beat.version]}-%{+yyyy.MM.dd}"
setup.template.name: "customname"
setup.template.pattern: "customname-*"
setup.dashboards.index: "customname-*"

setup.dashboards.index => 如果你计划设置Kibana仪表盘,还可以设置此选项以覆盖仪表盘和索引模式中定义的索引名称。

有关配置选项的完整列表,请参阅加载Elasticsearch索引模板。

手动加载模板

要手动加载模板,运行setup命令,需要连接到Elasticsearch,如果启用了另一个输出,你需要使用-E选项暂时禁用该输出并启用Elasticsearch。这里的示例假设启用了Logstash输出,如果已经启用了Elasticsearch输出,可以省略-E标志。

如果你连接到一个安全的Elasticsearch集群,请确保你已经按照步骤2:配置Metricbeat所述配置了凭证。

如果运行Metricbeat的主机没有直接连接到Elasticsearch,请参见手动加载模板(备用方法)。

要加载模板,请为系统使用适当的命令。

deb和rpm:

metricbeat setup --template -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]

mac:

./metricbeat setup --template -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'

docker:

docker run docker.elastic.co/beats/metricbeat:6.4.2 setup --template -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'

win:

作为管理员打开PowerShell提示符(右键单击PowerShell图标并选择Run as Administrator)。

从PowerShell提示符,切换到你安装Metricbeat的目录,然后运行:

PS > .\metricbeat.exe setup --template -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'

强迫Kibana查看最新的文档

如果你已经使用Metricbeat将数据索引到Elasticsearch,那么索引可能包含旧文档,加载索引模板后,可以从metricbeat-*删除旧文档,以强制Kibana查看最新的文档,使用此命令:

deb、rpm和mac:

curl -XDELETE 'http://localhost:9200/metricbeat-*'

win:

PS > Invoke-RestMethod -Method Delete "http://localhost:9200/metricbeat-*"

这个命令删除所有匹配metricbeat-*模式的索引,在运行此命令之前,请确保要删除与模式匹配的所有索引。

手动加载模板(备用方法)

如果运行Metricbeat的主机没有直接连接到Elasticsearch,你可以将索引模板导出到文件,将其移动到有连接的机器上,然后手动安装模板。

  1. 导出索引模板:
    deb和rpm:

    metricbeat export template > metricbeat.template.json

    mac:

    ./metricbeat export template > metricbeat.template.json

    win:

    PS > .\metricbeat.exe export template --es.version 6.4.2 | Out-File -Encoding UTF8 metricbeat.template.json
  2. 安装模版:
    deb、rpm和mac:

    curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/metricbeat-6.4.2 -d@metricbeat.template.json

    win:

    PS > Invoke-RestMethod -Method Put -ContentType "application/json" -InFile metricbeat.template.json -Uri http://localhost:9200/_template/metricbeat-6.4.2

http://www.niftyadmin.cn/n/4472223.html

相关文章

android手机屏幕适配补充

如何将一个应用程序适配在不同的手机上&#xff0c;虽然这不算是一个技术问题&#xff0c;但是对于刚刚做屏幕的开发人员来说&#xff0c;还真不是一件多么简单的事情。 首先&#xff1a;你需要在AndroidManifest.xml文件的<manifest>元素如下添加子元素 <supports-sc…

url加密 比较

1.escape 简单来说&#xff0c;escape是对字符串(string)进行编码(而另外两种是对URL)&#xff0c;作用是让它们在所有电脑上可读。 编码之后的效果是%XX或者%uXXXX这种形式。 其中 ASCII字母、数字、*/ &#xff0c;这几个字符不会被编码&#xff0c;其余的都会。 最关键的是&…

ERROR tool.ImportTool: Import failed: java.io.IOException: Generating splits for a textual index col

sqoop任务报错&#xff1a; 异常内容&#xff1a; ERROR tool.ImportTool: Import failed: java.io.IOException: Generating splits for a textual index column allowed only in case of “-Dorg.apache.sqoop.splitter.allow_text_splittertrue” property passed as a par…

Android GridView 横向滚动 一行显示

都知道gridview和listview是android比较重要的数据组件&#xff0c; 接到一个横向显示数据的任务&#xff0c;头大半天&#xff0c;最后只能用gridview试试了。呵呵&#xff0c;费了N多脑细胞&#xff0c;搞定。 布局文件main.xml [java] view plaincopy <?xml version&…

JAVA 获取两个日期间的所有日期

2019独角兽企业重金招聘Python工程师标准>>> public static List<String> getDates(Date startDate, Date endDate){ SimpleDateFormat sdf new SimpleDateFormat("yyyyMMdd"); List<String> dates new ArrayLis…

navicat报错SSH:Unable to load key

navicat的版本比较老了。在加载ssh的pub key时报这个错。这个private key确实可以用来登录服务器。而且navicat也能够加载以前的private key&#xff0c;那么问题只有一个&#xff1a;文件有问题 我的解决办法是安装新版的navicat&#xff0c;问题已解决&#xff01;

Error: Error while compiling statement: FAILED: SemanticException Schema of both sides of union shou

sqoop任务导数据到hive报错&#xff1a; Error: Error while compiling statement: FAILED: SemanticException Schema of both sides of union should match. (state42000,code40000) 原因是hive中做union时&#xff0c;查询到的两个表的有差异&#xff0c;列名不一致。删除…

用GridView实现Gallery的效果

本帖最后由 likeyou 于 2011-11-7 21:01 编辑 在实现横向的类似Gallery的效果中做了实现Gallery的尝试&#xff0c;但是效果不好。使用的是TableLayout&#xff0c;出现了横向拖动图片的时候&#xff0c;因为有倾斜&#xff08;轻微的竖向拖动&#xff09;&#xff0c;会整个…