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"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eLabels in metrics allow for differentiation of metric characteristics, and the \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource offers optional observability features.\u003c/p\u003e\n"],["\u003cp\u003eMetrics can be sent to a different project by adding the \u003ccode\u003e_gdch_project\u003c/code\u003e label or setting it as a target label in the \u003ccode\u003emetricsRelabelings\u003c/code\u003e field of the \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource.\u003c/p\u003e\n"],["\u003cp\u003eNew labels can be added to metrics by specifying them as targets with replacement values in the \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource, improving observability and monitoring.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMonitoringTarget\u003c/code\u003e resource enables the renaming of container metrics by defining the original name (as a regex) and its replacement in the \u003ccode\u003emetricsRelabelings\u003c/code\u003e field.\u003c/p\u003e\n"],["\u003cp\u003eCreating unique label combinations generates new time series, increasing storage requirements, so avoid labels with many possible values, known as high-cardinality dimensions.\u003c/p\u003e\n"]]],[],null,["# Label metrics\n\nLabels let you differentiate the characteristics of a metric. In addition to\n[collecting metrics](/distributed-cloud/hosted/docs/latest/gdch/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/gdch/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,\neven 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\ndestination project name.\n\nAlternatively, use the `MonitoringTarget` custom resource to send *all*\ncollected metric data to another project. Set the `_gdch_project` label as a\ntarget label in the `metricsRelabelings` field, with the new project name as the\nreplacement value.\n\nThe following code sample shows how to set the `_gdch_project` target label in\nthe `MonitoringTarget` custom resource to send metrics to the project\nnamed `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\ncharacteristics. You can add labels that the scraped containers don't initially\nexpose. In the `MonitoringTarget` custom resource, set the new label as a target\nand 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\nconfigure its value to `my_label_value` in the `MonitoringTarget` custom\nresource: \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."]]