

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将公制数学与 CloudWatch 指标配合使用
<a name="monitoring-metric-math"></a>

使用指标数学，您可以查询多个 Amazon CloudWatch 指标，并使用数学表达式根据这些指标创建新的时间序列。您可以在 CloudWatch 控制台中可视化生成的时间序列并将其添加到仪表板中。例如，可以使用 Amazon EFS 指标将 `DataRead` 操作样本数除以 60。结果是在给定 1 分钟间隔内在文件系统上平均每秒读取的次数。有关指标数学的更多信息，请参阅 *Amazon CloudWatch 用户指南中的将[数学表达式与 CloudWatch 指标配合使用](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html)。*

可以在下文中找到一些有用的 Amazon EFS 指标数学表达式。

**Topics**
+ [公制数学：吞吐量 MiBps](#metric-math-throughput-mib)
+ [指标数学：百分比吞吐量](#metric-math-throughput-percent)
+ [指标数学：允许的吞吐量利用率百分比](#metric-math-throughput-utilization)
+ [指标数学：吞吐量 IOPS](#metric-math-throughput-iops)
+ [指标数学：IOPS 百分比](#metric-math-iops-percent)
+ [公制数学：以 KiB 为 I/O 单位的平均大小](#metric-math-average-io)
+ [通过 Amazon EFS 的 CloudFormation 模板使用公制数学](#metric-math-cloudformation-template)

## 公制数学：吞吐量 MiBps
<a name="metric-math-throughput-mib"></a>

要计算一段时间内的平均吞吐量 (in MiBps)，请先选择一个总和统计数据（`DataReadIOBytes``DataWriteIOBytes`、`MetadataIOBytes`、或`TotalIOBytes`）。然后，将该值转换为 MiB，并将该值除以该时间段的秒数。

假设您的示例逻辑是：(`TotalIOBytes` 总和 ÷ 1048576 (以转换为 MiB)) ÷ 该时间段的秒数

那么您的 CloudWatch 指标信息如下所示。


| ID | 可用的指标 | Statistic | 周期 | 
| --- | --- | --- | --- | 
| m1 |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | sum | 1 minute | 

您的指标数学 ID 和表达式如下所示。


| ID | Expression | 
| --- | --- | 
| e1 | (m1/1048576)/PERIOD(m1) | 

## 指标数学：百分比吞吐量
<a name="metric-math-throughput-percent"></a>

此度量数学表达式计算用于不同 I/O 类型的总吞吐量的百分比，例如，由读取请求驱动的总吞吐量的百分比。要计算一段时间内某个 I/O 类型（`DataReadIOBytes`、`DataWriteIOBytes` 或 `MetadataIOBytes`）使用的总吞吐量百分比，请首先将相应的总和统计值乘以 100。然后，将结果除以同一时间段的 `TotalIOBytes` 总计统计数据。

假设您的示例逻辑是：(`DataReadIOBytes` 总和 x 100 (以转换为百分比)) ÷ `TotalIOBytes` 总和

那么您的 CloudWatch 指标信息如下所示。


| ID | 可用的一个或多个指标 | Statistic | 周期 | 
| --- | --- | --- | --- | 
| m1 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | sum | 1 minute | 
| m2 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | sum | 1 minute | 

您的指标数学 ID 和表达式如下所示。


| ID | Expression | 
| --- | --- | 
| e1 | (m2\$1100)/m1 | 

## 指标数学：允许的吞吐量利用率百分比
<a name="metric-math-throughput-utilization"></a>

要计算一段时间内允许的吞吐量利用率 (`MeteredIOBytes`) 的百分比，请先将吞吐量乘以 100。 MiBps然后，将结果除以同一时段的 `PermittedThroughput` 平均统计数据（转换为 MiB）。

假设你的示例逻辑是这样的：（以 MiBps x 100 为单位的吞吐量的度量数学表达式（转换为百分比））▼（总和 ± 1,048,576（将字节转换为 MiB））`PermittedThroughput`

那么您的 CloudWatch 指标信息如下所示。


| ID | 可用的一个或多个指标 | Statistic | 周期 | 
| --- | --- | --- | --- | 
| m1 |  `MeteredIOBytes`  | sum | 1 minute | 
| m2 | `PermittedThroughput` | average | 1 minute | 

您的指标数学 ID 和表达式如下所示。


| ID | Expression | 
| --- | --- | 
| e1 |   (m1/1048576)/PERIOD(m1)  | 
| e2 | m2/1048576 | 
| e3 | ((e1)\$1100)/(e2) | 

## 指标数学：吞吐量 IOPS
<a name="metric-math-throughput-iops"></a>

要计算某个时间段的平均每秒操作数 (IOPS)，请将样本数统计数据（`DataReadIOBytes`、`DataWriteIOBytes`、`MetadataIOBytes` 或 `TotalIOBytes`）除以该时间段的秒数。

假设您的示例逻辑是：`DataWriteIOBytes` 样本数 ÷ 该时间段的秒数

那么您的 CloudWatch 指标信息如下所示。


| ID | 可用的指标 | Statistic | 周期 | 
| --- | --- | --- | --- | 
| m1 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | 样本数 | 1 minute | 

您的指标数学 ID 和表达式如下所示。


| ID | Expression | 
| --- | --- | 
| e1 | m1/PERIOD(m1) | 

## 指标数学：IOPS 百分比
<a name="metric-math-iops-percent"></a>

要计算一段时间内不同 I/O 类型（`DataReadIOBytes`、`DataWriteIOBytes`或`MetadataIOBytes`）每秒 IOPS 的百分比，请先将相应的样本计数统计数据乘以 100。然后，将该值除以同一时间段的 `TotalIOBytes` 样本数统计数据。

假设您的示例逻辑是：(`MetadataIOBytes` 样本数 x 100 (以转换为百分比)) ÷ `TotalIOBytes` 样本数

那么您的 CloudWatch 指标信息如下所示。


| ID | 可用的指标 | Statistic | 周期 | 
| --- | --- | --- | --- | 
| m1 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | 样本数 | 1 minute | 
| m2 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | 样本数 | 1 minute | 

您的指标数学 ID 和表达式如下所示。


| ID | Expression | 
| --- | --- | 
| e1 | (m2\$1100)/m1 | 

## 公制数学：以 KiB 为 I/O 单位的平均大小
<a name="metric-math-average-io"></a>

要计算一段时间内的平均 I/O 大小（以 KiB 为单位），请将`DataReadIOBytes``DataWriteIOBytes`、或`MetadataIOBytes`指标的相应总和统计数据除以该指标的相同样本计数统计量。

假设您的示例逻辑是：（`DataReadIOBytes` 总和 ÷ 1024（以转换为 KiB））÷ `DataReadIOBytes` 样本数

那么您的 CloudWatch 指标信息如下所示。


| ID | 可用的指标 | Statistic | 周期 | 
| --- | --- | --- | --- | 
| m1 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | sum | 1 minute | 
| m2 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/efs/latest/ug/monitoring-metric-math.html)  | 样本数 | 1 minute | 

您的指标数学 ID 和表达式如下所示。


| ID | Expression | 
| --- | --- | 
| e1 | (m1/1024)/m2 | 

## 通过 Amazon EFS 的 CloudFormation 模板使用公制数学
<a name="metric-math-cloudformation-template"></a>

您也可以通过 CloudFormation 模板创建公制数学表达式。其中一个模板可供您下载和自定义，以便在 [Amazon EFS 教程](https://github.com/aws-samples/amazon-efs-tutorial)中使用 GitHub。有关使用 CloudFormation 模板的更多信息，请参阅《*AWS CloudFormation 用户指南》中的[使用 CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)。*