您可以对应用进行插桩,以便它收集特定于应用的信息。有几种开源插桩框架可让您从应用收集指标、日志和跟踪记录,并将这些数据发送给任何供应商,包括 Google Cloud。如需对应用进行插桩,我们建议您使用不受制于供应商的开源插桩框架(例如 OpenTelemetry),而不是使用供应商和产品特有的 API 或客户端库。
Google Cloud 支持根据日志数据创建指标。这些基于日志的指标用于记录写入 Cloud Logging 的日志的数字信息。某些指标(例如Google Cloud 项目收到的日志条目总数)会自动从日志中派生出来。您还可以定义基于日志的指标。例如,您可以创建一个指标,对部署到 App Engine 的应用的 404 Not Found 错误数行计数。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-05。"],[],[],null,["# Collect metrics overview\n\nThis document describes what metrics are automatically available to you\nwhen you use Google Cloud services.\nIt also describes different approaches that\nyou can use to collect additional information about the performance of\nyour services.\n\nYou can monitor the (numeric) metric data stored in your Google Cloud project by\ncreating [alerting policies](/monitoring/alerts). These policies notify you when\nthe data monitored by the policy meets criteria that you define.\nYou can also visualize your\nmetric data by creating [charts](/monitoring/charts/metrics-explorer) and\n[dashboards](/monitoring/dashboards).\n\nThe metrics scope of a Google Cloud project determines the time-series data\nthat can be charted or monitored by the Google Cloud project. By default, the\nmetrics scope limits the project to the time-series data stored by\nproject. You can configure a metrics scope to include time-series data\nthat is stored by other projects.\nFor conceptual information and references to\nconfiguration documents, see [Metrics scopes overview](/monitoring/settings).\n\nMetrics from Google Cloud services\n----------------------------------\n\nSystem metrics generated by Google Cloud services are automatically\ncollected and stored by Cloud Monitoring. These metrics provide\ninformation about how the service is operating. For example,\nCompute Engine reports over 25 unique metrics for each\nvirtual machine (VM) instance.\n\nFor a complete list of available system metrics,\nsee [Google Cloud metrics](/monitoring/api/metrics_gcp).\n\nMetrics from your VMs\n---------------------\n\nSome system metrics are automatically captured from your Compute Engine\ninstances. However, these\n[automatically collected Compute Engine metrics](/monitoring/api/metrics_gcp_c#gcp-compute)\nmight not provide you with all the information\nthat you need to monitor your services.\n\nTo collect additional system metrics from your Compute Engine instances,\ninstall an agent. For example,\nthe [Ops Agent metrics](/monitoring/api/metrics_opsagent) include those for CPU, disk, memory,\nand swap. These metrics, and others, can be collected from your\nLinux and Windows VMs.\n\nFor agent information, see [Google Cloud Observability agents](/monitoring/agent).\n\nMetrics from integrations\n-------------------------\n\nCloud Monitoring provides integrations that let you collect telemetry\nfrom applications such as Apache\nWeb Server, MySQL, Redis, and others for deployments running on\nCompute Engine and Google Kubernetes Engine:\n\n- When using Compute Engine, third-party telemetry is collected by\n the [Ops Agent](/monitoring/agent/ops-agent).\n\n- When using GKE, third-party telemetry is collected by\n [Google Cloud Managed Service for Prometheus](/stackdriver/docs/managed-prometheus).\n\nIn the Google Cloud console, go to the\n**Integrations**\npage:\n\n[Go to **Integrations**](https://console.cloud.google.com/monitoring/integrations)\n\n\u003cbr /\u003e\n\nIf you use the search bar to find this page, then select the result whose subheading is\n**Monitoring**.\n\nMetrics you define\n------------------\n\n\nYou can instrument your application so that it collects\napplication-specific information. Several open-source\ninstrumentation frameworks let you collect metrics, logs, and\ntraces from your application and send that data to any vendor,\nincluding Google Cloud. To instrument your application, we recommend that you use a\nvendor-neutral instrumentation framework that is open source, such as\n[OpenTelemetry](https://opentelemetry.io/), instead of\nvendor- and product-specific APIs or client libraries.\n\nFor information about instrumenting your applications by using\nvendor-neutral instrumentation frameworks, see\n[Instrumentation and observability](/stackdriver/docs/instrumentation/overview).\n\nYou can instrument your application by using a client library\nor the [Cloud Monitoring API](/monitoring/docs/apis).\nFor more information about these\napproaches, see [User-defined metrics overview](/monitoring/custom-metrics).\n\nMetrics derived from logs\n-------------------------\n\nGoogle Cloud supports creating metrics from log data. These\n*log-based metrics* record numeric information about\nthe logs written to [Cloud Logging](/logging/docs).\nSome metrics, such as the total number of log entries received by your\nGoogle Cloud project, are automatically derived from your logs.\nYou can also define log-based metrics. For example, you might\ncreate a metric that counts the number of `404 Not Found` errors\nfor an application deployed to App Engine.\n\nFor more information, see [Log-based metrics overview](/logging/docs/logs-based-metrics).\n\nPricing\n-------\n\nIn general, Cloud Monitoring system metrics are free, and metrics\nfrom external systems, agents, or applications are not. Billable metrics are\nbilled by either the number of bytes or the number of samples ingested.\n\nFor more information, see the Cloud Monitoring sections of the [Google Cloud Observability pricing](https://cloud.google.com/stackdriver/pricing) page."]]