apiVersion:monitoring.gdc.goog/v1alpha1kind:MonitoringTargetmetadata:# Choose the same namespace as the workload podsnamespace:PROJECT_NAMESPACEname:stringspec:...podMetricsEndpoints:...metricsRelabelings:...- action:replacetargetLabel:_gdch_projectreplacement:another-project-name
apiVersion:monitoring.gdc.goog/v1alpha1kind:MonitoringTargetmetadata:# Choose the same namespace as the workload podsnamespace:PROJECT_NAMESPACEname:stringspec:...podMetricsEndpoints:...metricsRelabelings:...- action:replacetargetLabel:my_new_labelreplacement:my_label_value
apiVersion:monitoring.gdc.goog/v1alpha1kind:MonitoringTargetmetadata:# Choose the same namespace as the workload podsnamespace:PROJECT_NAMESPACEname:stringspec:...podMetricsEndpoints:...metricsRelabelings:...- action:replaceregex:cpu_usagereplacement:cpu_usage_new_namesourceLabels:[__name__]targetLabel:__name__
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eTo label or view metrics, you'll need the "Monitoring Target Editor" or "Monitoring Target Viewer" role, respectively, granted by your Project IAM Admin.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMonitoringTarget\u003c/code\u003e custom resource enables advanced metric labeling features such as sending metrics to another project, adding new labels, and renaming metrics.\u003c/p\u003e\n"],["\u003cp\u003eYou can direct specific metrics to be sent to a different project by using the \u003ccode\u003e_gdch_project\u003c/code\u003e label within your code or via the \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource.\u003c/p\u003e\n"],["\u003cp\u003eNew labels can be added to metrics by specifying a new target label and its replacement value within the \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource also allows for the renaming of existing metrics, by using the \u003ccode\u003emetricsRelabelings\u003c/code\u003e field, utilizing a regular expression for the original metric name and specifying a replacement.\u003c/p\u003e\n"]]],[],null,["# Label metrics\n\nBefore you begin\n----------------\n\nTo get the permissions you need to label metrics or view metric labels, ask your Project IAM Admin to grant you one of the following roles in your project namespace:\n\n- **Monitoring Target Editor** : edits or modifies `MonitoringTarget` custom resources. Request the Monitoring Target Editor (`monitoringtarget-editor`) role.\n- **Monitoring Target Viewer** : views `MonitoringTarget` custom resources. Request the Monitoring Target Viewer (`monitoringtarget-viewer`) role.\n\nLabels let you differentiate the characteristics of a metric. Apart from [collecting metrics](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/collect-metrics), the `MonitoringTarget` custom resource lets you label metrics for optional features such as the following:\n\n- [Send metrics to another project](#send-metrics-to-another-project)\n- [Add new labels to metrics](#add-new-labels-to-metrics)\n- [Rename a metric](#rename-a-metric)\n\n| **Important:** Every unique combination of key-value label pairs represents a new time series, which can very much increase the amount of data stored. Don't use labels to store dimensions with high cardinality (many different label values), such as user IDs, email addresses, or other unbounded sets of values.\n\nFor more information on metrics relabeling, see \u003chttps://grafana.com/blog/2022/03/21/how-relabeling-in-prometheus-works/\u003e\n\nSend metrics to another project\n-------------------------------\n\nContainer authors can write in their code that the system must send specific metrics to another project for system monitoring, even if the project corresponds to a different GDC persona. To send metrics to a specific project, add the `_gdch_project` label to a metric in your code. Set its value to the name of the project you want to own that particular observability metric. For example, `\"_gdch_project\": \"another-project-name\"`.\n\nAlternatively, use the `MonitoringTarget` custom resource to send all the metric data it collects to another project for data observability. To do so, set the `_gdch_project` label as a target label in the `metricsRelabelings` field and establish a replacement value.\n\nThe following code sample shows how to replace the `_gdch_project` label value with `another-project-name` in the `MonitoringTarget` custom resource: \n\n apiVersion: monitoring.gdc.goog/v1alpha1\n kind: MonitoringTarget\n metadata:\n # Choose the same namespace as the workload pods\n namespace: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_NAMESPACE\u003c/span\u003e\u003c/var\u003e\n name: string\n spec:\n ...\n podMetricsEndpoints:\n ...\n metricsRelabelings:\n ...\n - action: replace\n targetLabel: _gdch_project\n replacement: another-project-name\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e with the namespace of your project.\n\nAdd new labels to metrics\n-------------------------\n\nLabels are useful for data observability and system monitoring because they let you identify different characteristics of a metric. You can add new labels to metrics that the scrapped containers don't initially expose. In the `MonitoringTarget` custom resource, set the new label as a target and establish a replacement to serve as the value of the label. The system adds the new key-value pair to all metrics the custom resource collects for your data observability purposes.\n\nThe following code sample shows how to add the `my_new_label` label and set its value to `my_label_value` in the `MonitoringTarget` custom resource: \n\n apiVersion: monitoring.gdc.goog/v1alpha1\n kind: MonitoringTarget\n metadata:\n # Choose the same namespace as the workload pods\n namespace: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_NAMESPACE\u003c/span\u003e\u003c/var\u003e\n name: string\n spec:\n ...\n podMetricsEndpoints:\n ...\n metricsRelabelings:\n ...\n - action: replace\n targetLabel: my_new_label\n replacement: my_label_value\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e with the namespace of your project.\n\nRename a metric\n---------------\n\nYou can entirely rename a metric a container produces from the `MonitoringTarget` CR. Set the original name of the metric and its replacement in the `metricsRelabelings` field. The custom resource takes the original metric name as a regular expression and replaces it with the new name you added.\n\nThe following code sample shows how to replace the `cpu_usage` metric name with `cpu_usage_new_name` in the `MonitoringTarget` CR: \n\n apiVersion: monitoring.gdc.goog/v1alpha1\n kind: MonitoringTarget\n metadata:\n # Choose the same namespace as the workload pods\n namespace: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_NAMESPACE\u003c/span\u003e\u003c/var\u003e\n name: string\n spec:\n ...\n podMetricsEndpoints:\n ...\n metricsRelabelings:\n ...\n - action: replace\n regex: cpu_usage\n replacement: cpu_usage_new_name\n sourceLabels: [__name__]\n targetLabel: __name__\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e with the namespace of your project."]]