1. 接口描述
接口请求域名: monitor.tencentcloudapi.com 。
创建 Prometheus 告警策略(将逐步废弃,建议使用 CreatePrometheusAlertGroup 创建告警策略)
默认接口请求频率限制:20次/秒。
推荐使用 API Explorer
点击调试
API Explorer 提供了在线调用、签名验证、SDK 代码生成和快速检索接口等能力。您可查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。
2. 输入参数
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
参数名称 | 必选 | 类型 | 描述 |
---|---|---|---|
Action | 是 | String | 公共参数,本接口取值:CreatePrometheusAlertPolicy。 |
Version | 是 | String | 公共参数,本接口取值:2018-07-24。 |
Region | 是 | String | 公共参数,详见产品支持的 地域列表。 |
InstanceId | 是 | String | 实例id 示例值:prom-ksnrbv |
AlertRule | 是 | PrometheusAlertPolicyItem | 告警配置 示例值:参考复杂类型 |
3. 输出参数
参数名称 | 类型 | 描述 |
---|---|---|
Id | String | 告警id 示例值:alert-oshger |
RequestId | String | 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。 |
4. 示例
示例1 新增告警
新增告警
输入示例
POST / HTTP/1.1
Host: monitor.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreatePrometheusAlertPolicy
<公共请求参数>
{
"InstanceId": "prom-kshrsdf",
"AlertRule": {
"Id": "alert-odhjeg",
"Name": "资源告警",
"TemplateId": "temp-cjhger",
"Notification": {
"Enabled": true,
"Type": "amp",
"WebHook": "",
"AlertManager": {
"ClusterType": "eks",
"ClusterId": "cls-ojeg",
"Url": "http://10.0.0.1:9000"
},
"RepeatInterval": "5m",
"TimeRangeStart": "00:00:00",
"TimeRangeEnd": "23:59:59",
"NotifyWay": [
"wechat"
],
"ReceiverGroups": [
"skjehrsheb"
],
"PhoneNotifyOrder": [
1
],
"PhoneCircleTimes": 0,
"PhoneInnerInterval": 0,
"PhoneCircleInterval": 0,
"PhoneArriveNotice": true
},
"Rules": [
{
"Annotations": [
{
"Name": "summary",
"Value": "磁盘使用率过高"
}
],
"Describe": "",
"For": "2m",
"Labels": [
{
"Name": "severity",
"Value": "warning"
}
],
"Name": "磁盘使用率过高",
"Rule": "1- node_filesystem_avail_bytes / node_filesystem_size_bytes > 0.85",
"RuleState": 0,
"Template": "磁盘使用率过高,实例: {{$labels.instance}},ID: {{$labels.instance_id}},当前值: {{ $value | humanizePercentage }}。"
}
],
"UpdatedAt": "2024-07-15T16:46:42+08:00",
"ClusterId": "cls-iehgr"
}
}
输出示例
{
"Response": {
"Id": "alert-ojnfb",
"RequestId": "ac-khgr-iohvr"
}
}
示例2 添加告警策略,告警渠道为Alertmanager
添加告警策略,告警渠道为Alertmanager
输入示例
POST / HTTP/1.1
Host: monitor.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreatePrometheusAlertPolicy
<公共请求参数>
{
"InstanceId": "prom-kshrsdf",
"AlertRule": {
"Id": "alert-odhjeg",
"Name": "资源告警",
"TemplateId": "temp-cjhger",
"Notification": {
"AlertManager": {
"ClusterId": "cls-ksjbr",
"ClusterType": "eks",
"Url": "http://10.0.0.1:9000/api/v1/alerts"
},
"Enabled": true,
"NotifyWay": null,
"PhoneArriveNotice": false,
"PhoneCircleInterval": 0,
"PhoneCircleTimes": 0,
"PhoneInnerInterval": 0,
"PhoneNotifyOrder": null,
"ReceiverGroups": null,
"RepeatInterval": "5m",
"TimeRangeEnd": "23:59:59",
"TimeRangeStart": "00:00:00",
"Type": "alertmanager",
"WebHook": ""
},
"Rules": [
{
"Annotations": [
{
"Name": "summary",
"Value": "MySQL High CPU Usage"
}
],
"Describe": "",
"For": "5m",
"Labels": [
{
"Name": "severity",
"Value": "warning"
}
],
"Name": "MySQL High CPU Usage",
"Rule": "avg by (instance_id,cluster_id,instance_region) (qce_cynosdb_mysql_cpuuserate_max) > 85",
"RuleState": 0,
"Template": "MySQL cpu usage is higher than 85%. Instance ID: {{ $labels.instance_id }}, cluster ID: {{ $labels.cluster_id }}, region: {{ $labels.instance_region }}"
}
],
"ClusterId": "cls-iehgr"
}
}
输出示例
{
"Response": {
"Id": "alert-xxx",
"RequestId": "3dfe620f-11b8-4301-b279-1fdadedf7a59"
}
}
5. 开发者资源
腾讯云 API 平台
腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。
API Inspector
用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。
SDK
云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。
- Tencent Cloud SDK 3.0 for Python: GitHub Gitee
- Tencent Cloud SDK 3.0 for Java: GitHub Gitee
- Tencent Cloud SDK 3.0 for PHP: GitHub Gitee
- Tencent Cloud SDK 3.0 for Go: GitHub Gitee
- Tencent Cloud SDK 3.0 for Node.js: GitHub Gitee
- Tencent Cloud SDK 3.0 for .NET: GitHub Gitee
- Tencent Cloud SDK 3.0 for C++: GitHub Gitee
- Tencent Cloud SDK 3.0 for Ruby: GitHub Gitee
命令行工具
6. 错误码
以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码。
错误码 | 描述 |
---|---|
FailedOperation.ComponentClientCommon | FailedOperation.ComponentClientCommon |
FailedOperation.ComponentClientUnpack | FailedOperation.ComponentClientUnpack |
FailedOperation.Db | FailedOperation.Db |
FailedOperation.DoTRPCTransferFailed | DoTRPCTransferFailed |
FailedOperation.KubeClientConf | FailedOperation.KubeClientConf |
FailedOperation.KubeCommon | FailedOperation.KubeCommon |
InternalError | 内部错误。 |
InternalError.Param | InternalError.Param |
InternalError.UnexpectedInternal | InternalError.UnexpectedInternal |
InvalidParameter.Param | InvalidParameter.Param |
InvalidParameter.PromClusterNotFound | InvalidParameter.PromClusterNotFound |
InvalidParameter.PromInstanceNotFound | InvalidParameter.PromInstanceNotFound |
ResourceNotFound | 资源不存在。 |