이 문서에서는 운영 에이전트를 자동으로 설치하는 Batch 작업을 만들고 실행하는 방법을 설명합니다. 운영 에이전트를 설치하여 Cloud Monitoring에서 작업 리소스의 성능에 대한 추가 측정항목을 제공합니다. 작업에 리소스 성능 측정항목을 사용하는 방법은 측정항목을 확인하여 작업 리소스를 모니터링하고 최적화를 참조하세요.
예를 들어 운영 에이전트를 자동으로 설치하는 작업에는 다음과 비슷한 JSON 구성 파일이 있을 수 있습니다.
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3,}],"allocationPolicy":{"instances":[{"installOpsAgent":true}]},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(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,["This 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\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\nOps 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\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- 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)."]]