Jobressourcen anhand von Messwerten überwachen und optimieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Dokument wird beschrieben, wie Sie die Ressourcen für einen Batch-Job überwachen und optimieren können, indem Sie Messwerte in Cloud Monitoring ansehen.
Weitere Informationen zu den Ressourcen, auf denen ein Job ausgeführt wird, finden Sie unter Jobressourcen.
Für jeden Job stellt Monitoring grundlegende Messwerte wie CPU-Auslastung und Netzwerk-Traffic bereit. Einige Messwerte, z. B. für die Speicher- und Prozessauslastung, können jedoch nur erfasst werden, wenn der Ops-Agent durch einen Job installiert wird.
Mit Messwerten für die Ressourcen eines Jobs können Sie die Leistung und Auslastung der einzelnen Ressourcen bewerten. Anhand dieser Informationen können Sie Verbesserungen für zukünftige Iterationen des Jobs vornehmen. Sie können beispielsweise nicht genutzte Ressourcen entfernen, um die Kosten zu optimieren, oder überlastete Ressourcen verbessern oder erhöhen, um die Leistung zu steigern.
Bitten Sie Ihren Administrator, Ihnen die IAM-Rolle Monitoring Metric Viewer (roles/monitoring.metricViewer) für das Projekt zuzuweisen, um die Berechtigungen zu erhalten, die Sie zum Aufrufen von Observability-Messwerten benötigen.
Weitere Informationen zum Zuweisen von Rollen finden Sie unter Zugriff auf Projekte, Ordner und Organisationen verwalten.
In der Compute Engine-Dokumentation finden Sie unter VMs beobachten und überwachen relevante konzeptionelle Informationen zu VM-Messwerten. Für das Aufrufen von VM-Messwerten für Batch-Jobs werden jedoch andere Methoden empfohlen. In der Compute Engine-Dokumentation wird beschrieben, wie Sie Messwerte mit den vordefinierten Monitoring-Dashboards für Compute Engine oder auf den Compute Engine-Seiten in der Google Cloud -Konsole aufrufen.
Wichtig ist jedoch, dass diese Methoden keine Informationen zu gelöschten VMs anzeigen. Verwenden Sie diese Methoden daher nur, wenn Sie Messwerte für Batch-Jobs während der Ausführung ansehen möchten.
In diesem Abschnitt wird beschrieben, wie Sie mit Metrics Explorer-Diagrammen Messwerte für laufende und abgeschlossene Batch-Jobs aufrufen.
Diagramme sind nur temporär verfügbar, sofern Sie sie nicht in benutzerdefinierten Dashboards speichern.
So erstellen Sie ein Diagramm, in dem ein oder mehrere Messwerte dargestellt werden:
Ohne Filter enthält jeder VM-Messwert in einem Diagramm Daten von allen VMs in Ihrem Projekt. Optional können Sie das Diagramm filtern, sodass nur Messwerte aus allen oder bestimmten Batch-Jobs enthalten sind. Fügen Sie dazu den folgenden Filter hinzu:
Ressourcengruppen zum Filtern von Messwerten erstellen
Sie können Ressourcengruppen als benutzerdefinierte Filter für Metrics Explorer-Diagramme verwenden.
So erstellen Sie eine Ressourcengruppe für alle oder bestimmte Batch-Jobs in Ihrem Projekt:
Wählen Sie ein Label aus, das als Mitgliedschaftskriterium verwendet werden soll, anhand dessen Sie Jobs in die Gruppe aufnehmen möchten:
Alle Batch-Jobs:Verwenden Sie das vordefinierte Label batch-node, das automatisch auf alle Ressourcen für alle Batch-Jobs angewendet wird und einen Nullwert hat.
Bestimmte Batch-Jobs:Verwenden Sie ein Label, das nur für bestimmte Batch-Jobs auf die Ressourcen angewendet wird.
Wenn Sie beispielsweise eine Gruppe basierend auf vollständigen oder teilweisen Jobnamen erstellen möchten, verwenden Sie den vordefinierten Labelnamen batch-job-id mit einem bestimmten Wert.
Das Label batch-job-id wird automatisch auf alle Ressourcen für alle Batchjobs angewendet und mit dem Jobnamen definiert.
Wenn Sie ein benutzerdefiniertes Label verwenden, müssen Sie es beim Erstellen der Batch-Jobs auf alle Ressourcen anwenden, die in der Gruppe enthalten sein sollen.
Achten Sie darauf, dass Ihr Projekt mindestens einen Job mit dem ausgewählten Label enthält und dass sich dieser Job im Status RUNNING befindet. Andernfalls wird dieses Label nicht als Option angezeigt, wenn Sie versuchen, die Ressourcengruppe zu erstellen.
Ressourcengruppe erstellen
Gehen Sie so vor, wenn Sie die Kriterien für die Aufnahme in ein Segment angeben:
Legen Sie für TypTag fest.
Legen Sie für das Feld Tag den Namen des ausgewählten Labels fest. Legen Sie dann die folgenden Felder basierend auf den Labelwerten fest, die die Gruppe enthalten soll.
Wenn diese Gruppe beispielsweise alle Batch-Jobs enthalten soll, legen Sie Tag auf batch-node und Operator auf Exists fest.
Alternativ können Sie festlegen, dass diese Gruppe Batch-Jobs mit Namen enthält, die mit test beginnen. Setzen Sie dazu Tag auf batch-job-id, Operator auf Beginnt mit und Wert auf test.
Nächste Schritte
Weitere Informationen zu Messwerten für Jobressourcen:
[[["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 explains how to monitor Batch job resources using Cloud Monitoring, focusing on metrics like CPU utilization and network traffic.\u003c/p\u003e\n"],["\u003cp\u003eInstalling the Ops Agent is required to collect advanced metrics such as memory and process utilization, providing a more comprehensive view of job performance.\u003c/p\u003e\n"],["\u003cp\u003eMetrics Explorer charts can be used to view metrics for both running and completed Batch jobs, but these charts are temporary unless saved to a custom dashboard.\u003c/p\u003e\n"],["\u003cp\u003eResource groups can be created to filter Metrics Explorer charts, allowing users to view metrics for all or specific Batch jobs by using predefined or custom labels.\u003c/p\u003e\n"],["\u003cp\u003eYou must have the Monitoring Metric Viewer role to view the observability metrics, and be aware that metrics are automatically deleted after the monitoring retention periods.\u003c/p\u003e\n"]]],[],null,["This document describes how to monitor and try to optimize the resources for a\nBatch job by viewing metrics in Cloud Monitoring.\nTo learn more about the resources that a job runs on, see\n[Job resources](/batch/docs/create-run-job#resources).\n\nFor any job, Monitoring provides basic metrics such as CPU\nutilization and network traffic. However, some metrics, such as memory and\nprocess utilization, can only be collected if a job installs the Ops Agent.\nMetrics for a job's resources help you evaluate the performance and utilization\nof each resource. This information can help you identify improvements for any\nfuture iterations of the job. For example, you might remove unutilized resources\nto help optimize costs, or you might improve or increase strained resources to\nhelp enhance performance.\n| **Note:** Monitoring and the Ops Agent feature are not part of Batch and have their own pricing. For more information, see [Monitoring pricing](/stackdriver/pricing#monitoring-pricing-summary) and [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. Optional: To collect additional metrics for a job, [create and run\n a job that automatically installs the Ops Agent.](/batch/docs/create-run-job-ops-agent)\n3. If your project hasn't already, enable the Monitoring API:\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com)\n4.\n\n To get the permissions that\n you need to view observability metrics,\n\n ask your administrator to grant you the\n\n\n [Monitoring Metric Viewer](/iam/docs/roles-permissions/monitoring#monitoring.metricViewer) (`roles/monitoring.metricViewer`)\n IAM role 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).\n\n\u003cbr /\u003e\n\nView metrics for job resources **Important:** You cannot view metrics after they are deleted, which happens automatically after the [Monitoring retention periods](/monitoring/quotas#data_retention_policy). If you need to retain metrics for a longer period, [export Monitoring metrics to BigQuery](/architecture/monitoring-metric-export).\n\n[Observe and monitor VMs](/compute/docs/instances/observe-monitor-vms) in\nthe Compute Engine documentation provides relevant conceptual information\nabout VM metrics; however, different methods are recommended for viewing\nVM metrics for Batch jobs. Specifically, the\nCompute Engine documentation explains how to view metrics by using the\npredefined Monitoring dashboards for Compute Engine or\nCompute Engine pages in the Google Cloud console.\nBut, importantly, those methods don't display information about VMs that have\nbeen deleted. As a result, don't use those methods unless you only want to view\nmetrics for Batch jobs while they are running.\n\nView metrics for running and finished Batch jobs by\nusing Metrics Explorer charts as explained in this section.\nNotably, charts are temporary unless you save\nthem to custom dashboards.\n| **Tip:** To see if your project already has a custom dashboard that you can use instead of creating a new chart, [view custom dashboards](/monitoring/charts/dashboards#view-dashboard).\n\nTo create a chart for viewing one or more metrics, do the following:\n\n1. Optional: If you plan to save the chart, [identify or create a custom dashboard](/monitoring/charts/dashboards) for the chart.\n2. [Create a Metrics Explorer chart for one or more metrics](/monitoring/charts/metrics-explorer).\n\n Without filters, each VM metric in a chart includes data from all the VMs in\n your project. Optionally, if you want to filter the chart to only include\n metrics from all or specific Batch jobs, add the following\n filter: \n\n group=\u003cvar translate=\"no\"\u003eRESOURCE_GROUP_NAME\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eRESOURCE_GROUP_NAME\u003c/var\u003e with the name of a\n resource group for Batch jobs. For more information, see\n [Create resource groups to filter metrics](#create-group-filter) in this\n document.\n\nCreate resource groups to filter metrics\n\nYou can use [resource groups](/monitoring/groups) as customizable filters\nfor Metrics Explorer charts.\nTo create a resource group for all or specific Batch jobs in\nyour project, do the following:\n\n1. Select a [label](/batch/docs/organize-resources-using-labels) to use\n as the membership criteria based on which jobs you want to include in the\n group:\n\n - **All Batch jobs:** Use the predefined `batch-node` label, which is automatically applied to all the resources for all Batch jobs and has a null value.\n - **Specific Batch jobs:** Use a label that is applied to\n the resources only for specific Batch jobs.\n\n For example, if you want to create a group based on full or partial job\n names, use the predefined `batch-job-id` label name with a specific value.\n The `batch-job-id` label is automatically applied to all the resources\n for all Batch jobs and defined with the job name.\n\n Alternatively, if you use a custom label, you must apply the\n custom label to all the resources of the Batch jobs that\n you want to be included in the group when you create the jobs.\n2. Ensure that your project has at least one job with your selected label and\n that this job is in the `RUNNING` state. Otherwise, this label won't\n appear as an option when you try to create the resource group.\n\n3. [Create a resource group](/monitoring/groups).\n When you are specifying the membership criteria, do the following:\n\n 1. Set the **Type** to **Tag**.\n 2. Set the **Tag** field to the name of your selected label. Then, set the\n following fields based on the label values that you want the group to\n include.\n\n For example, if you want this group to include all Batch\n jobs, set **Tag** to `batch-node`, and set **Operator** to **Exists** .\n Alternatively, you want this group to include Batch jobs\n with names that start with `test`, set **Tag** to `batch-job-id`,\n set **Operator** to **Starts with** , and set **Value** to `test`.\n\nWhat's next\n\n- Learn more about job resource metrics:\n - [Collect additional resource metrics using the Ops Agent](/batch/docs/create-run-job-ops-agent).\n - [Create and manage custom Monitoring dashboards](/monitoring/charts/dashboards).\n - [Monitor GPUs](/compute/docs/gpus/monitor-gpus).\n- Learn about other methods to monitor and optimize Batch jobs:\n - [Monitor job status using Pub/Sub notifications and BigQuery](/batch/docs/monitor-jobs-using-notifications).\n - [Colocate VMs to reduce latency](/batch/docs/create-run-job-placement-policy).\n - Learn about more [job creation options](/batch/docs/create-run-job#job-creation-options)."]]