5.9.3. 서비스 모니터


ServiceMonitorService 오브젝트에서 Endpoints를 검색하고 해당 Pod를 모니터링하도록 Prometheus를 구성하는 Prometheus Operator에서 제공하는 사용자 정의 리소스입니다.

Operator SDK를 사용하여 생성한 Go 기반 Operator에서는 GenerateServiceMonitor() 도우미 함수에서 Service 오브젝트를 가져와서 이를 기반으로 ServiceMonitor 오브젝트를 생성할 수 있습니다.

추가 리소스

5.9.3.1. 서비스 모니터 생성

Operator 작성자는 metrics.CreateServiceMonitor() 도우미 함수를 사용하여 생성한 모니터링 서비스에 대한 서비스 대상 검색 기능을 추가하여 새로 생성한 서비스를 허용할 수 있습니다.

사전 요구 사항

  • Operator SDK를 사용하여 Go 기반 Operator가 생성됨
  • Kubernetes 기반 클러스터에 Prometheus Operator가 배포됨

프로세스

  • Operator 코드에 metrics.CreateServiceMonitor() 도우미 함수를 추가합니다.

    import(
        "k8s.io/api/core/v1"
        "github.com/operator-framework/operator-sdk/pkg/metrics"
        "machine.openshift.io/controller-runtime/pkg/client/config"
    )
    func main() {
    
        ...
        // Populate below with the Service(s) for which you want to create ServiceMonitors.
        services := []*v1.Service{}
        // Create one ServiceMonitor per application per namespace.
        // Change the below value to name of the Namespace you want the ServiceMonitor to be created in.
        ns := "default"
        // restConfig is used for talking to the Kubernetes apiserver
        restConfig := config.GetConfig()
    
        // Pass the Service(s) to the helper function, which in turn returns the array of ServiceMonitor objects.
        serviceMonitors, err := metrics.CreateServiceMonitors(restConfig, ns, services)
        if err != nil {
            // Handle errors here.
        }
        ...
    }
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.