瀏覽指標與資源類型

本頁說明如何使用 Monitoring API 執行下列操作:

  • 取得您自訂指標類型的清單或說明。
  • 取得內建指標類型的清單或說明,進而協助您設計自訂指標。這個清單也會顯示在說明文件中;請參閱指標清單一文。
  • 取得可用受控資源類型的清單或說明,用來為您自訂指標的時間序列資料加上標籤。這個清單也會顯示在說明文件中;請參閱監控資源清單一文。

如需這些概念的簡介,請參閱「指標、時間序列和資源」。

本頁面說明 metricDescriptors.listget 方法,以及 monitoredResourceDescriptors.listget 方法。您可以透過以下方式使用這些方法:

  • 為了在不編寫任何程式碼的情況下執行這些方法,本頁「通訊協定」分頁中的範例使用表單式的 API Explorer (如要進一步瞭解這項工具,請參閱 API Explorer)。

  • 如要瞭解如何使用所選程式設計語言的方法,請參閱本頁面的可執行程式碼範例。

「工作區」並非必要條件

除了使用自訂指標以外,您都可以在 metricDescriptors.listget 叫用中使用任何現有的專案,即使專案不在工作區中也是如此。如果您使用的是自訂指標,則必須指定定義自訂指標的專案。

您還可以將 monitoredResourceDescriptors.listget 方法搭配任何現有的專案使用。

列出指標描述元

指標描述元是定義內建與自訂指標的結構定義。透過瀏覽可用的指標描述元,您可以瞭解感興趣的指標詳細資料。

目前已有超過 900 種的內建指標,請參考完整的指標清單

如要進一步瞭解如何為指標類型命名,請參閱命名規則一文。

範例:列出指標類型

如要取得目前的指標類型清單,請使用 metricDescriptors.list 方法。使用篩選器可縮小傳回的指標類型集範圍。如需決定搜尋哪些指標類型名稱的說明,請參閱指標類型一文。

通訊協定

以下是用來傳回 Compute Engine 指標的 metricDescriptors.list 範例參數:

  • name (名稱)projects/[PROJECT_ID]
  • filter (篩選器)metric.type = starts_with("compute.googleapis.com")
  • fields (欄位)metricDescriptors.type,metricDescriptors.displayName

試試看!

按一下 [Execute] (執行) 按鈕之前,請先將 [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 值,請參閱範例:列出指標類型中的「PROTOCOL」(通訊協定) 分頁。

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

通訊協定

如要取得 Compute Engine 的 /firewall/dropped_packets_count 指標的詳細資料,請使用 metricDescriptors.get 的下列參數:

  • name (名稱)projects/[PROJECT_ID]/metricDescriptors/compute.googleapis.com/firewall/dropped_packets_count

試試看!

按一下 [Execute] (執行) 按鈕之前,請先將 [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.metricDescriptorPath(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

  • name (名稱)projects/[PROJECT_ID]
  • fields (欄位)resourceDescriptors.type

試試看!

按一下 [Execute] (執行) 按鈕之前,請先將 [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 值,請參閱範例:列出資源類型中的「PROTOCOL」(通訊協定) 分頁。

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

通訊協定

如要取得 gce_instance 資源類型的詳細資料,請使用 monitoredResourceDescriptors.get 方法的下列參數:

  • name (名稱)projects/[PROJECT_ID]/monitoredResourceDescriptors/gce_instance

試試看!

按一下 [Execute] (執行) 按鈕之前,請先將 [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.monitoredResourceDescriptorPath(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 這類指標的時間序列資料。在您識別可能的指標時間序列之後,請參閱讀取指標資料

本頁內容對您是否有任何幫助?請提供意見:

傳送您對下列選項的寶貴意見...

這個網頁
Stackdriver Monitoring
需要協助嗎?請前往我們的支援網頁