Raccogli metriche aggiuntive sulle risorse utilizzando Ops Agent
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questo documento descrive come creare ed eseguire un job Batch che
installa automaticamente l'Ops Agent. Installa Ops Agent per fornire
metriche aggiuntive in Cloud Monitoring sulle prestazioni delle
risorse di un job. Per scoprire di più sull'utilizzo delle metriche sul rendimento delle risorse per un job, consulta
Monitorare e ottimizzare le risorse dei job visualizzando le metriche.
A meno che tu non stia utilizzando la configurazione predefinita per
il service account del job,
assicurati che disponga delle autorizzazioni necessarie.
Per assicurarti che il account di servizio del job disponga delle autorizzazioni
necessarie per scrivere le metriche dell'Ops Agent in Monitoring,
chiedi all'amministratore di concedere al account di servizio del job i
seguenti ruoli IAM:
Se il tuo job utilizza una configurazione di rete non predefinita o i Controlli di servizio VPC, assicurati che soddisfi i requisiti di accesso per l'Ops Agent. Per ulteriori informazioni, consulta
VM senza accesso remoto ai pacchetti
nella documentazione di Google Cloud Observability.
Assicurati che il job non installi un agente Cloud Logging legacy o
Cloud Monitoring, ad esempio tramite un'immagine personalizzata o
un modello di istanza.
Per saperne di più sulle funzionalità e sui requisiti di Ops Agent,
consulta la panoramica di Ops Agent
nella documentazione di Google Cloud Observability.
Crea un job che installi automaticamente l'Ops Agent
Ad esempio, un job che installa automaticamente l'Ops Agent può avere un file di configurazione JSON simile al seguente:
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3,}],"allocationPolicy":{"instances":[{"installOpsAgent":true}]},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 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)."]]