apiVersion:monitoring.gdc.goog/v1kind:MonitoringTargetmetadata:# Choose the same namespace as the workload pods.namespace:PROJECT_NAMESPACEname:MONITORING_TARGET_NAMEspec:[...]podMetricsEndpoints:[...]metricsRelabelings:-action:replacetargetLabel:_gdch_projectreplacement:another-project-name[...]
apiVersion:monitoring.gdc.goog/v1kind:MonitoringTargetmetadata:# Choose the same namespace as the workload pods.namespace:PROJECT_NAMESPACEname:MONITORING_TARGET_NAMEspec:[...]podMetricsEndpoints:[...]metricsRelabelings:-action:replacetargetLabel:my_new_labelreplacement:my_label_value[...]
apiVersion:monitoring.gdc.goog/v1kind:MonitoringTargetmetadata:# Choose the same namespace as the workload pods.namespace:PROJECT_NAMESPACEname:MONITORING_TARGET_NAMEspec:[...]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 (世界標準時間)。"],[],[],null,["# Label metrics\n\nLabels let you differentiate the characteristics of a metric. In addition to\n[collecting metrics](/distributed-cloud/hosted/docs/latest/appliance/platform/pa-user/collect-metrics), the\n`MonitoringTarget` custom resource lets you label metrics for optional\nobservability features:\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:** Each unique combination of key-value label pairs creates a new time series, which can significantly increase data storage. Avoid using labels for high-cardinality dimensions (many possible values), like user IDs or email addresses.\n\nFor more information on metrics relabeling, see\n\u003chttps://grafana.com/blog/2022/03/21/how-relabeling-in-prometheus-works/\u003e.\n\nBefore you begin\n----------------\n\nTo get the permissions that you need to manage `MonitoringTarget` custom\nresources, ask your Organization IAM Admin or Project IAM Admin to grant you one\nof the associated `MonitoringTarget` roles.\n\nDepending on the level of access and permissions you need, you might obtain\ncreator, editor, or viewer roles for this resource in an organization or a\nproject. For more information, see [Prepare IAM permissions](/distributed-cloud/hosted/docs/latest/appliance/platform/pa-user/obs-iam-permissions).\n\nSend metrics to another project\n-------------------------------\n\nContainer authors can code specific metrics to be sent to a different project, even to projects they don't own. To send a metric to a specific project, add the\n`_gdch_project` label to the metric in your code, setting its value to the destination project name.\n\nAlternatively, use the `MonitoringTarget` custom resource to send *all* collected metric data to another project. Set the `_gdch_project` label as a target label in the `metricsRelabelings` field, with the new project name as the replacement value.\n\nThe following code sample shows how to set the `_gdch_project` target label in the `MonitoringTarget` custom resource to send metrics to the project named `another-project-name`: \n\n apiVersion: monitoring.gdc.goog/v1\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: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eMONITORING_TARGET_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n [...]\n podMetricsEndpoints:\n [...]\n metricsRelabelings:\n - action: replace\n targetLabel: _gdch_project\n replacement: another-project-name\n [...]\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e: your project namespace.\n- \u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e: the name of the `MonitoringTarget` definition file.\n\nAdd new labels to metrics\n-------------------------\n\nLabels help with observability and monitoring by identifying metric characteristics. You can add labels that the scraped containers don't initially expose. In the `MonitoringTarget` custom resource, set the new label as a target label and provide a replacement value. This key-value pair is added to all metrics the\nresource collects.\n\nThe following code sample shows how to set the `my_new_label` target label and configure its value to `my_label_value` in the `MonitoringTarget` custom resource: \n\n apiVersion: monitoring.gdc.goog/v1\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: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eMONITORING_TARGET_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n [...]\n podMetricsEndpoints:\n [...]\n metricsRelabelings:\n - action: replace\n targetLabel: my_new_label\n replacement: my_label_value\n [...]\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e: your project namespace.\n- \u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e: the name of the `MonitoringTarget` definition file.\n\nRename a metric\n---------------\n\nYou can rename a container's metric using the `MonitoringTarget` resource. Set\nthe original metric name and its replacement in the `metricsRelabelings` field.\nThe original name is treated as a regular expression (regex) and is replaced by\nthe new name.\n\nThe following code sample shows how to replace the `cpu_usage` metric name\n(regex) with `cpu_usage_new_name` in the `MonitoringTarget` custom resource: \n\n apiVersion: monitoring.gdc.goog/v1\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: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eMONITORING_TARGET_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n [...]\n podMetricsEndpoints:\n [...]\n metricsRelabelings:\n - action: replace\n regex: cpu_usage\n replacement: cpu_usage_new_name\n sourceLabels: [__name__]\n targetLabel: __name__\n [...]\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e: your project namespace.\n- \u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e: the name of the `MonitoringTarget` definition file."]]