tencent cloud

TencentCloud Managed Service for Prometheus

Product Introduction
Overview
Strengths
Use Cases
Concepts
Use Limits
Features
Service Regions
Purchase Guide
Billing Overview
Pay-as-You-Go (Postpaid)
Free Trial Introduction
Managed Collector Billing Introduction
Archive Storage Billing Introduction
Purchase Methods
Payment Overdue
Getting Started
Integration Guide
Scrape Configuration Description
Custom Monitoring
EMR Integration
Java Application Integration
Go Application Integration
Exporter Integration
Nacos Integration
Common Exporter
Health Check
Instructions for Installing Components in the TKE Cluster
Cloud Monitoring
Non-Tencent Cloud Host Monitoring
Read Cloud-Hosted Prometheus Instance Data via Remote Read
Agent Self-Service Access
Pushgateway Integration
Security Group Open Description
Operation Guide
Instance
TKE
Integration Center
Data Multi-Write
Recording Rule
Instance Diagnosis
Archive Storage
Alerting Rule
Tag
Access Control
Grafana
API Guide
TKE Metrics
Resource Usage and Billing Overview
Practical Tutorial
Migration from Self-Built Prometheus
Custom Integration with CVM
TKE Monitoring
Enabling Public Network Access for TKE Serverless Cluster
Connecting TMP to Local Grafana
Enabling Public Network Access for Prometheus Instances
Configuring a Public Network Address for a Prometheus Instance
Terraform
Terraform Overview
Managing Prometheus Instances Using Terraform
Managing the Integration Center of Prometheus Instances Using Terraform
Collecting Container Monitoring Data Using Terraform
Configuring Alarm Policies Using Terraform
FAQs
Basic Questions
Integration with TKE Cluster
Product Consulting
Use and Technology
Cloud Monitor FAQs
Service Level Agreement
TMP Policy
Privacy Policy
Data Processing And Security Agreement
DocumentationTencentCloud Managed Service for PrometheusTerraformCollecting Container Monitoring Data Using Terraform

Collecting Container Monitoring Data Using Terraform

PDF
Focus Mode
Font Size
Last updated: 2024-10-09 10:10:11

Prerequisites

Installing Terraform

For detailed instructions on installing Terraform, see Installing Terraform.
Note:
The installed version of Terraform must not be below v1.6.3. You can verify the version of Terraform installed by using the command terraform --version.

Configuring Tencent Cloud Account Information

Before using Terraform for the first time, go to API Key to apply for a SecretID and SecretKey of the security credentials. If you already have valid credentials, skip this step.
1. Log in to the CAM Console and choose Access Key > API Keys from the left sidebar.
2. On the API Keys page, click Create Key to create a SecretId/SecretKey pair.

There are two methods for configuring Tencent Cloud account information:

Authentication by Static Credentials
Create a provider.tf file in the user directory with the following content. Replace my-secret-id and my-secret-key with your SecretId and SecretKey, respectively.
provider "tencentcloud" {
secret_id = "my-secret-id"
secret_key = "my-secret-key"
}
Authentication by Environment Variables
Set the computer variables or cloud environment variables by running the command below. Replace YOUR_SECRET_ID and YOUR_SECRET_KEY with your SecretId and SecretKey, respectively.
export TENCENTCLOUD_SECRET_ID=YOUR_SECRET_ID
export TENCENTCLOUD_SECRET_KEY=YOUR_SECRET_KEY

Adding Container Monitoring Data Collection to Prometheus Instances

1. Create a new Terraform configuration file: Create a new directory and a file named main.tf in the directory. The following shows the configuration:
#Specifying Provider Configuration Information

terraform { required_providers { tencentcloud = { source = "tencentcloudstack/tencentcloud" } } }
#Prometheus Managing Cloud Monitoring Integration

#Prometheus Management of Container Clusters (Collection Containers)

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 of the cluster that needs to be associated
enable_external = false
}
}
Note:
To create the Integration Center component of a Prometheus instance, the corresponding fields must be configured as follows:
instance_id: (Required, string, ForceNew) Instance ID.
agents: (Required, list) List of agents.
cluster_id: (Required, string) Identifier for the cluster ID.
region: (Required, string) Region restrictions.
enable_external: (Required, Bool) Whether to enable public network CLB.
cluster_type: (Required, string) Cluster type.
For more details about parameters, see Detailed Parameters. You can also see Tencent Cloud Provider on Github and Terraform Tencent Cloud Provider.
2. To initialize the Terraform runtime environment, run the following command:
terraform init
Expected output:
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. To generate a resource plan, run the following command:
terraform plan
Expected output:
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. To create component integration of the Integration Center, run the following command:
terraform apply
Expected output:
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...
Instance content...

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

Viewing the Status of the Prometheus Instance

Log in to the TCOP, and choose Managed Service for Prometheus from the left-hand navigation bar. Existing instances are displayed in the Prometheus instance list.

Deleting the Component Integration in the Prometheus Instance Integration Center

To terminate the resources, run the following command:
terraform destroy
Expected output:
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:
Instance content...

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.
Note:
If Destroy complete! Resources: (numbers of existing instances) destroyed. is displayed, the instance has been deleted.


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback