Coletar mais métricas de recursos usando o Agente de operações
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Neste documento, descrevemos como criar e executar um job do Batch que instala automaticamente o Agente de operações. Instale o Agente de operações para fornecer métricas adicionais no Cloud Monitoring sobre o desempenho dos recursos de um job. Para saber mais sobre como usar métricas de desempenho de recursos em um job, consulte Monitorar e otimizar recursos de jobs visualizando métricas.
A menos que você esteja usando a configuração padrão para
a conta de serviço do job,
verifique se ela tem as permissões necessárias.
Para garantir que a conta de serviço do job tenha as permissões
necessárias para gravar métricas do agente de operações no Monitoring,
peça ao administrador para conceder à conta de serviço do job os
seguintes papéis do IAM:
Se o job usar uma configuração de rede não padrão ou o
VPC Service Controls, verifique se ele atende aos
requisitos de acesso
do Agente de operações. Para mais informações, consulte
VMs sem acesso a pacotes remotos
na documentação do Google Cloud Observability.
Verifique se o job não instala um agente legado do Cloud Logging ou do
Cloud Monitoring, por exemplo, usando uma imagem personalizada ou
um modelo de instância.
Para mais informações sobre os recursos e requisitos do agente de operações,
consulte a visão geral do agente de operações
na documentação do Google Cloud Observability.
Criar um job que instale automaticamente o agente de operações
Use a Google Cloud CLI ou a API REST para criar um job que inclua o campo installOpsAgent definido como true no campo allocationPolicy.instances no corpo principal do arquivo JSON:
Por exemplo, um job que instala automaticamente o Agente de operações pode ter um arquivo de configuração JSON semelhante a este:
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3,}],"allocationPolicy":{"instances":[{"installOpsAgent":true}]},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
Depois que as VMs do job começarem a ser executadas, você poderá ver as métricas do Agente de operações da mesma forma que
qualquer outra métrica de recurso. Para mais informações, consulte
Monitorar e otimizar recursos de jobs visualizando métricas.
A seguir
Se você tiver problemas para criar ou executar um job, consulte
Solução de problemas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)."]]