浏览指标和资源类型

本页介绍如何使用 Monitoring API 执行以下操作:

  • 获取自定义指标类型的列表或描述。
  • 获取内置指标类型的列表或描述,这可以帮助您设计自定义指标。文档中也提供了该列表,具体请参阅指标列表
  • 获取可用受监控资源类型的列表或描述,您可以用其来标记自定义指标的时间序列数据。文档中也提供了该列表,具体请参阅受监控的资源列表

如需了解这些概念,请参阅指标、时间序列和资源

本页面介绍了 metricDescriptors.listget 方法,以及 monitoredResourceDescriptors.listget 方法。使用这些方法的方式有若干种:

  • 为了在不编写任何代码的情况下运行这些方法,本页面上的协议 标签中的示例使用基于表单的 API Explorer。(如需详细了解此工具,请参阅 API Explorer。)

  • 要了解如何从所选编程语言使用这些方法,请参阅本页面上的可运行代码示例。

浏览 BindPlane 的指标

您可以在 Metrics Explorer 中找到 BindPlane 的指标。所有 BindPlane 指标都显示为资源类型 generic_node,并且指标名称以 external.googleapis.com/bluemedora/generic_node/ 为前缀。

有关 BindPlane 中可用来源的信息,请参阅 BindPlane 来源文档。

工作区不是必需的

除非要使用自定义指标,否则您可以在 metricDescriptors.listget 调用中使用任何现有项目,即使项目不在工作区中也无妨。如果要使用自定义指标,则必须指定定义了这些自定义指标的项目。

您还可以通过 monitoredResourceDescriptors.listget 方法使用任何现有项目。

列出指标描述符

指标描述符是对内置指标和自定义指标进行定义的架构。 通过浏览可用的指标描述符,您可以找到您想要了解的指标的详细信息。

目前有 900 多个内置指标;如需参考,请参阅完整的指标列表

如需详细了解指标类型的命名方式,请参阅命名惯例

示例:列出指标类型

要获取当前的指标类型列表,请使用 metricDescriptors.list 方法。要减少返回的指标类型数量,请使用过滤条件。请参阅值类型和指标种类,以帮助确定要搜索的指标类型。

协议

以下是用于返回 Compute Engine 指标的 metricDescriptors.list 示例参数:

  • 名称projects/[PROJECT_ID]
  • 过滤条件metric.type = starts_with("compute.googleapis.com")
  • 字段metricDescriptors.type,metricDescriptors.displayName

试试看!

[PROJECT_ID] 更改为有效的 ID,然后点击执行按钮。

以下示例输出显示了与过滤条件相匹配的许多 Compute Engine 指标中的三个:

"metricDescriptors": [
      {
       "displayName": "Dropped bytes",
       "type": "compute.googleapis.com/firewall/dropped_bytes_count"
      },
      {
       "displayName": "Dropped packets",
       "type": "compute.googleapis.com/firewall/dropped_packets_count"
      },
      {
       "displayName": "Reserved cores.",
       "type": "compute.googleapis.com/instance/cpu/reserved_cores"
      },
      ...
    ]
    

此处的 type 值用于标识指标描述符,例如 compute.googleapis.com/firewall/dropped_packets_count。此值有时也称为“指标类型^”或“指标类型名称”。

C#

public static object ListMetrics(string projectId)
    {
        MetricServiceClient client = MetricServiceClient.Create();
        ProjectName projectName = new ProjectName(projectId);
        PagedEnumerable<ListMetricDescriptorsResponse, MetricDescriptor> metrics = client.ListMetricDescriptors(projectName);
        foreach (MetricDescriptor metric in metrics)
        {
            Console.WriteLine($"{metric.Name}: {metric.DisplayName}");
        }
        return 0;
    }

Go


    import (
    	"context"
    	"fmt"
    	"io"

    	monitoring "cloud.google.com/go/monitoring/apiv3"
    	"google.golang.org/api/iterator"
    	monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    )

    // listMetrics lists all the metrics available to be monitored in the API.
    func listMetrics(w io.Writer, projectID string) error {
    	ctx := context.Background()
    	c, err := monitoring.NewMetricClient(ctx)
    	if err != nil {
    		return err
    	}

    	req := &monitoringpb.ListMetricDescriptorsRequest{
    		Name: "projects/" + projectID,
    	}
    	iter := c.ListMetricDescriptors(ctx, req)

    	for {
    		resp, err := iter.Next()
    		if err == iterator.Done {
    			break
    		}
    		if err != nil {
    			return fmt.Errorf("Could not list metrics: %v", err)
    		}
    		fmt.Fprintf(w, "%v\n", resp.GetType())
    	}
    	fmt.Fprintln(w, "Done")
    	return nil
    }
    

Java

// Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");

    final MetricServiceClient client = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);

    ListMetricDescriptorsRequest request =
        ListMetricDescriptorsRequest.newBuilder().setName(name.toString()).build();
    ListMetricDescriptorsPagedResponse response = client.listMetricDescriptors(request);

    System.out.println("Listing descriptors: ");

    for (MetricDescriptor d : response.iterateAll()) {
      System.out.println(d.getName() + " " + d.getDisplayName());
    }

Node.js

// Imports the Google Cloud client library
    const monitoring = require('@google-cloud/monitoring');

    // Creates a client
    const client = new monitoring.MetricServiceClient();

    /**
     * TODO(developer): Uncomment and edit the following lines of code.
     */
    // const projectId = 'YOUR_PROJECT_ID';

    const request = {
      name: client.projectPath(projectId),
    };

    // Lists metric descriptors
    const [descriptors] = await client.listMetricDescriptors(request);
    console.log('Metric Descriptors:');
    descriptors.forEach(descriptor => console.log(descriptor.name));
    

PHP

use Google\Cloud\Monitoring\V3\MetricServiceClient;

    /**
     * Example:
     * ```
     * list_descriptors($projectId);
     * ```
     *
     * @param string $projectId Your project ID
     */
    function list_descriptors($projectId)
    {
        $metrics = new MetricServiceClient([
            'projectId' => $projectId,
        ]);

        $projectName = $metrics->projectName($projectId);
        $descriptors = $metrics->listMetricDescriptors($projectName);

        printf('Metric Descriptors:' . PHP_EOL);
        foreach ($descriptors->iterateAllElements() as $descriptor) {
            printf($descriptor->getName() . PHP_EOL);
        }
    }

Python

client = monitoring_v3.MetricServiceClient()
    project_name = client.project_path(project_id)
    for descriptor in client.list_metric_descriptors(project_name):
        print(descriptor.type)

Ruby

client = Google::Cloud::Monitoring::Metric.new
    project_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path project_id
    results = client.list_metric_descriptors project_name
    results.each do |descriptor|
      p descriptor.type
    end

如果遇到困难,请参阅 API 调用问题排查

示例:获取指标描述符

要获取有关指标类型的更多详细信息,请使用 metricDescriptors.get 方法检索完整的指标描述符。

要检索特定的指标描述符,您需要描述符的全名。此值由两个组件构成:

  • projects/[PROJECT_ID]/metricDescriptors 组成的前缀。
  • 标识指标描述符的 type 值,例如 compute.googleapis.com/firewall/dropped_packets_count。如需详细了解 type 值,请参阅示例:列出指标类型中的协议标签。

示例:projects/[PROJECT_ID]/metricDescriptors/compute.googleapis.com/firewall/dropped_packets_count

协议

如需获取 Compute Engine 的 /firewall/dropped_packets_count 指标的详细信息,请对 metricDescriptors.get 使用以下参数:

  • 名称projects/[PROJECT_ID]/metricDescriptors/compute.googleapis.com/firewall/dropped_packets_count

试试看!

[PROJECT_ID] 更改为有效的 ID,然后点击执行按钮。

以下示例响应显示了该指标的描述符:

{
      "type": "compute.googleapis.com/firewall/dropped_packets_count",
      "name": "projects/[PROJECT_ID]/metricDescriptors/compute.googleapis.com/firewall/dropped_packets_count",
      "description": "Delta count of incoming packets dropped by the firewall.",
      "displayName": "Dropped packets",
      "labels": [
       {
        "key": "instance_name",
        "description": "The name of the VM instance."
       }
      ],
      "metricKind": "DELTA",
      "valueType": "INT64",
      "unit": "1"
    }
    

C#

public static object GetMetricDetails(string projectId, string metricType)
    {
        MetricServiceClient client = MetricServiceClient.Create();
        MetricDescriptorName name = new MetricDescriptorName(projectId, metricType);
        try
        {
            var response = client.GetMetricDescriptor(name);
            string metric = JObject.Parse($"{response}").ToString();
            Console.WriteLine($"{ metric }");
        }
        catch (Grpc.Core.RpcException ex)
            when (ex.Status.StatusCode == Grpc.Core.StatusCode.NotFound)
        { }
        return 0;
    }

Go


    import (
    	"context"
    	"fmt"
    	"io"

    	monitoring "cloud.google.com/go/monitoring/apiv3"
    	monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    )

    // getMetricDescriptor gets the descriptor for the given metricType and prints
    // information about it. metricType is the type of the metric, for example
    // compute.googleapis.com/firewall/dropped_packets_count.
    func getMetricDescriptor(w io.Writer, projectID, metricType string) error {
    	ctx := context.Background()
    	c, err := monitoring.NewMetricClient(ctx)
    	if err != nil {
    		return fmt.Errorf("NewMetricClient: %v", err)
    	}
    	req := &monitoringpb.GetMetricDescriptorRequest{
    		Name: fmt.Sprintf("projects/%s/metricDescriptors/%s", projectID, metricType),
    	}
    	resp, err := c.GetMetricDescriptor(ctx, req)
    	if err != nil {
    		return fmt.Errorf("could not get custom metric: %v", err)
    	}

    	fmt.Fprintf(w, "Name: %v\n", resp.GetName())
    	fmt.Fprintf(w, "Description: %v\n", resp.GetDescription())
    	fmt.Fprintf(w, "Type: %v\n", resp.GetType())
    	fmt.Fprintf(w, "Metric Kind: %v\n", resp.GetMetricKind())
    	fmt.Fprintf(w, "Value Type: %v\n", resp.GetValueType())
    	fmt.Fprintf(w, "Unit: %v\n", resp.GetUnit())
    	fmt.Fprintf(w, "Labels:\n")
    	for _, l := range resp.GetLabels() {
    		fmt.Fprintf(w, "\t%s (%s) - %s", l.GetKey(), l.GetValueType(), l.GetDescription())
    	}
    	return nil
    }
    

Java

// Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");

    final MetricServiceClient client = MetricServiceClient.create();
    MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of(projectId, type);
    MonitoredResourceDescriptor response = client.getMonitoredResourceDescriptor(name);

    System.out.println("Printing monitored resource descriptor: ");
    System.out.println(response);

Node.js

// Imports the Google Cloud client library
    const monitoring = require('@google-cloud/monitoring');

    // Creates a client
    const client = new monitoring.MetricServiceClient();

    /**
     * TODO(developer): Uncomment and edit the following lines of code.
     */
    // const projectId = 'YOUR_PROJECT_ID';
    // const metricId = 'custom.googleapis.com/your/id';

    const request = {
      name: client.projectMetricDescriptorPath(projectId, metricId),
    };

    // Retrieves a metric descriptor
    const [descriptor] = await client.getMetricDescriptor(request);
    console.log(`Name: ${descriptor.displayName}`);
    console.log(`Description: ${descriptor.description}`);
    console.log(`Type: ${descriptor.type}`);
    console.log(`Kind: ${descriptor.metricKind}`);
    console.log(`Value Type: ${descriptor.valueType}`);
    console.log(`Unit: ${descriptor.unit}`);
    console.log('Labels:');
    descriptor.labels.forEach(label => {
      console.log(`  ${label.key} (${label.valueType}) - ${label.description}`);
    });

PHP

use Google\Cloud\Monitoring\V3\MetricServiceClient;

    /**
     * Example:
     * ```
     * get_descriptor($projectId);
     * ```
     *
     * @param string $projectId Your project ID
     * @param string $metricId  The ID of the Metric Descriptor to get
     */
    function get_descriptor($projectId, $metricId)
    {
        $metrics = new MetricServiceClient([
            'projectId' => $projectId,
        ]);

        $metricName = $metrics->metricDescriptorName($projectId, $metricId);
        $descriptor = $metrics->getMetricDescriptor($metricName);

        printf('Name: ' . $descriptor->getDisplayName() . PHP_EOL);
        printf('Description: ' . $descriptor->getDescription() . PHP_EOL);
        printf('Type: ' . $descriptor->getType() . PHP_EOL);
        printf('Metric Kind: ' . $descriptor->getMetricKind() . PHP_EOL);
        printf('Value Type: ' . $descriptor->getValueType() . PHP_EOL);
        printf('Unit: ' . $descriptor->getUnit() . PHP_EOL);
        printf('Labels:' . PHP_EOL);
        foreach ($descriptor->getLabels() as $labels) {
            printf('  %s (%s) - %s' . PHP_EOL,
                $labels->getKey(),
                $labels->getValueType(),
                $labels->getDescription());
        }
    }

Python

client = monitoring_v3.MetricServiceClient()
    descriptor = client.get_metric_descriptor(metric_name)
    pprint.pprint(descriptor)

Ruby

client = Google::Cloud::Monitoring::Metric.new
    descriptor = client.get_metric_descriptor metric_name
    p descriptor

如果遇到困难,请参阅 API 调用问题排查

列出受监控的资源

受监控的资源是可以受监控的云端实体。通过浏览现有的受监控资源类型,您可以找到具有指标的实体种类。

目前大约有 100 种不同的受监控资源描述符;请参阅受监控的资源列表,查看完整集合。

如需了解指标描述符和受监控的资源,请参阅指标、时间序列和资源

您可以在 monitoredResourceDescriptors.listget 调用中使用任何现有项目,即使项目不在工作区中也无妨。

示例:列出资源类型

要从 Monitoring API 获取受监控的资源类型的当前列表,请使用 monitoredResourceDescriptors.list 方法并提供项目 ID。

协议

如需获取受监控的资源类型的当前列表,请将 monitoredResourceDescriptors.list 与以下示例参数结合使用:

  • 名称projects/[PROJECT_ID]
  • 字段resourceDescriptors.type

试试看!

[PROJECT_ID] 更改为有效的 ID,然后点击执行按钮。

以下示例响应显示了返回的一些受监控的资源类型:

{
     "resourceDescriptors": [
      {
       "type": "api"
      },
      {
       "type": "aws_cloudfront_distribution"
      },
      {
       "type": "aws_dynamodb_table"
      },
      {
       "type": "aws_ebs_volume"
      },
      ...
    }
    

C#

        public static object ListMonitoredResources(string projectId)
            {
                Console.WriteLine("Starting to List Monitored Resources...");
                MetricServiceClient client = MetricServiceClient.Create();
                ProjectName projectName = new ProjectName(projectId);

                PagedEnumerable<ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor>
                    resources = client.ListMonitoredResourceDescriptors(projectName);
                if (resources != null)
                {
                    foreach (MonitoredResourceDescriptor resource in resources.Take(10))
                    {
                        Console.WriteLine($"{resource.Name}: {resource.DisplayName}");
                    }
                }
                else { Console.WriteLine("No resources found."); }
                return 0;
            }

Go


    import (
    	"context"
    	"fmt"
    	"io"

    	monitoring "cloud.google.com/go/monitoring/apiv3"
    	"google.golang.org/api/iterator"
    	monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    )

    // listMonitoredResources lists all the resources available to be monitored.
    func listMonitoredResources(w io.Writer, projectID string) error {
    	ctx := context.Background()
    	c, err := monitoring.NewMetricClient(ctx)
    	if err != nil {
    		return err
    	}

    	req := &monitoringpb.ListMonitoredResourceDescriptorsRequest{
    		Name: "projects/" + projectID,
    	}
    	iter := c.ListMonitoredResourceDescriptors(ctx, req)

    	for {
    		resp, err := iter.Next()
    		if err == iterator.Done {
    			break
    		}
    		if err != nil {
    			return fmt.Errorf("Could not list time series: %v", err)
    		}
    		fmt.Fprintf(w, "%v\n", resp)
    	}
    	fmt.Fprintln(w, "Done")
    	return nil
    }
    

Java

// Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");

    final MetricServiceClient client = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);

    ListMonitoredResourceDescriptorsRequest request =
        ListMonitoredResourceDescriptorsRequest.newBuilder().setName(name.toString()).build();

    System.out.println("Listing monitored resource descriptors: ");

    ListMonitoredResourceDescriptorsPagedResponse response =
        client.listMonitoredResourceDescriptors(request);

    for (MonitoredResourceDescriptor d : response.iterateAll()) {
      System.out.println(d.getType());
    }

Node.js

// Imports the Google Cloud client library
    const monitoring = require('@google-cloud/monitoring');

    // Creates a client
    const client = new monitoring.MetricServiceClient();

    /**
     * TODO(developer): Uncomment and edit the following lines of code.
     */
    // const projectId = 'YOUR_PROJECT_ID';

    const request = {
      name: client.projectPath(projectId),
    };

    // Lists monitored resource descriptors
    const [descriptors] = await client.listMonitoredResourceDescriptors(request);
    console.log('Monitored Resource Descriptors:');
    descriptors.forEach(descriptor => {
      console.log(descriptor.name);
      console.log(`  Type: ${descriptor.type}`);
      if (descriptor.labels) {
        console.log('  Labels:');
        descriptor.labels.forEach(label => {
          console.log(
            `    ${label.key} (${label.valueType}): ${label.description}`
          );
        });
      }
      console.log();
    });
    

PHP

use Google\Cloud\Monitoring\V3\MetricServiceClient;

    /**
     * Example:
     * ```
     * list_resources('your-project-id');
     * ```
     *
     * @param string $projectId Your project ID
     */
    function list_resources($projectId)
    {
        $metrics = new MetricServiceClient([
            'projectId' => $projectId,
        ]);
        $projectName = $metrics->projectName($projectId);
        $descriptors = $metrics->listMonitoredResourceDescriptors($projectName);
        foreach ($descriptors->iterateAllElements() as $descriptor) {
            print($descriptor->getType() . PHP_EOL);
        }
    }

Python

client = monitoring_v3.MetricServiceClient()
    project_name = client.project_path(project_id)
    resource_descriptors = (
        client.list_monitored_resource_descriptors(project_name))
    for descriptor in resource_descriptors:
        print(descriptor.type)

Ruby

client = Google::Cloud::Monitoring::Metric.new
    project_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path project_id
    results = client.list_monitored_resource_descriptors project_name
    results.each do |descriptor|
      p descriptor.type
    end

如果遇到困难,请参阅 API 调用问题排查

获取资源描述符

要获取有关受监控的资源类型的更多详细信息,请使用 monitoredResourceDescriptors.get 方法检索完整的描述符。

要检索特定的受监控资源描述符,您需要描述符的全名。此值由两个组件构成:

  • projects/[PROJECT_ID]/monitoredResourceDescriptors 组成的前缀。
  • 标识指标描述符的 type 值,例如 gce_instance。如需详细了解 type 值,请参阅示例:列出资源类型中的协议标签。

示例:projects/[PROJECT_ID]/monitoredResourceDescriptors/gce_instance

协议

如需获取 gce_instance 资源类型的详细信息,请对 monitoredResourceDescriptors.get 方法使用以下参数:

  • 名称projects/[PROJECT_ID]/monitoredResourceDescriptors/gce_instance

试试看!

[PROJECT_ID] 更改为有效的 ID,然后点击执行按钮。

以下示例响应显示了此受监控资源的描述符:

{
      "type": "gce_instance",
      "displayName": "G​C​E VM Instance",
      "description": "A virtual machine instance hosted in Google Compute Engine (G​C​E).",
      "labels": [
        {
          "key": "project_id",
          "description": "The identifier of the GCP project associated with this resource, such as \"my-project\"."
        },
        {
          "key": "instance_id",
          "description": "The numeric VM instance identifier assigned by Compute Engine."
        },
        {
          "key": "zone",
          "description": "The Compute Engine zone in which the VM is running."
        }
      ],
      "name": "projects/[PROJECT_ID]/monitoredResourceDescriptors/gce_instance"
    }
    

C#

public static object GetMonitoredResource(string projectId, string resourceId)
    {
        MetricServiceClient client = MetricServiceClient.Create();
        MonitoredResourceDescriptorName name = new MonitoredResourceDescriptorName(projectId, resourceId);
        var response = client.GetMonitoredResourceDescriptor(name);
        string resource = JObject.Parse($"{response}").ToString();
        Console.WriteLine($"{ resource }");
        return 0;
    }

Go


    import (
    	"context"
    	"fmt"
    	"io"

    	monitoring "cloud.google.com/go/monitoring/apiv3"
    	monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    )

    // getMonitoredResource gets the descriptor for the given resourceType and
    // prints information about it. resource should be of the form
    // "projects/[PROJECT_ID]/monitoredResourceDescriptors/[RESOURCE_TYPE]".
    func getMonitoredResource(w io.Writer, resource string) error {
    	ctx := context.Background()
    	c, err := monitoring.NewMetricClient(ctx)
    	if err != nil {
    		return fmt.Errorf("NewMetricClient: %v", err)
    	}
    	req := &monitoringpb.GetMonitoredResourceDescriptorRequest{
    		Name: fmt.Sprintf(resource),
    	}
    	resp, err := c.GetMonitoredResourceDescriptor(ctx, req)
    	if err != nil {
    		return fmt.Errorf("could not get custom metric: %v", err)
    	}

    	fmt.Fprintf(w, "Name: %v\n", resp.GetName())
    	fmt.Fprintf(w, "Description: %v\n", resp.GetDescription())
    	fmt.Fprintf(w, "Type: %v\n", resp.GetType())
    	fmt.Fprintf(w, "Labels:\n")
    	for _, l := range resp.GetLabels() {
    		fmt.Fprintf(w, "\t%s (%s) - %s", l.GetKey(), l.GetValueType(), l.GetDescription())
    	}
    	return nil
    }
    

Java

void getMonitoredResource(String resourceId) throws IOException {
      String projectId = System.getProperty("projectId");
      MetricServiceClient client = MetricServiceClient.create();
      MonitoredResourceDescriptorName name =
          MonitoredResourceDescriptorName.of(projectId, resourceId);
      MonitoredResourceDescriptor response = client.getMonitoredResourceDescriptor(name);
      System.out.println("Retrieved Monitored Resource: " + gson.toJson(response));
    }

Node.js

// Imports the Google Cloud client library
    const monitoring = require('@google-cloud/monitoring');

    // Creates a client
    const client = new monitoring.MetricServiceClient();

    /**
     * TODO(developer): Uncomment and edit the following lines of code.
     */
    // const projectId = 'YOUR_PROJECT_ID';
    // const resourceType = 'some_resource_type, e.g. cloudsql_database';

    const request = {
      name: client.projectMonitoredResourceDescriptorPath(
        projectId,
        resourceType
      ),
    };

    // Lists monitored resource descriptors
    const [descriptor] = await client.getMonitoredResourceDescriptor(request);

    console.log(`Name: ${descriptor.displayName}`);
    console.log(`Description: ${descriptor.description}`);
    console.log(`Type: ${descriptor.type}`);
    console.log('Labels:');
    descriptor.labels.forEach(label => {
      console.log(`  ${label.key} (${label.valueType}) - ${label.description}`);
    });

PHP

use Google\Cloud\Monitoring\V3\MetricServiceClient;

    /**
     * Example:
     * ```
     * get_resource('your-project-id', 'gcs_bucket');
     * ```
     *
     * @param string $projectId Your project ID
     * @param string $resourceType The resource type of the monitored resource.
     */
    function get_resource($projectId, $resourceType)
    {
        $metrics = new MetricServiceClient([
            'projectId' => $projectId,
        ]);

        $metricName = $metrics->monitoredResourceDescriptorName($projectId, $resourceType);
        $resource = $metrics->getMonitoredResourceDescriptor($metricName);

        printf('Name: %s' . PHP_EOL, $resource->getName());
        printf('Type: %s' . PHP_EOL, $resource->getType());
        printf('Display Name: %s' . PHP_EOL, $resource->getDisplayName());
        printf('Description: %s' . PHP_EOL, $resource->getDescription());
        printf('Labels:' . PHP_EOL);
        foreach ($resource->getLabels() as $labels) {
            printf('  %s (%s) - %s' . PHP_EOL,
                $labels->getKey(),
                $labels->getValueType(),
                $labels->getDescription());
        }
    }

Python

client = monitoring_v3.MetricServiceClient()
    resource_path = client.monitored_resource_descriptor_path(
        project_id, resource_type_name)
    pprint.pprint(client.get_monitored_resource_descriptor(resource_path))

Ruby

client = Google::Cloud::Monitoring::Metric.new
    resource_path = Google::Cloud::Monitoring::V3::MetricServiceClient.monitored_resource_descriptor_path(
      project_id,
      resource_type
    )

    result = client.get_monitored_resource_descriptor resource_path
    p result

如果遇到困难,请参阅 API 调用问题排查

查找资源

受监控资源对象包含在时间序列数据中。您通常可以猜到哪些指标包含特定类型的受监控资源。例如,如果要查看受监控的资源 gce_instance,请查看 compute.googleapils.com/instance/cpu/utilization 之类的指标的时间序列数据。在确定了可能的指标时间序列后,请参阅读取指标数据