컨테이너 작성자는 프로젝트가 다른 GDC 페르소나에 해당하는 경우에도 시스템 모니터링을 위해 시스템이 특정 측정항목을 다른 프로젝트로 전송해야 한다고 코드에 작성할 수 있습니다. 특정 프로젝트에 측정항목을 전송하려면 코드의 측정항목에 _gdch_project 라벨을 추가합니다. 값을 특정 관측 가능성 측정항목을 소유할 프로젝트의 이름으로 설정합니다. 예를 들면 "_gdch_project": "another-project-name"입니다.
또는 MonitoringTarget 맞춤 리소스를 사용하여 수집된 모든 측정항목 데이터를 데이터 관찰 가능성을 위해 다른 프로젝트로 전송합니다. 이렇게 하려면 _gdch_project 라벨을 metricsRelabelings 필드의 타겟 라벨로 설정하고 대체 값을 설정합니다.
다음 코드 샘플은 MonitoringTarget 커스텀 리소스에서 _gdch_project 라벨 값을 another-project-name로 바꾸는 방법을 보여줍니다.
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
PROJECT_NAMESPACE을 프로젝트의 네임스페이스로 바꿉니다.
측정항목에 새 라벨 추가
라벨은 측정항목의 다양한 특성을 식별할 수 있으므로 데이터 관측 가능성 및 시스템 모니터링에 유용합니다. 스크랩된 컨테이너가 처음에는 노출하지 않는 측정항목에 새 라벨을 추가할 수 있습니다. MonitoringTarget 맞춤 리소스에서 새 라벨을 타겟으로 설정하고 라벨의 값으로 제공할 대체 항목을 설정합니다. 시스템은 데이터 관측 가능성 목적으로 맞춤 리소스가 수집하는 모든 측정항목에 새 키-값 쌍을 추가합니다.
다음 코드 샘플은 MonitoringTarget 맞춤 리소스에서 my_new_label 라벨을 추가하고 값을 my_label_value로 설정하는 방법을 보여줍니다.
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
PROJECT_NAMESPACE을 프로젝트의 네임스페이스로 바꿉니다.
측정항목 이름 바꾸기
MonitoringTarget CR에서 컨테이너가 생성하는 측정항목의 이름을 완전히 바꿀 수 있습니다. metricsRelabelings 필드에 측정항목의 원래 이름과 대체 이름을 설정합니다. 맞춤 리소스는 원래 측정항목 이름을 정규 표현식으로 가져와 추가한 새 이름으로 바꿉니다.
다음 코드 샘플은 MonitoringTarget CR에서 cpu_usage 측정항목 이름을 cpu_usage_new_name으로 바꾸는 방법을 보여줍니다.
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(UTC)"],[[["\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."]]