tencent cloud

Prometheus 监控服务

产品简介
产品概述
产品优势
应用场景
基本概念
相关限制
功能特性
开服地域
购买指南
计费概述
按量付费(后付费)
免费试用介绍
托管采集器付费介绍
归档存储付费介绍
购买方式
欠费说明
快速入门
接入指南
抓取配置说明
自定义监控
EMR 接入
Java 应用接入
Golang 应用接入
Exporters 接入
Nacos 接入
通用组件监控
健康巡检
TKE 集群内安装组件说明
云监控
非腾讯云主机监控
通过 Remote Read 读取云托管 Prometheus 实例数据
Agent 自助接入
Pushgateway 接入
安全组开放说明
操作指南
实例
容器监控
集成中心
数据多写
预聚合
实例诊断
归档存储
告警策略
标签管理
访问控制
Grafana
API 使用指南
容器服务指标
相关资源使用及计费说明
实践教程
自建 Prometheus 迁入
云服务器场景下自定义接入
容器场景监控
TKE Serverless 集群如何放通外网
Prometheus 监控服务如何接入本地 Grafana
Prometheus 实例访问公网
配置 Prometheus 公网地址
Terraform
Terraform 概述
使用 Terraform 管理 Prometheus 实例
使用 Terraform 管理 Prometheus 实例的集成中心
使用 Terraform 采集容器监控数据
使用 Terraform 配置告警策略
常见问题
基础问题
集成容器服务相关
产品咨询
使用&技术问题
云监控问题
服务等级协议
TMP 政策
TMP 隐私协议
TMP 数据处理和安全协议
文档Prometheus 监控服务Terraform使用 Terraform 采集容器监控数据

使用 Terraform 采集容器监控数据

PDF
聚焦模式
字号
最后更新时间: 2024-10-09 10:09:20

前提条件

安装 Terraform

关于安装 Terraform 的具体操作,请参见在 本地安装和配置 Terraform
说明:
Terraform 安装版本不得低于 v1.6.3,可通过 terraform --version 命令查看安装后 Terraform 版本。

配置腾讯云账号信息

在首次使用 Terraform 之前,请前往 云 API 密钥页面 申请安全凭证 SecretId 和 SecretKey。若已有可使用的安全凭证,则跳过该步骤。
1. 登录 访问管理控制台,在左侧导航栏,选择访问密钥 > API 密钥管理
2. 在 API 密钥管理页面,单击新建密钥,即可以创建一对 SecretId / SecretKey。

配置腾讯云账号信息,有以下两种方式:

静态凭证鉴权
在用户目录下创建 provider.tf 文件,输入如下内容。其中my-secret-idmy-secret-key 需替换为密钥 SecretId 和 SecretKey。
provider "tencentcloud" {
secret_id = "my-secret-id"
secret_key = "my-secret-key"
}
环境变量鉴权
配置电脑环境变量或云端环境变量,请执行以下命令。其中YOUR_SECRET_IDYOUR_SECRET_KEY 需替换为密钥 SecretId 和 SecretKey。
export TENCENTCLOUD_SECRET_ID=YOUR_SECRET_ID
export TENCENTCLOUD_SECRET_KEY=YOUR_SECRET_KEY

增加 Prometheus 实例的采集容器监控数据

1. 创建一个新的 Terraform 配置文件:创建一个新目录,并在该目录下创建一个名为 main.tf 的文件,配置如下信息:
# 指定 provider 配置信息

terraform { required_providers { tencentcloud = { source = "tencentcloudstack/tencentcloud" } } }
# prometheus管理云监控集成

#prometheus 管理容器集群(采集容器)

resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" {
instance_id = tencentcloud_monitor_tmp_instance.foo.id
agents {
region = "ap-mumbai"
cluster_type = "eks"
cluster_id = "cls-1uary7z2" #需要关联的集群id
enable_external = false
}
}
说明:
创建 Prometheus 实例的集成中心组件需配置对应参数,需配置的字段如下:
instance_id: (必填、字符串、ForceNew)实例 ID。
agents :(必填,列表)代理列表。
cluster_id :(必填,字符串)标识集群的 id。
region:(必填,字符串)区域限制。
enable_external: (必填,Bool) 是否开启公网 CLB。
cluster_type:(必填,字符串)集群类型。
您若需要获取更多详细参数请参考 腾讯接入云集成接入 github,也可以通过 Terraform 腾讯云提供商 了解更多。
2. 初始化 Terraform 运行环境,执行命令如下:
terraform init
预期输出信息:
Initializing the backend...

Initializing provider plugins...
- Reusing previous version of tencentcloudstack/tencentcloud from the dependency lock file
- Using previously-installed tencentcloudstack/tencentcloud v1.81.32

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
3. 生成资源规划,执行命令如下:
terraform plan
预期输出信息:
tencentcloud_monitor_tmp_instance.foo: Refreshing state... [id=prom-jh0zntj2]
tencentcloud_monitor_tmp_exporter_integration.tmpExporterIntegration: Refreshing state... [id=balck-box-tf-test#prom-jh0zntj2#1##blackbox-exporter]
tencentcloud_monitor_tmp_exporter_integration.tmpExporterMointor: Refreshing state... [id=tf-test-cjtest#prom-jh0zntj2#1##qcloud-exporter]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
+ create

Terraform will perform the following actions:

# tencentcloud_monitor_tmp_tke_cluster_agent.foo will be created
+ resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" {
+ id = (known after apply)
+ instance_id = "prom-jh0zntj2"

+ agents {
+ cluster_id = "cls-1uary7z2"
+ cluster_name = (known after apply)
+ cluster_type = "eks"
+ enable_external = false
+ region = "ap-mumbai"
+ status = (known after apply)
}
}

Plan: 1 to add, 0 to change, 0 to destroy.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if
you run "terraform apply" now.
4. 创建集成中心组件集成,执行命令如下:
terraform apply
预期输出信息:
tencentcloud_monitor_tmp_instance.foo: Refreshing state... [id=prom-jh0zntj2]
tencentcloud_monitor_tmp_exporter_integration.tmpExporterIntegration: Refreshing state... [id=balck-box-tf-test#prom-jh0zntj2#1##blackbox-exporter]
tencentcloud_monitor_tmp_exporter_integration.tmpExporterMointor: Refreshing state... [id=tf-test-cjtest#prom-jh0zntj2#1##qcloud-exporter]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
+ create

Terraform will perform the following actions:

# tencentcloud_monitor_tmp_tke_cluster_agent.foo will be created
+ resource "tencentcloud_monitor_tmp_tke_cluster_agent" "foo" {
+ id = (known after apply)
+ instance_id = "prom-jh0zntj2"

+ agents {
+ cluster_id = "cls-1uary7z2"
+ cluster_name = (known after apply)
+ cluster_type = "eks"
+ enable_external = false
+ region = "ap-mumbai"
+ status = (known after apply)
}
}

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

tencentcloud_monitor_tmp_tke_cluster_agent.foo: Creating...
实例内容。。。

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

查看 Prometheus 实例状态

登录 腾讯云可观测平台,在左侧导航栏,选择 prometheus 监控 ,可在 prometheus 实例列表中看到存在的实例。

删除 Prometheus 实例集成中心组件集成

销毁资源,执行命令如下:
terraform destroy
预期输出信息:
tencentcloud_monitor_tmp_instance.foo: Refreshing state... [id=prom-8dyb6iny]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
- destroy

Terraform will perform the following actions:
实例内容。。。

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.

Enter a value: yes

tencentcloud_monitor_tmp_instance.foo: Destroying... [id=prom-8dyb6iny]
tencentcloud_monitor_tmp_instance.foo: Destruction complete after 6s

Destroy complete! Resources: 1 destroyed.
注意:
当出现 Destroy complete! Resources: (存在的实例个数) destroyed. 表示您已删除该实例。


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈