Mengumpulkan metrik resource tambahan menggunakan Agen Operasional
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dokumen ini menjelaskan cara membuat dan menjalankan tugas Batch yang
menginstal Ops Agent secara otomatis. Instal Agen Operasional untuk memberikan metrik tambahan di Cloud Monitoring tentang performa resource tugas. Untuk mempelajari lebih lanjut cara menggunakan metrik performa resource untuk
tugas, lihat
Memantau dan mengoptimalkan resource tugas dengan melihat metrik.
Anda mungkin juga bisa mendapatkan
izin yang diperlukan melalui peran
khusus atau peran
bawaan lainnya.
Kecuali jika Anda menggunakan konfigurasi default untuk
akun layanan tugas,
pastikan akun layanan tersebut memiliki izin yang diperlukan.
Untuk memastikan bahwa akun layanan tugas memiliki izin yang diperlukan
untuk menulis metrik Agen Operasi ke Monitoring,
minta administrator untuk memberi akun layanan tugas
peran IAM berikut:
Jika tugas Anda menggunakan konfigurasi jaringan non-default atau menggunakan
Kontrol Layanan VPC, pastikan tugas memenuhi
persyaratan akses
untuk Ops Agent. Untuk mengetahui informasi selengkapnya, lihat
VM tanpa akses paket jarak jauh
dalam dokumentasi Google Cloud Observability.
Pastikan tugas tidak menginstal agen Cloud Logging atau agen Cloud Monitoring lama—misalnya, melalui image kustom atau template instance.
Untuk mengetahui informasi selengkapnya tentang fitur dan persyaratan Agen Operasi, lihat Ringkasan Agen Operasi dalam dokumentasi Google Cloud Observability.
Membuat tugas yang menginstal Agen Operasional secara otomatis
Gunakan Google Cloud CLI atau REST API untuk
membuat tugas yang
mencakup
kolom installOpsAgent
yang ditetapkan ke true di kolom allocationPolicy.instances di isi utama dalam
file JSON:
Misalnya, tugas yang otomatis menginstal Agen Operasi dapat memiliki file konfigurasi JSON yang mirip dengan berikut:
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3,}],"allocationPolicy":{"instances":[{"installOpsAgent":true}]},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-12 UTC."],[[["\u003cp\u003eThis guide outlines how to create and run a Batch job that automatically installs the Ops Agent, which provides enhanced resource performance metrics in Cloud Monitoring.\u003c/p\u003e\n"],["\u003cp\u003eTo enable the installation of the Ops Agent, the \u003ccode\u003einstallOpsAgent\u003c/code\u003e field must be set to \u003ccode\u003etrue\u003c/code\u003e within the \u003ccode\u003eallocationPolicy.instances\u003c/code\u003e section of the job configuration file when creating the job.\u003c/p\u003e\n"],["\u003cp\u003eEnsure that the job's service account has the necessary IAM roles, specifically Monitoring Metric Writer and Logs Writer, to allow it to write Ops Agent metrics to Monitoring.\u003c/p\u003e\n"],["\u003cp\u003eJobs using the Ops Agent must adhere to specific requirements, including using a supported operating system and ensuring compliance with network and access prerequisites, as well as not installing legacy Cloud Logging or Cloud Monitoring agents.\u003c/p\u003e\n"],["\u003cp\u003eThe Ops Agent is a separate feature from Batch and incurs its own costs, and further details on pricing can be found in the Google Cloud Observability documentation.\u003c/p\u003e\n"]]],[],null,["# Collect additional resource metrics using the Ops Agent\n\nThis document describes how to create and run a Batch job that\nautomatically installs the Ops Agent. Install the Ops Agent to provide\nadditional metrics in Cloud Monitoring about the performance of a job's\nresources. To learn more about using resource performance metrics for\na job, see\n[Monitor and optimize job resources by viewing metrics](/batch/docs/monitor-job-resources-using-metrics).\n| **Note:** The Ops Agent feature is not part of Batch and has its own pricing. For more information, see [Ops Agent pricing](/stackdriver/docs/solutions/agents/ops-agent#pricing) in the Google Cloud Observability documentation.\n\nBefore you begin\n----------------\n\n1. If you haven't used Batch before, review [Get started with Batch](/batch/docs/get-started) and enable Batch by completing the [prerequisites for projects and users](/batch/docs/get-started#prerequisites).\n2. If your project hasn't already, enable the Cloud Monitoring and Cloud Logging APIs:\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com,logging.googleapis.com)\n3.\n\n To get the permissions that\n you need to create a job,\n\n ask your administrator to grant you the\n following IAM roles:\n\n - To create a job:\n - [Batch Job Editor](/iam/docs/roles-permissions/batch#batch.jobsEditor) (`roles/batch.jobsEditor`) on the project\n - [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the [job's service account](/batch/docs/get-started#job-service-account), which by default is the [default Compute Engine service account](/compute/docs/access/service-accounts#default_service_account)\n - To view logs: [Logs Viewer](/iam/docs/roles-permissions/logging#logging.viewer) (`roles/logging.viewer`) on the project\n\n\n For more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\n You might also be able to get\n the required permissions through [custom\n roles](/iam/docs/creating-custom-roles) or other [predefined\n roles](/iam/docs/roles-overview#predefined).\n4. Unless you are using the default configuration for\n [the job's service account](/batch/docs/get-started#job-service-account),\n ensure that it has the necessary permissions.\n\n\n To ensure that the job's service account has the necessary\n permissions to write Ops Agent metrics to Monitoring,\n\n ask your administrator to grant the job's service account the\n following IAM roles:\n\n | **Important:** You must grant these roles to the job's service account, *not* to your user account. Failure to grant the roles to the correct principal might result in permission errors.\n - [Monitoring Metric Writer](/iam/docs/roles-permissions/monitoring#monitoring.metricWriter) (`roles/monitoring.metricWriter`) on the project\n - [Logs Writer](/iam/docs/roles-permissions/logging#logging.logWriter) (`roles/logging.logWriter`) on the project\n\n\n5. Ensure that your planned job configuration meets the [Ops Agent requirements](#requirements).\n\n\u003cbr /\u003e\n\n### Ops Agent requirements\n\nTo create and run a job that uses the Ops Agent, your job must comply with\nall the following requirements:\n\n- Ensure that the job's VMs use an\n [operating system (OS) that the Ops Agent supports](/stackdriver/docs/solutions/agents/ops-agent#supported_operating_systems).\n For more information about the VM OS image for a job, see\n [Overview of the OS environment for a job's VMs](/batch/docs/vm-os-environment-overview).\n\n- If your job uses a non-default networking configuration or uses\n VPC Service Controls, ensure that the job meets the\n [access requirements](/stackdriver/docs/solutions/agents/ops-agent#access)\n for the Ops Agent. For more information, see\n [VMs without remote package access](/stackdriver/docs/solutions/agents/ops-agent/installation#remote_package_access)\n in the Google Cloud Observability documentation.\n\n- Ensure that the job doesn't install a legacy Cloud Logging agent or\n Cloud Monitoring agent---for example, through a custom image or\n instance template.\n\nFor more information about the features and requirements of the Ops Agent,\nsee [Ops Agent overview](/stackdriver/docs/solutions/agents/ops-agent)\nin the Google Cloud Observability documentation.\n\nCreate a job that automatically installs the Ops Agent\n------------------------------------------------------\n\nUse the Google Cloud CLI or REST API to\n[create a job](/batch/docs/create-run-basic-job#create-basic-job) that\nincludes the\n[`installOpsAgent` field](/batch/docs/reference/rest/v1/projects.locations.jobs#InstancePolicyOrTemplate.FIELDS.install_ops_agent)\nset to `true` in the `allocationPolicy.instances` field in the main body in the\nJSON file: \n\n \"allocationPolicy\": {\n \"instances\": [\n {\n \"installOpsAgent\": true\n }\n ]\n }\n\nFor example, a job that automatically installs the Ops Agent can have a JSON\nconfiguration file that is similar to the following: \n\n {\n \"taskGroups\": [\n {\n \"taskSpec\": {\n \"runnables\": [\n {\n \"script\": {\n \"text\": \"echo Hello World! This is task $BATCH_TASK_INDEX.\"\n }\n }\n ]\n },\n \"taskCount\": 3,\n }\n ],\n \"allocationPolicy\": {\n \"instances\": [\n {\n \"installOpsAgent\": true\n }\n ]\n },\n \"logsPolicy\": {\n \"destination\": \"CLOUD_LOGGING\"\n }\n }\n\nAfter the job's VMs start running, you can see the Ops Agent metrics the same as\nany other resource metric. For more information, see\n[Monitor and optimize job resources by viewing metrics](/batch/docs/monitor-job-resources-using-metrics).\n\nWhat's next\n-----------\n\n- If you have issues creating or running a job, see [Troubleshooting](/batch/docs/troubleshooting).\n- [View jobs and tasks](/batch/docs/view-jobs-tasks).\n- Learn about more [job creation options](/batch/docs/create-run-job#job-creation-options)."]]