Zusätzliche Ressourcenmesswerte mit dem Ops-Agent erfassen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Dokument wird beschrieben, wie Sie einen Batch-Job erstellen und ausführen, mit dem der Ops-Agent automatisch installiert wird. Installieren Sie den Ops-Agent, um zusätzliche Messwerte in Cloud Monitoring zur Leistung der Ressourcen eines Jobs zu erhalten. Weitere Informationen zur Verwendung von Ressourcenleistungsmesswerten für einen Job finden Sie unter Jobressourcen mit Messwerten überwachen und optimieren.
Bitten Sie Ihren Administrator, Ihnen die folgenden IAM-Rollen zuzuweisen, um die Berechtigungen zu erhalten, die Sie zum Erstellen eines Jobs benötigen:
Sofern Sie nicht die Standardkonfiguration für das Dienstkonto des Jobs verwenden, müssen Sie dafür sorgen, dass es die erforderlichen Berechtigungen hat.
Damit das Dienstkonto des Jobs die erforderlichen Berechtigungen zum Schreiben von Ops-Agent-Messwerten in Monitoring hat, bitten Sie Ihren Administrator, dem Dienstkonto des Jobs die folgenden IAM-Rollen zu erteilen:
Wenn für Ihren Job eine nicht standardmäßige Netzwerkkonfiguration oder VPC Service Controls verwendet werden, muss der Job die Zugriffsanforderungen für den Ops-Agenten erfüllen. Weitere Informationen finden Sie in der Google Cloud Observability-Dokumentation unter VMs ohne Remote-Paketzugriff.
Achten Sie darauf, dass durch den Job kein Legacy-Cloud Logging-Agent oder Cloud Monitoring-Agent installiert wird, z. B. über ein benutzerdefiniertes Image oder eine Instanzvorlage.
Weitere Informationen zu den Funktionen und Anforderungen des Ops-Agents finden Sie in der Google Cloud Observability-Dokumentation unter Ops-Agent – Übersicht.
Job erstellen, mit dem der Ops-Agent automatisch installiert wird
Verwenden Sie die Google Cloud CLI oder die REST API, um einen Job zu erstellen, der das Feld installOpsAgent enthält, das im Feld allocationPolicy.instances im Hauptteil der JSON-Datei auf true festgelegt ist:
Ein Job, der den Ops-Agent automatisch installiert, kann beispielsweise eine JSON-Konfigurationsdatei haben, die so ähnlich aussieht wie die folgende:
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3,}],"allocationPolicy":{"instances":[{"installOpsAgent":true}]},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-02 (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)."]]