Beats:如何启动 Metricbeat 中的 MySQL 模块 - query Metricset

article/2025/10/7 23:42:08

在我做之前的教程 “Observability:Elastic Metrics 应用介绍”,我发现当我尝试启动 MySQL 模块中的 query metricset 会出现错误。之后我发现官方文档也缺少相应的资料。在今天的文章中,我将介绍如上启动这个 metricset。在使用这个 metricset 时需要做相应的配置。在开始之前,如果你对 Beats 模块的启动还不是很清楚的话,请参阅我之前的文章:

  • Beats:Beats 入门教程 (一)
  • Beats:Beats 入门教程 (二)

简单地说,我们需要使用如下的步骤来进行启动 MySQL 模块:

./metricbeat modules enable mysql

我们可以使用如下的命令来检查这个模块是否被启动:

./metricbeat modules modules list

在本次测试中,为了方便,我们只启动 MySQL 模块。我们可以尝试使用如下的命令来检查我们的 MySQL 模块是否配置成功:

 ./metricbeat test modules mysql

上面显示我们的模块配置是不成功的。我们需要配置 modules.d/mysql.yml

modules.d/mysql.yml

# Module: mysql
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.x/metricbeat-module-mysql.html- module: mysqlmetricsets:- status#  - galera_status#  - performance#  - queryperiod: 10s# Host DSN should be defined as "user:pass@tcp(127.0.0.1:3306)/"# or "unix(/var/lib/mysql/mysql.sock)/",# or another DSN format supported by <https://github.com/Go-SQL-Driver/MySQL/>.# The username and password can either be set in the DSN or using the username# and password config options. Those specified in the DSN take precedence.hosts: ["root:1234@tcp(127.0.0.1:3306)/"]# Username of hosts. Empty by default.#username: root# Password of hosts. Empty by default.#password: secret

请注意上面的 1234 是我的 mysql root 用户的密码。我们重新进行测试:

$ ./metricbeat test modules  mysql | grep OKstatus...OK

上面表示我们的测试是成功的。我们接下来启动 query metricset:

modules.d/mysql.yml

如果我们重新测试的话,我们就会发现有这样的错误:

./metricbeat test modules  mysql 

从上面的输出中,我们可以看出来,有一个错误信息。我们需要做更多的配置:

modules.d/mysql.yml

# Module: mysql
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.x/metricbeat-module-mysql.html- module: mysqlmetricsets:#  - status#  - galera_status#  - performance- queryperiod: 10snamespace: "my_namespace"# Host DSN should be defined as "user:pass@tcp(127.0.0.1:3306)/"# or "unix(/var/lib/mysql/mysql.sock)/",# or another DSN format supported by <https://github.com/Go-SQL-Driver/MySQL/>.# The username and password can either be set in the DSN or using the username# and password config options. Those specified in the DSN take precedence.hosts: ["root:1234@tcp(127.0.0.1:3306)/"]queries:- query: "SELECT * FROM data.sensors"response_format: "table"query_namespace: "my_first_query_namespace"- query: "SELECT * FROM data.SalesJan2009"response_format: "table"query_namespace: "my_second_query_namespace"# Username of hosts. Empty by default.#username: root# Password of hosts. Empty by default.#password: secret

在上面 data 是我们在 MySQL 中的数据库。sensors 以及 SalesJan2009 是 data 数据库中的表格:

经过上面的配置后,我们重新来进行测试:

$ ./metricbeat test modules  mysql 
mysql...query...OKresult: {"@timestamp": "2021-03-29T05:24:57.477Z","event": {"dataset": "mysql.query","duration": 8743859,"module": "mysql"},"metricset": {"name": "query","period": 10000},"mysql": {"my_namespace": {"my_first_query_namespace": {"buildingname": "222 Broadway","customer": "Elastic","department": "Engineering","floor": "Floor 1","id": 1,"latitude": 41,"locationonfloor": "Desk 102","longitude": -74,"room": 101,"sensortype": "Temperature"}}},"service": {"address": "tcp(127.0.0.1:3306)/?readTimeout=10s\u0026timeout=10s\u0026writeTimeout=10s","type": "mysql"}}

从上面的输出中,我们可以看出来我们的测试是成功的。

接下来我们使用如下的配置 Metricbeat:

./metricbeat setup
$ ./metricbeat setup
Overwriting ILM policy is disabled. Set `setup.ilm.overwrite: true` for enabling.Index setup finished.
Loading dashboards (Kibana must be running and reachable)
Loaded dashboards

我们使用如下的命令来启动 Metricbeat:

./metricbeat -e

我们在 Discover 中可以看到如下的数据:

从上面我们可以看出来。event.dataset 来自 mysql.query 还是有蛮多的数据的。


http://chatgpt.dhexx.cn/article/wgE1980k.shtml

相关文章

Metricbeat源码分析

0X00 版本信息 Golang&#xff1a;1.16.8 Metricbeat&#xff1a;7.14 0X01 Metricbeat介绍 Metricbeat quick start: installation and configuration | Metricbeat Reference [7.14] | Elastichttps://www.elastic.co/guide/en/beats/metricbeat/7.14/metricbeat-install…

Elk-Metricbeat配置Tomcat的日志分析 (Metricbeat-part3)

1, 安装软件 Metricbeat安装 请参考之前的文档链接&#xff1a; Metricbeat 8.4.0 linux 安装(Metricbeat-part1)_yangkei的博客-CSDN博客Metricbeat 能够以一种轻量型的方式&#xff0c;输送各种系统和服务统计数据&#xff0c;从 CPU 到内存&#xff0c;从 Redis 到 Nginx…

Metricbeat config file metricbeat.yml must be owned by the user identifier (uid=0) or root

Linux 上修改呢metricbeat.yml的权限&#xff0c;启动的时候报错。查了下解决方案 记录下 https://www.elastic.co/guide/en/beats/libbeat/5.3/config-file-permissions.html#config-file-permissions 简而言之就是所有者必须是root&#xff0c;然后权限必须是0644 sudo c…

Elk-Metricbeat配置Nginx的日志分析 (Metricbeat-part2)

1 情况说明&#xff1a; Metricbeat的基本安装部分可以参考&#xff1a; Metricbeat 8.4.0 linux 安装(Metricbeat-part1)_yangkei的博客-CSDN博客 下面来聊聊如何通过elkmetricbeat来监控Nginx日志。 借用网上以为大师的图就是这样子 Metricbeat 采集 Nginx 指标_叶康铭的…

metricbeat收集elasticsearch、kibana监控数据

一、kibana 1、下载metricbeat并部署到kibana所在的服务器 2、禁用 Kibana 监控指标的默认集合&#xff0c;在kibana.yml文件中增加如下配置&#xff1a; monitoring.kibana.collection.enabled: false3、从控制台或命令行&#xff0c;在生产集群上设置xpack.monitoring.col…

ELK日志采集平台(四)---轻量级采集工具metricbeat

目录 一、安装metricbeat 二、与kibana数据可视化联用 logstash是负责采集数据的&#xff0c;是入口&#xff0c;流向为logstash-> ES->kibana&#xff0c;但是它的资源消耗很大&#xff0c;有时候没那么多内存给他占用&#xff0c;同时有些定制的采集指标logstash无法…

Metricbeat安装下载,nginx模块使用

目录 MetricbeatMetricbeat组成下载启动Metricbeat Modulesystem module配置内容 Nginx Module开启Nginx Module 配置nginx module测试 Metricbeat 定期收集操作系统或应用服务的指标数据存储到Elasticsearch中&#xff0c;进行实时分析 Metricbeat组成 Metricbeat有2部分组成…

metricbeat对接kafka

在监控系统中经常用到kafka来处理数据&#xff0c;上层平台会从kafka直接取数据进行分析&#xff0c;今天分享下metricbeat监控的数据如何输出到kafka中&#xff0c;并对各配置项进行详细说明。 metricbeat环境搭建点这里 kafka环境搭建点这里 -在metricbeat配置文件中配置o…

Beats:通过 Metricbeat 实现外部对 Elastic Stack 的监控

自 Elastic 7.5 发布开始&#xff0c;通过外部监控 Elastic Stack 已经全面实施。 可以通过 Metricbeat 模块监视 Elasticsearch&#xff0c;Kibana&#xff0c;Logstash&#xff0c;APM 服务器和 Beats。 使用外部收集&#xff0c;用户现在可以收集和发送其 Elastic Stack 的…

Metricbeat 的使用

目标 统计并展示系统的信息 cpu&#xff0c; 内存等 (当然metricbeat能收集的信息种类还很多) 前提 版本&#xff1a; 5.x已经安装了ELK (elasticsearch, logstash (可选&#xff09;, kibana)安装了x-pack &#xff08;配置了对应的security&#xff09;&#xff08;可选&a…

Metricbeat 8.4.0 linux 安装(Metricbeat-part1)

Metricbeat是一款轻量型指标采集器&#xff0c;用于从系统和服务收集指标。Metricbeat 能够以一种轻量型的方式&#xff0c;输送各种系统和服务统计数据&#xff0c;从 CPU 到内存&#xff0c;从 Redis 到 Nginx&#xff0c;不一而足。将 Metricbeat 部署到您的所有 Linux、Win…

Metricbeat部署指南

官网下载metricbeat&#xff0c;https://www.elastic.co/downloads/beats/metricbeat。 解压tar包&#xff0c;tar -zxvf metricbeat-7.0.0-linux-x86_64.tar.gz。 进入目录&#xff0c;cd metricbeat-7.0.0-linux-x86_64。 编辑metricbeat配置文件metricbeat.yml&#xff1…

metricbeat的基本使用

文章目录 概述metricbeat安装metricbeat启动案例举例1&#xff1a;收集系统运行的指标数据至es举例2&#xff1a;收集es运行的指标数据至es 概述 定期收集操作系统或应用服务的指标数据存储到Elasticsearch中&#xff0c;进行实时分析 metricbeat安装 去下载页下载&#xff…

Metricbeat安装与初级使用

metricbeat作用&#xff1a; 将 Metricbeat 部署到您所有的 Linux、Windows 和 Mac 主机&#xff0c;并将它连接到 Elasticsearch 就大功告成啦&#xff1a;您可以获取系统级的 CPU 使用率、内存、文件系统、磁盘 IO 和网络 IO 统计数据&#xff0c;以及获得如同系统上 top 命令…

Metricbeat和Filebeat的安装及配置

Beats的安装及配置 一、Metricbeat的安装配置 环境准备 下载与es同版本的metricbeat&#xff0c;这里为 metricbeat-7.11.1-linux-x86_64.tar.gz 这里使用root用户进行配置及启动metricbeat 已启动对应的ES服务及Kibana服务 metricbeat的安装 这里在/路径下建立beats文件…

windows安装wget

1、下载地址&#xff1a;http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe 2、双击下载的exe&#xff0c;同意协议&#xff0c;更改安装安装目录。 其余默认安装&#xff0c;继续下一步&#xff0c;安装完成 3、设置系统环境变量 添加path变量&#xff1a;…

手动编译源代码安装wget

从wget的源代码入手&#xff0c;来完成wget在Ubuntu上的安装&#xff0c;如果你的机器上已经默认安装了wget&#xff0c;请采用apt-get remove命令先卸载掉。 解决configure: error: –with-ssl was given, but GNUTLS/SSL is not available.&#xff1b;解决error: ./stdio.h…

win10安装wget,从此可以更快的下载文件 and windows10 下 zip命令行参数详解

1.win10安装wget 1.1安装下载 GNU Wget 1.21.3 for Windows 依次如下&#xff1a; 2、将下载好的wget.exe放到 C:/windows/system32文件夹下 也可以自行放置文件&#xff0c;添加到系统路径即可 第三步&#xff1a;配置系统环境变量&#xff08;如下&#xff09;电脑-属性…

Mac安装wget流程及异常解决

目录 1.终端输入wget检查自己是否已经安装过wget,没有安装如下图 2. 安装brew 1)点击brew官网&#xff1a;官网网址 2&#xff09;将命令粘贴到终端&#xff0c;回车执行 3&#xff09;输入sudo密码。 4&#xff09;系统开始自动安装brew&#xff0c;等待晚装完成&#xf…

使用rpm 安装wget

步骤&#xff1a; 下载wget的rpm包&#xff1a;http://mirrors.163.com/centos/7/os/x86_64/Packages/ 使用浏览器搜索功能查找关键字 ,这个网站搜索wget 运行&#xff1a; rpm -ivh wget-1.14-15.el7_4.1.x86_64.rpm