在 Azure Monitor 中收集 Linux 应用程序的性能计数器Collect performance counters for Linux applications in Azure Monitor

本文详细介绍了如何配置适用于 Linux 的 Log Analytics 代理以将特定应用程序的性能计数器收集到 Azure Monitor 中。This article provides details for configuring the Log Analytics agent for Linux to collect performance counters for specific applications into Azure Monitor. 本文中包括的应用程序有:The applications included in this article are:

MySQLMySQL

如果安装 Log Analytics 代理时在计算机上检测到 MySQL 服务器或 MariaDB 服务器,则会自动安装 MySQL 服务器的性能监视提供程序。If MySQL Server or MariaDB Server is detected on the computer when the Log Analytics agent is installed, a performance monitoring provider for MySQL Server will be automatically installed. 此提供程序连接到本地 MySQL/MariaDB 服务器以公开性能统计信息。This provider connects to the local MySQL/MariaDB server to expose performance statistics. 必须配置 MySQL 用户凭据,以便提供程序能够访问 MySQL 服务器。MySQL user credentials must be configured so that the provider can access the MySQL Server.

配置 MySQL 凭据Configure MySQL credentials

MySQL OMI 提供程序需要预先配置 MySQL 用户并安装 MySQL 客户端库,才能从 MySQL 实例中查询性能和运行状况信息。The MySQL OMI provider requires a preconfigured MySQL user and installed MySQL client libraries in order to query the performance and health information from the MySQL instance. 这些凭据存储在 Linux 代理上存储的一个身份验证文件中。These credentials are stored in an authentication file that's stored on the Linux agent. 该身份验证文件指定了 MySQL 实例正在侦听的绑定地址和端口以及用于收集指标的凭据。The authentication file specifies what bind-address and port the MySQL instance is listening on and what credentials to use to gather metrics.

在安装 Log Analytics Linux 代理期间,MySQL OMI 提供程序会在 MySQL my.cnf 配置文件(默认位置)中扫描绑定地址和端口并对 MySQL OMI 身份验证文件进行部分设置。During installation of the Log Analytics agent for Linux the MySQL OMI provider will scan MySQL my.cnf configuration files (default locations) for bind-address and port and partially set the MySQL OMI authentication file.

MySQL 身份验证文件存储在 /var/opt/microsoft/mysql-cimprov/auth/omsagent/mysql-auth 处。The MySQL authentication file is stored at /var/opt/microsoft/mysql-cimprov/auth/omsagent/mysql-auth.

身份验证文件格式Authentication file format

下面是 MySQL OMI 身份验证文件的格式Following is the format for the MySQL OMI authentication file

[端口]=[绑定地址], [用户名], [Base64 编码的密码][Port]=[Bind-Address], [username], [Base64 encoded Password]
(端口)=(绑定地址), (用户名), (Base64 编码的密码)(Port)=(Bind-Address), (username), (Base64 encoded Password)
(端口)=(绑定地址), (用户名), (Base64 编码的密码)(Port)=(Bind-Address), (username), (Base64 encoded Password)
AutoUpdate=[true|false]AutoUpdate=[true|false]

下表描述了身份验证文件中的条目。The entries in the authentication file are described in the following table.

属性Property 描述Description
端口Port 表示 MySQL 实例正在侦听的当前端口。Represents the current port the MySQL instance is listening on. 端口 0 指定后面的属性用于默认实例。Port 0 specifies that the properties following are used for default instance.
绑定地址Bind-Address 当前 MySQL 绑定地址。Current MySQL bind-address.
usernameusername 用来监视 MySQL 服务器实例的 MySQL 用户。MySQL user used to use to monitor the MySQL server instance.
Base64 编码的密码Base64 encoded Password MySQL 监视用户的密码(采用 Base64 编码)。Password of the MySQL monitoring user encoded in Base64.
AutoUpdateAutoUpdate 指定当升级 MySQL OMI 提供程序时,是否将重新扫描 my.cnf 文件中的更改并覆盖 MySQL OMI 身份验证文件。Specifies whether to rescan for changes in the my.cnf file and overwrite the MySQL OMI Authentication file when the MySQL OMI Provider is upgraded.

默认实例Default instance

MySQL OMI 身份验证文件可以定义一个默认的实例和端口号,以便更轻松地管理一台 Linux 主机上的多个 MySQL 实例。The MySQL OMI authentication file can define a default instance and port number to make managing multiple MySQL instances on one Linux host easier. 端口为 0 的实例代表默认实例。The default instance is denoted by an instance with port 0. 所有其他实例都将继承在默认实例中设置的属性,除非它们指定了不同的值。All additional instances will inherit properties set from the default instance unless they specify different values. 例如,如果添加了在端口“3308”上侦听的 MySQL 实例,则将使用默认实例的绑定地址、用户名和 Base64 编码的密码来尝试和监视在端口 3308 上侦听的实例。For example, if MySQL instance listening on port ‘3308’ is added, the default instance’s bind-address, username, and Base64 encoded password will be used to try and monitor the instance listening on 3308. 如果 3308 上的实例绑定到了另一个地址,且使用相同的 MySQL 用户名和密码对,则只需要指定绑定地址,并且将继承其他属性。If the instance on 3308 is bound to another address and uses the same MySQL username and password pair only the bind-address is needed, and the other properties will be inherited.

下表提供了示例实例设置The following table has example instance settings

说明Description 文件File
默认实例和端口为 3308 的实例。Default instance and instance with port 3308. 0=127.0.0.1, myuser, cnBwdA==
3308=, ,
AutoUpdate=true
默认实例和端口为 3308 且采用不同用户名和密码的实例。Default instance and instance with port 3308 and different user name and password. 0=127.0.0.1, myuser, cnBwdA==
3308=127.0.1.1, myuser2,cGluaGVhZA==
AutoUpdate=true

MySQL OMI 身份验证文件程序MySQL OMI Authentication File Program

随 MySQL OMI 提供程序安装了一个 MySQL OMI 身份验证文件程序,可以使用该程序来编辑 MySQL OMI 身份验证文件。Included with the installation of the MySQL OMI provider is a MySQL OMI authentication file program which can be used to edit the MySQL OMI Authentication file. 可以在以下位置找到该身份验证文件程序。The authentication file program can be found at the following location.

/opt/microsoft/mysql-cimprov/bin/mycimprovauth

备注

凭据文件必须可供 omsagent 帐户读取。The credentials file must be readable by the omsagent account. 建议以 omsgent 身份运行 mycimprovauth 命令。Running the mycimprovauth command as omsgent is recommended.

下表提供了有关 mycimprovauth 的使用语法的详细信息。The following table provides details on the syntax for using mycimprovauth.

操作Operation 示例Example 说明Description
autoupdate false or trueautoupdate false or true mycimprovauth autoupdate falsemycimprovauth autoupdate false 设置在重新启动或更新时是否会自动更新身份验证文件。Sets whether or not the authentication file will be automatically updated on restart or update.
default bind-address username passworddefault bind-address username password mycimprovauth default 127.0.0.1 root pwdmycimprovauth default 127.0.0.1 root pwd 在 MySQL OMI 身份验证文件中设置默认实例。Sets the default instance in the MySQL OMI authentication file.
应当以纯文本输入密码字段 - MySQL OMI 身份验证文件中的密码将是 Base 64 编码的。The password field should be entered in plain text - the password in the MySQL OMI authentication file will be Base 64 encoded.
delete default or port_numdelete default or port_num mycimprovauth 3308mycimprovauth 3308 删除由默认值或端口号指定的实例。Deletes the specified instance by either default or by port number.
helphelp mycimprov helpmycimprov help 输出可使用的命令列表。Prints out a list of commands to use.
printprint mycimprov printmycimprov print 输出易于阅读的 MySQL OMI 身份验证文件。Prints out an easy to read MySQL OMI authentication file.
update port_num bind-address username passwordupdate port_num bind-address username password mycimprov update 3307 127.0.0.1 root pwdmycimprov update 3307 127.0.0.1 root pwd 更新指定的实例,或添加该实例(如果它不存在)。Updates the specified instance or adds the instance if it does not exist.

以下示例命令为 localhost 上的 MySQL 服务器定义了一个默认用户帐户。The following example commands define a default user account for the MySQL server on localhost. 应当以纯文本输入密码字段 - MySQL OMI 身份验证文件中的密码将是 Base 64 编码的The password field should be entered in plain text - the password in the MySQL OMI authentication file will be Base 64 encoded

sudo su omsagent -c '/opt/microsoft/mysql-cimprov/bin/mycimprovauth default 127.0.0.1 <username> <password>'
sudo /opt/omi/bin/service_control restart

MySQL 性能计数器所需的数据库权限Database Permissions Required for MySQL Performance Counters

MySQL 用户需要访问以下查询来收集 MySQL 服务器性能数据。The MySQL User requires access to the following queries to collect MySQL Server performance data.

SHOW GLOBAL STATUS;
SHOW GLOBAL VARIABLES:

MySQL 用户还需要对以下默认表具有 SELECT 访问权限。The MySQL user also requires SELECT access to the following default tables.

  • information_schemainformation_schema
  • mysqlmysql.

可以通过运行以下授予命令来授予这些特权。These privileges can be granted by running the following grant commands.

GRANT SELECT ON information_schema.* TO ‘monuser’@’localhost’;
GRANT SELECT ON mysql.* TO ‘monuser’@’localhost’;

备注

要向 MySQL 监视用户授予权限,执行授权的用户必须具有 'GRANT option' 特权以及要授予的特权。To grant permissions to a MySQL monitoring user the granting user must have the ‘GRANT option’ privilege as well as the privilege being granted.

定义性能计数器Define performance counters

将适用于 Linux 的 Log Analytics 代理配置为将数据发送到 Azure Monitor 后,必须配置要收集的性能计数器。Once you configure the Log Analytics agent for Linux to send data to Azure Monitor, you must configure the performance counters to collect. 请对下表中的计数器使用 Azure Monitor 中的 Windows 和 Linux 性能数据来源中所述的过程。Use the procedure in Windows and Linux performance data sources in Azure Monitor with the counters in the following table.

对象名称Object Name 计数器名称Counter Name
MySQL 数据库MySQL Database 磁盘空间(字节)Disk Space in Bytes
MySQL 数据库MySQL Database Tables
MySQL ServerMySQL Server 中止的连接百分比Aborted Connection Pct
MySQL ServerMySQL Server 连接使用百分比Connection Use Pct
MySQL ServerMySQL Server 磁盘空间使用(字节)Disk Space Use in Bytes
MySQL ServerMySQL Server 全表扫描百分比Full Table Scan Pct
MySQL ServerMySQL Server InnoDB 缓冲池命中百分比InnoDB Buffer Pool Hit Pct
MySQL ServerMySQL Server InnoDB 缓冲池使用百分比InnoDB Buffer Pool Use Pct
MySQL ServerMySQL Server InnoDB 缓冲池使用百分比InnoDB Buffer Pool Use Pct
MySQL ServerMySQL Server 键缓存命中百分比Key Cache Hit Pct
MySQL ServerMySQL Server 键缓存使用百分比Key Cache Use Pct
MySQL ServerMySQL Server 键缓存写入百分比Key Cache Write Pct
MySQL ServerMySQL Server 查询缓存命中百分比Query Cache Hit Pct
MySQL ServerMySQL Server 查询缓存修剪百分比Query Cache Prunes Pct
MySQL ServerMySQL Server 查询缓存使用百分比Query Cache Use Pct
MySQL ServerMySQL Server 表缓存命中百分比Table Cache Hit Pct
MySQL ServerMySQL Server 表缓存使用百分比Table Cache Use Pct
MySQL ServerMySQL Server 表锁争用百分比Table Lock Contention Pct

Apache HTTP ServerApache HTTP Server

如果安装 omsagent 捆绑包时在计算机上检测到 Apache HTTP Server,则会自动安装 Apache HTTP Server 的性能监视提供程序。If Apache HTTP Server is detected on the computer when the omsagent bundle is installed, a performance monitoring provider for Apache HTTP Server will be automatically installed. 此提供程序依赖于必须加载到 Apache HTTP Server 才能访问性能数据的一个 Apache 模块。This provider relies on an Apache module that must be loaded into the Apache HTTP Server in order to access performance data. 可以使用以下命令加载该模块:The module can be loaded with the following command:

sudo /opt/microsoft/apache-cimprov/bin/apache_config.sh -c

要卸载 Apache 监视模块,请运行以下命令︰To unload the Apache monitoring module, run the following command:

sudo /opt/microsoft/apache-cimprov/bin/apache_config.sh -u

定义性能计数器Define performance counters

将适用于 Linux 的 Log Analytics 代理配置为将数据发送到 Azure Monitor 后,必须配置要收集的性能计数器。Once you configure the Log Analytics agent for Linux to send data to Azure Monitor, you must configure the performance counters to collect. 请对下表中的计数器使用 Azure Monitor 中的 Windows 和 Linux 性能数据来源中所述的过程。Use the procedure in Windows and Linux performance data sources in Azure Monitor with the counters in the following table.

对象名称Object Name 计数器名称Counter Name
Apache HTTP ServerApache HTTP Server 繁忙工作线程数Busy Workers
Apache HTTP ServerApache HTTP Server 空闲工作线程数Idle Workers
Apache HTTP ServerApache HTTP Server 繁忙工作线程数百分比Pct Busy Workers
Apache HTTP ServerApache HTTP Server CPU 百分比总计Total Pct CPU
Apache 虚拟主机Apache Virtual Host 每分钟错误数 - 客户端Errors per Minute - Client
Apache 虚拟主机Apache Virtual Host 每分钟错误数 - 服务器Errors per Minute - Server
Apache 虚拟主机Apache Virtual Host 每个请求的 KB 数KB per Request
Apache 虚拟主机Apache Virtual Host 每秒的请求的 KB 数Requests KB per Second
Apache 虚拟主机Apache Virtual Host 每秒的请求数Requests per Second

后续步骤Next steps