MonitoringTarget 커스텀 리소스를 관리하는 데 필요한 권한을 얻으려면 조직 IAM 관리자 또는 프로젝트 IAM 관리자에게 연결된 MonitoringTarget 역할 중 하나를 부여해 달라고 요청하세요.
필요한 액세스 수준과 권한에 따라 조직 또는 프로젝트에서 이 리소스에 대한 생성자, 편집자 또는 뷰어 역할을 획득할 수 있습니다. 자세한 내용은 IAM 권한 준비를 참고하세요.
다른 프로젝트로 측정항목 보내기
컨테이너 작성자는 소유하지 않은 프로젝트를 포함하여 다른 프로젝트로 전송할 특정 측정항목을 코딩할 수 있습니다. 특정 프로젝트에 측정항목을 전송하려면 코드의 측정항목에 _gdch_project 라벨을 추가하고 값을 대상 프로젝트 이름으로 설정합니다.
또는 MonitoringTarget 맞춤 리소스를 사용하여 수집된 모든 측정항목 데이터를 다른 프로젝트로 전송합니다. metricsRelabelings 필드에서 _gdch_project 라벨을 타겟 라벨로 설정하고 새 프로젝트 이름을 대체 값으로 사용합니다.
다음 코드 샘플은 MonitoringTarget 커스텀 리소스에서 _gdch_project 타겟 라벨을 설정하여 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:_gdch_projectreplacement:another-project-name[...]
다음을 바꿉니다.
PROJECT_NAMESPACE: 프로젝트 네임스페이스
MONITORING_TARGET_NAME: MonitoringTarget 정의 파일의 이름입니다.
측정항목에 새 라벨 추가
라벨은 측정항목 특성을 식별하여 관측 가능성과 모니터링에 도움이 됩니다. 스크랩된 컨테이너가 처음에는 노출하지 않는 라벨을 추가할 수 있습니다. MonitoringTarget 맞춤 리소스에서 새 라벨을 타겟 라벨로 설정하고 대체 값을 제공합니다. 이 키-값 쌍은 리소스가 수집하는 모든 측정항목에 추가됩니다.
다음 코드 샘플은 MonitoringTarget 커스텀 리소스에서 my_new_label 타겟 라벨을 설정하고 값을 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:replacetargetLabel:my_new_labelreplacement:my_label_value[...]
다음을 바꿉니다.
PROJECT_NAMESPACE: 프로젝트 네임스페이스
MONITORING_TARGET_NAME: MonitoringTarget 정의 파일의 이름입니다.
측정항목 이름 바꾸기
MonitoringTarget 리소스를 사용하여 컨테이너의 측정항목 이름을 바꿀 수 있습니다. metricsRelabelings 필드에 원래 측정항목 이름과 대체 이름을 설정합니다.
원래 이름은 정규 표현식으로 처리되며 새 이름으로 대체됩니다.
다음 코드 샘플은 MonitoringTarget 맞춤 리소스에서 cpu_usage 측정항목 이름(정규식)을 cpu_usage_new_name으로 대체하는 방법을 보여줍니다.
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__[...]
다음을 바꿉니다.
PROJECT_NAMESPACE: 프로젝트 네임스페이스
MONITORING_TARGET_NAME: MonitoringTarget 정의 파일의 이름입니다.
[[["이해하기 쉬움","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)"],[],[],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."]]