カスタム指標を削除する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
カスタム指標を削除する方法を説明します。
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
C#
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Go
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Java
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Node.js
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
PHP
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Ruby
Monitoring で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to delete a custom metric.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Create user-defined metrics with the API](/monitoring/custom-metrics/creating-metrics)\n\nCode sample \n\nC#\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n public static object DeleteMetric(string projectId, string metricType)\n {\n // Create client.\n MetricServiceClient metricServiceClient = MetricServiceClient.Create();\n // Initialize request argument(s).\n MetricDescriptorName name = new MetricDescriptorName(projectId, metricType);\n // Make the request.\n metricServiceClient.DeleteMetricDescriptor(name);\n Console.WriteLine($\"Done deleting metric descriptor: {name}\");\n return 0;\n }\n\nGo\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tmonitoring \"cloud.google.com/go/monitoring/apiv3\"\n \t\"cloud.google.com/go/monitoring/apiv3/v2/monitoringpb\"\n )\n\n // deleteMetric deletes the given metric. name should be of the form\n // \"projects/PROJECT_ID/metricDescriptors/METRIC_TYPE\".\n func deleteMetric(w io.Writer, name string) error {\n \tctx := context.Background()\n \tc, err := monitoring.NewMetricClient(ctx)\n \tif err != nil {\n \t\treturn err\n \t}\n \tdefer c.Close()\n \treq := &monitoringpb.DeleteMetricDescriptorRequest{\n \t\tName: name,\n \t}\n\n \tif err := c.DeleteMetricDescriptor(ctx, req); err != nil {\n \t\treturn fmt.Errorf(\"could not delete metric: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Deleted metric: %q\\n\", name)\n \treturn nil\n }\n\nJava\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n final String projectId = System.getProperty(\"projectId\");\n try (final MetricServiceClient client = MetricServiceClient.create();) {\n MetricDescriptorName metricName = MetricDescriptorName.of(projectId, type);\n client.deleteMetricDescriptor(metricName);\n System.out.println(\"Deleted descriptor \" + type);\n }\n\nNode.js\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud client library\n const monitoring = require('https://cloud.google.com/nodejs/docs/reference/monitoring/latest/overview.html');\n\n // Creates a client\n const client = new monitoring.https://cloud.google.com/nodejs/docs/reference/monitoring/latest/overview.html();\n\n async function deleteMetricDescriptor() {\n /**\n * TODO(developer): Uncomment and edit the following lines of code.\n */\n // const projectId = 'YOUR_PROJECT_ID';\n // const metricId = 'custom.googleapis.com/stores/daily_sales';\n\n const request = {\n name: client.https://cloud.google.com/nodejs/docs/reference/monitoring/latest/monitoring/v3.metricserviceclient.html(projectId, metricId),\n };\n\n // Deletes a metric descriptor\n const [result] = await client.deleteMetricDescriptor(request);\n console.log(`Deleted ${metricId}`, result);\n }\n deleteMetricDescriptor();\n\nPHP\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\Cloud\\Monitoring\\V3\\Client\\MetricServiceClient;\n use Google\\Cloud\\Monitoring\\V3\\DeleteMetricDescriptorRequest;\n\n /**\n * Example:\n * ```\n * delete_metric($projectId, $databaseId);\n * ```\n *\n * @param string $projectId Your project ID\n * @param string $metricId The ID of the Metric Descriptor to delete\n */\n function delete_metric($projectId, $metricId)\n {\n $metrics = new MetricServiceClient([\n 'projectId' =\u003e $projectId,\n ]);\n\n $metricPath = $metrics-\u003emetricDescriptorName($projectId, $metricId);\n $deleteMetricDescriptorRequest = (new DeleteMetricDescriptorRequest())\n -\u003esetName($metricPath);\n $metrics-\u003edeleteMetricDescriptor($deleteMetricDescriptorRequest);\n\n printf('Deleted a metric: ' . $metricPath . PHP_EOL);\n }\n\nPython\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import https://cloud.google.com/python/docs/reference/monitoring/latest/\n\n client = https://cloud.google.com/python/docs/reference/monitoring/latest/.https://cloud.google.com/python/docs/reference/monitoring/latest/google.cloud.monitoring_v3.services.metric_service.MetricServiceClient.html()\n client.https://cloud.google.com/python/docs/reference/monitoring/latest/google.cloud.monitoring_v3.services.metric_service.MetricServiceClient.html#google_cloud_monitoring_v3_services_metric_service_MetricServiceClient_delete_metric_descriptor(name=descriptor_name)\n print(\"Deleted metric descriptor {}.\".format(descriptor_name))\n\nRuby\n\n\nTo authenticate to Monitoring, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n gem \"google-cloud-monitoring\"\n require \"google/cloud/monitoring\"\n\n # Your Google Cloud Platform project ID\n # project_id = \"YOUR_PROJECT_ID\"\n\n # Example metric type\n # metric_type = \"custom.googleapis.com/my_metric\"\n\n client = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-monitoring/latest/Google-Cloud-Monitoring.html.https://cloud.google.com/ruby/docs/reference/google-cloud-monitoring/latest/Google-Cloud-Monitoring.html\n metric_name = client.https://cloud.google.com/ruby/docs/reference/google-cloud-monitoring-v3/latest/Google-Cloud-Monitoring-V3-MetricService-Paths.html project: project_id,\n metric_descriptor: metric_type\n\n client.delete_metric_descriptor name: metric_name\n p \"Deleted metric descriptor #{metric_name}.\"\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=monitoring)."]]