監視効率を高め、関連する管理を簡素化するために、Managed Service for Prometheus では、Terraform を使用して監視ジョブを作成し、監視対象オブジェクト、キャプチャされたメトリックの保存パス、およびメトリックのキャプチャ間隔に関するパラメータを設定できます。その後、Container Service for Kubernetes (ACK) 環境インスタンスまたは Elastic Compute Service (ECS) 環境インスタンスにジョブをデプロイして、自動監視を実装できます。
前提条件
Container Service for Kubernetes (ACK) 環境インスタンスが作成されていること。詳細については、Terraform を使用して環境インスタンスを管理する を参照してください。
制限事項
ACK 環境インスタンスと ECS 環境インスタンスのみがサポートされています。
環境インスタンスのカスタムジョブを作成する
作業ディレクトリを作成し、作業ディレクトリに
main.tf
という名前の設定ファイルを作成して、カスタムジョブリソースを設定します。provider "alicloud" { // access_key = "************" // secret_key = "************" // region = "cn-beijing" } // 環境インスタンスのカスタムジョブ設定。 resource "alicloud_arms_env_custom_job" "my-custom-job1" { env_custom_job_name = "カスタムジョブの名前。例: my-custom-job1。" environment_id = "ACK または ECS 環境インスタンスの ID。例: env-xxxxx。" config_yaml = <<-EOT scrape_configs: - job_name: job-demo1 honor_timestamps: false honor_labels: false scrape_interval: 30s scheme: http metrics_path: /metric static_configs: - targets: - 127.0.0.1:9090 - job_name: job-demo2 honor_timestamps: false honor_labels: false scrape_interval: 30s scheme: http metrics_path: /metric static_configs: - targets: - 127.0.0.1:9090 http_sd_configs: - url: 127.0.0.1:9090 refresh_interval: 30s EOT }
次のコマンドを実行して、Terraform のランタイム環境を初期化します。
terraform init
期待される出力:
Initializing the backend... Initializing provider plugins... - Checking for available provider plugins... - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.90.1... ... 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.
次のコマンドを実行して、実行プランを作成します。
terraform plan
期待される出力:
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: # alicloud_arms_env_custom_job.myCustomJob1 will be created + resource "alicloud_arms_env_custom_job" "myCustomJob1" { env_custom_job_name = "myCustomJob1" environment_id = "xxx" config_yaml = .... } Plan: 1 to add, 0 to change, 0 to destroy.
次のコマンドを実行して、カスタムジョブを作成します。
terraform apply
期待される出力:
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: # alicloud_arms_env_custom_job.myCustomJob1 will be created + resource "alicloud_arms_env_custom_job" "myCustomJob1" { env_custom_job_name = "myCustomJob1" environment_id = "xxx" config_yaml = .... } 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
Enter a value
が返されたら、yes
と入力します。現在の環境インスタンスのカスタムジョブが作成されます。Managed Service for Prometheus console にログインします。
左側のナビゲーションペインで、統合管理 をクリックします。統合管理 ページで、環境インスタンスの名前をクリックします。
環境インスタンスの詳細ページで、メトリックスクレイピング タブをクリックし、カスタム収集 タブをクリックして、カスタムジョブが作成されているかどうかを確認します。
ACK 環境インスタンスからカスタムジョブを削除する
次のコマンドを実行して、Terraform を使用して作成された ACK マネージドクラスタを削除できます。
terraform 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 ... Destroy complete! Resources: 1 destroyed.
Enter a value
が返されたら、yes
と入力します。Managed Service for Prometheus console にログインします。
左側のナビゲーションペインで、統合管理 をクリックします。統合管理 ページで、環境インスタンスの名前をクリックします。
環境インスタンスの詳細ページで、メトリックスクレイピング タブをクリックし、カスタム収集 タブをクリックして、カスタムジョブが削除されているかどうかを確認します。