监控(ibmcloud 监控)CLI
IBM Cloud® 命令行界面 (CLI) 为服务产品提供了额外的功能。 本信息介绍如何使用 CLI 访问 IBM Cloud Monitoring 中的信息。
先决条件
-
安装 IBM Cloud CLI。
-
运行以下命令安装 IBM Cloud 监控 CLI:
ibmcloud plugin install monitoring
当 IBM Cloud CLI 和插件的更新可用时,命令行会通知您。 确保更新 CLI,以便使用最新的命令。 运行 ibmcloud plugin list
可查看所有已安装插件的当前版本。
添加 IBM 云监控警报
使用此命令添加警报。
ibmcloud monitoring alert add --name NAME [--alert-name ALERT_NAME] [--description DESCRIPTION] [--type TYPE] [--timespan TIMESPAN] [--condition CONDITION] [--severity SEVERITY] [--severity-label LOW, MEDIUM OR HIGH] [--disable] [--segment SEGMENT] [--segment-condition SEGMENT_CONDITION] [--user-filter USER_FILTER] [--notify NOTIFY] [--file JSON_FILE] [--region REGION] [--output FORMAT] [--team TEAM_NAME]
命令选项
--name <NAME>
|--n <NAME>
-
实例的名称。
--alert-name <ALERT_NAME>
-
警报的名称。
--description <DESCRIPTION>
-
有关警报的信息。
--type <TYPE>
-
警报类型。 有效值包括 MANUAL、BASELINE 和 HOST_COMPARISON。
--timespan <TIMESPAN>
-
在触发警报之前必须满足警报条件的最短时间间隔(以微秒为单位)。 默认值为60,000,000微秒。
--condition <CONDITION>
-
警报阈值。 手动警报需要此参数,不适用于其他警报类型。
--severity <SEVERITY>
|-s <SEVERITY>
-
严重程度。 有效值范围为 0 至 7。0 表示紧急,7 表示调试。 默认情况下,严重性设置为4。
--severity-label <LOW | MEDIUM | HIGH>
-
警报的关键性。 有效值为
HIGH
、MEDIUM
、LOW
。较低的严重性值表示较高的严重性。 --disable
-
警报状态。 默认情况下,警报在创建时就已启用。 创建警报时,必须设置此参数才能禁用警报。
--segment <SEGMENT>
-
其他细分标准。 例如,您可以通过
['host.mac', 'proc.name']
来分割警报。 --segment-condition <SEGMENT_CONDITION>
-
定义了在
--segment
参数中指定的每个被监控实体的警报触发时间。 手动警报需要此参数,不适用于其他警报类型。 有效值为ANY
和ALL
。ANY
表示当至少一个受监控实体满足条件时触发警报。ALL
表示当所有受监控实体都满足条件时触发警报。 --user-filter <USER_FILTER>
-
布尔表达式,可用于缩小警报范围。 使用此参数可配置分段,如
kubernetes.namespace.name='production'
或container.image='nginx'
等过滤器。 --notify <NOTIFY>
-
您希望此提醒生成的通知类型。 选项包括
EMAIL
、SNS
、PAGER_DUTY
和SYSDIG_DUMP
。 --file <FILE>
|-f <JSON_FILE>
-
包含用于创建新警报的数据集的 JSON 文件的名称。 在调用此命令之前,请确保已创建
alert.json
文件。 --region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --output <FORMAT>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --team <TEAM_NAME>
-
用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring alert add
命令的示例。
为 IBM Cloud Monitoring abc
实例添加警报,以检测过去 5 分钟内发生的 CrashLoopBackOff 事件。
ibmcloud monitoring alert add \
--name "IBM Cloud Monitoring abc" \
--description "Alert to report crashLoopBackOffs that are detected" \
--severity 2 \
--timespan 300 \
--condition 'sum(avg(kubernetes.pod.restart.count)) > 1' \
--alert-name '[Kubernetes] Pod crash/restart loop'
为 IBM Cloud Monitoring abc
实例添加警报,以检测最近 5 分钟内发生的 CrashLoopBackOff 事件,并将严重性设置为中等。
ibmcloud monitoring alert add \
--name "IBM Cloud Monitoring abc" \
--description "Alert to report crashLoopBackOffs that are detected" \
--severity 2 \
--severity-label MEDIUM \
--timespan 300 \
--condition 'sum(avg(kubernetes.pod.restart.count)) > 1' \
--alert-name '[Kubernetes] Pod crash/restart loop'
IBM 云监控警报列表
使用此命令可列出指定实例的警报。
ibmcloud monitoring alert list --name NAME [--severity SEVERITY] [--enabled TRUE or FALSE] [--region REGION] [--output FORMAT] [--team TEAM_NAME]
命令选项
--name <NAME>
|--n <NAME>
-
实例的名称。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --severity <SEVERITY>
|-s <SEVERITY>
-
以逗号分隔的严重性值列表,用双引号(")括起来。如果只指定一个严重性,双引号可以省略。
--output <FORMAT>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --enabled <TRUE | FALSE>
|-e <TRUE | FALSE>
-
布尔值,表示根据警报通知设置列出的警报。 如果指定,
--enabled true
将列出启用了电子邮件或 Slack 等通知的实例的警报。 指定--enabled false
将返回未启用通知的实例的警报列表。 --team <TEAM_NAME>
-
用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring alert list
命令的示例。
列出 IBM Cloud Monitoring abc
实例的所有警报。
ibmcloud monitoring alert list --name "IBM Cloud Monitoring abc"
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中的所有警报。
ibmcloud monitoring alert list --name "IBM Cloud Monitoring abc" --region us-south
列出未启用通知的 low
和 medium
严重程度的 IBM Cloud Monitoring abc
实例的所有警报。
ibmcloud monitoring alert list --name "IBM Cloud Monitoring abc" --enabled false --severity low,medium
获取 IBM 云监控警报
使用此命令可通过警报 ID 获取警报的详细信息。
ibmcloud monitoring alert get --name NAME --id ALERT_ID [--region REGION] [--output FORMAT] [--team TEAM_NAME]
命令选项
--name <NAME>
|--n <NAME>
-
实例的名称。
--id <ALERT_ID>
-
警报的标识。
--region <REGIO>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --output <FORMAT>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --team <TEAM_NAME>
-
用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring alert get
命令的示例。
获取 IBM Cloud Monitoring abc
实例中 ID 为 1234567 的警报的详细信息。
ibmcloud monitoring alert get --name "IBM Cloud Monitoring abc" --id 1234567
获取 us-south
区域中 IBM Cloud Monitoring abc
实例的 ID 为 1234567 的警报详细信息。
ibmcloud monitoring alert get --name "IBM Cloud Monitoring abc" --id 1234567 --region us-south
IBM 云监控警报更新
使用此命令可通过 JSON 文件修改警报。
要更新警报,必须修改通过运行 ibmcloud monitoring alert get
命令得到的 JSON 文件。
ibmcloud monitoring alert update --name NAME --id ALERT_ID --file JSON_FILE [--region REGION] [--output FORMAT] [--team TEAM_NAME]
命令选项
--name <NAME>
|--n <NAME>
-
实例的名称。
--id <ALERT_ID>
-
警报的标识。
--file <FILE>
|-f <JSON_FILE>
-
包含警报定义数据的 JSON 文件名称。 在调用此命令前,请确保已创建或修改了 alert.json 文件。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --output <TYPE>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --team <TEAM_NAME>
-
用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring alert update
命令的示例。
为 IBM Cloud Monitoring abc
实例更新 ID 为 1234567 的警报。
ibmcloud monitoring alert update --name "IBM Cloud Monitoring abc" --id 1234567 --file alert.json
为 us-south
区域中的 IBM Cloud Monitoring abc
实例更新 ID 为 1234567 的警报。
ibmcloud monitoring alert update --name "IBM Cloud Monitoring abc" --id 1234567 --file alert.json --region us-south
删除 IBM 云监控警报
使用此命令可删除警报。
ibmcloud monitoring alert delete --name NAME --id ALERT_ID [--region REGION] [--force] [--team TEAM_NAME]
命令选项
--name <NAME>
|--n <NAME>
- 实例的名称。
--id <ALERT_ID>
- 警报的标识。
--region <REGION>
|-r <REGION>
- 例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --force
- 忽略提示并从
--name
指定的实例中删除警报。 --team <TEAM_NAME>
- 用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
- 列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring alert delete
命令的示例。
删除 IBM Cloud Monitoring abc
实例中 ID 为 1234567 的警报。
ibmcloud monitoring alert delete --name "IBM Cloud Monitoring abc" --id 1234567 --file alert.json
删除 us-south
区域中 IBM Cloud Monitoring abc
实例的 ID 为 1234567 的警报。
ibmcloud monitoring alert delete --name "IBM Cloud Monitoring abc" --id 1234567 --file alert.json --region us-south
ibmcloud 监控服务实例
使用此命令可列出 IBM Cloud Monitoring 服务实例。
ibmcloud monitoring service-instances [--region REGION] [--all-regions] [--g RESOURCE_GROUP] [--all-resource-groups] [--quiet] [--output FORMAT]
命令选项
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --all-regions
-
在所有地区提供服务。
-g <RESOURCE_GROUP>
-
与托管服务相关的资源组。
--all-resource-groups
-
所有资源组托管的服务。
--quiet
|-q
-
取消冗长输出。
--output <FORMAT>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring service-instances
命令的示例。
列出所有监控服务实例。
ibmcloud monitoring service-instances
列出 test-rg
资源组中的所有实例。
ibmcloud monitoring service-instances -g test-rg
列出所有实例并包含其他详细信息,如 ID、GUID 和资源 ID。
ibmcloud monitoring service-instances --output wide
列出所有实例,并只包括姓名、地区和州等最基本的细节。
ibmcloud monitoring service-instances --quiet
列出 us-south
区域的所有实例。
ibmcloud monitoring service-instances --region us-south
列出 us-south
区域中的所有实例,并以 JSON 格式返回输出。
ibmcloud monitoring service-instances --region us-south --output json
ibmcloud 监控平台-指标接收器
使用此命令可配置指定的 IBM Cloud Monitoring 服务实例以接收平台指标。 运行时,该命令会提示用户保留现有服务实例或用指定实例替换。
ibmcloud monitoring platform-metrics-receiver --name NAME [--region REGION] [--force]
命令选项
--name <NAME>
|--n <NAME>
- 实例的名称。
--region <REGION>
|-r <REGION>
- 例如,地区名称,
us-south
或eu-gb
。 如果未指定,则使用登录的区域或目标区域。 --force
- 忽略提示,并用
--name
指定的实例替换现有平台度量实例。 --help
|-h
- 列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring platform-metrics-receiver
命令的示例。
将 IBM Cloud Monitoring abc
配置为接收平台指标的实例。
ibmcloud monitoring platform-metrics-receiver --name "IBM Cloud Monitoring abc"
将 eu-gb
区域中的 IBM Cloud Monitoring abc
配置为接收平台指标的实例。
ibmcloud monitoring platform-metrics-receiver --name "IBM Cloud Monitoring abc" --region eu-gb
ibmcloud 监控仪表板列表
使用此命令可列出用户在监控实例中可见的所有仪表盘。
ibmcloud monitoring dashboard list --name NAME [--region REGION] [--output FORMAT] [--team TEAM_NAME]
命令选项
--name <NAME>
|--sn <NAME>
-
实例的名称。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --output <TYPE>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --team <TEAM_NAME>
-
用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring dashboard list
命令的示例。
列出 IBM Cloud Monitoring abc
实例的所有仪表盘。
ibmcloud monitoring dashboard list
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中的所有仪表盘。
ibmcloud monitoring dashboard list --region us-south
ibmcloud 监控仪表板获取
使用此命令可以通过仪表盘 ID 获取仪表盘的详细信息。
ibmcloud monitoring dashboard get --id DASHBOARD_ID --name NAME [OPTIONS] [--team TEAM_NAME]
命令选项
--name <NAME>
|--sn <NAME>
- 实例的名称。
--id <DASHBOARD_ID>
- 特定服务实例的 Dashboard_ID。
--region <REGION>
|-r <REGION>
- 例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --team <TEAM_NAME>
- 用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
- 列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring dashboard get
命令的示例。
为 IBM Cloud Monitoring abc
实例获取 ID 为 1234567 的仪表盘信息。
ibmcloud monitoring dashboard get --name "IBM Cloud Monitoring abc"
为 us-south
区域中的 IBM Cloud Monitoring abc
实例获取 ID 为 1234567 的仪表盘信息。
ibmcloud monitoring dashboard get --name "IBM Cloud Monitoring abc" --region us-south
ibmcloud 监控仪表板 add-json
使用此命令可使用 JSON 文件创建仪表盘。
ibmcloud monitoring dashboard add-json --file JSON_FILE --name NAME [--region REGION] [--team TEAM_NAME]
命令选项
--file <FILE>
|-f <JSON_FILE>
- 包含新仪表板创建信息的JSON文件名称。 在调用此命令之前,请确保已创建 dashboard.json 文件。
--name <NAME>
|--sn <NAME>
- 实例的名称。
--region <REGION>
|-r <REGION>
- 例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --team <TEAM_NAME>
- 用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
- 列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring dashboard add-json
命令的示例。
为 IBM Cloud Monitoring abc
实例创建仪表盘。
ibmcloud monitoring dashboard add-json --name "IBM Cloud Monitoring abc" --file dashboard.json
在 us-south
区域中为 IBM Cloud Monitoring abc
实例创建仪表盘。
ibmcloud monitoring dashboard add-json --name "IBM Cloud Monitoring abc" --file dashboard.json --region us-south
IBM 云监控事件列表
使用此命令列出事件。
ibmcloud monitoring event list --name NAME [--region REGION] [--last DURATION] [--from TIMESTAMP] [--to TIMESTAMP] [--limit LIMIT] [--output FORMAT] [--team TEAM_NAME]
命令选项
--name <NAME>
|--sn <NAME>
-
实例的名称。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --last <DURATION>
-
要列出事件的时间段。 例如,您可以设置
12h
显示过去 12 小时内的事件,15m
显示过去 15 分钟内的事件,或10d
显示过去 10 天内的事件。 --from <TIMESTAMP>
-
事件开始时的 Unix 时间戳记(以秒为单位)。
--to <TIMESTAMP>
-
事件结束时的 Unix 时间戳记(以秒为单位)。
--limit <LIMIT>
-
在请求中指定的时间段内要打印的最大事件数。 默认情况下,该参数设置为 100 个事件。 可设置的事件上限为 10000 个。
--output <TYPE>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --team <TEAM_NAME>
-
用于授权的 IBM Cloud Monitoring 小组的名称。 如果未指定团队,则使用默认团队。
--help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring event list
命令的示例。
列出 IBM Cloud Monitoring abc
实例的事件。
ibmcloud monitoring event list --name "IBM Cloud Monitoring abc"
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中的事件。
ibmcloud monitoring event list --name "IBM Cloud Monitoring abc" --region us-south
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中最近一小时内发生的事件。
ibmcloud monitoring event list --name "IBM Cloud Monitoring abc" --region us-south --duration 1H
IBM 云监控设置通知列表
使用此命令可列出通知通道。
ibmcloud monitoring settings notification list --name NAME [--region REGION] [--output FORMAT]
命令选项
--name <NAME>
|--sn <NAME>
-
实例的名称。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --output <TYPE>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring settings notification list
命令的示例。
列出 IBM Cloud Monitoring abc
实例的通知通道。
ibmcloud monitoring settings notification list --name "IBM Cloud Monitoring abc"
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中的通知通道。
ibmcloud monitoring settings notification list --name "IBM Cloud Monitoring abc" --region us-south
IBM 云监控设置团队列表
使用此命令列出团队。
ibmcloud monitoring settings team list --name NAME [--region REGION] [--output FORMAT]
命令选项
--name <NAME>
|--sn <NAME>
-
实例的名称。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --output <TYPE>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring settings team list
命令的示例。
列出 IBM Cloud Monitoring abc
实例的团队。
ibmcloud monitoring settings team list --name "IBM Cloud Monitoring abc"
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中的团队。
ibmcloud monitoring settings team list --name "IBM Cloud Monitoring abc" --region us-south
IBM 云监控设置用户列表
可使用此命令来列出用户。
ibmcloud monitoring settings user list --name NAME [--region REGION] [--teamID TEAM_ID] [--output FORMAT]
命令选项
--name <NAME>
|--sn <NAME>
-
实例的名称。
--region <REGION>
|-r <REGION>
-
例如,地区名称,
us-south
或eu-gb
。 如果未指定,将使用登录或锁定的区域。 --teamID <TEAM_ID>
-
团队的 ID。
--output <TYPE>
-
用逗号分隔的输出首选项列表,用双引号(")括起来。如果只指定一个首选项,双引号可以省略。 支持的选项有
WIDE
和JSON
。如果指定了
JSON
,输出将以 JSON 格式返回。 如果未指定JSON
,则将以表格形式返回输出。WIDE
在输出中返回更多详细信息。 --help
|-h
-
列出命令的可用选项。
示例
以下是使用 ibmcloud monitoring settings user list
命令的示例。
列出 IBM Cloud Monitoring abc
实例的用户。
ibmcloud monitoring settings user list --name "IBM Cloud Monitoring abc"
列出 IBM Cloud Monitoring abc
实例在 us-south
区域中的用户。
ibmcloud monitoring settings user list --name "IBM Cloud Monitoring abc" --region us-south