Prometheus 서비스 검색 메커니즘

13798 단어 prometheus

카탈로그

  • Prometheus 서비스 발견 메커니즘 개요
  • static_configs: 정적 서비스 발견
  • file_sd_configs: 파일 서비스 발견
  • dns_sd_configs: DNS 서비스 검색
  • kubernetes_sd_configs: Kubernetes 서비스 발견
  • Prometheus의 relabelconfigs 구성 상세 정보:
  • consul_sd_configs: Consul 서비스 검색
  • consul 소개
  • Consul 설치 구성
  • prometheus.yml 구성:
  • Prometheus 서비스 발견 메커니즘 개요


    Prometheus 데이터 원본의 구성은 주로 정적 구성과 동적 발견으로 나뉘는데 주로 다음과 같은 몇 가지 유형으로 사용된다.
  • static_configs: # 정적 서비스 검색
  • file_sd_configs: # 파일 서비스 검색
  • dns_sd_configs: #DNS 서비스 검색
  • kubernetes_sd_configs: #Kubernetes 서비스 발견
  • consul_sd_configs: #Consul 서비스 검색(권장)
  • static_configs: 정적 서비스 발견


    Prometheus.yaml 프로필:
    scrape_configs:
          - job_name: 'prometheus'
            static_configs:
              - targets: ['localhost:9090']
          - job_name: 'grafana'
            static_configs:
              - targets:
                  - 'grafana-service.ns-monitor:3000'
          - job_name: 'kubernetes-apiservers'
    
    

    file_sd_configs: 파일 서비스 발견


    파일 기반 서비스 발견 방식은 다른 플랫폼과 제3자 서비스에 의존할 필요가 없다. 사용자는 새로운 target 정보를 yaml이나 json 파일 형식으로 target 파일에 추가하기만 하면 prometheus는 정기적으로 지정된 파일에서 target 정보를 읽고 업데이트한다.
    target 파일:
    vim targets.json
    [
      {
        "targets": [ "192.168.20.136:9100"],
        "labels": {
          "instance": "nodeone",
          "job": "expor_test1"
        }
      },
      {
        "targets": [ "192.168.20.137:9100"],
        "labels": {
          "instance": "nodetwo",
          "job": "expor_test2"
        }
      }
    ]
    

    Prometheus.yaml 프로필:
    scrape_configs:
    - job_name: 'file_sd'   # 
      file_sd_configs:
        - files:
          - targets.json         # 
    

    웹 인터페이스 targets 보기 targets.json이 정의한 두 개의 job.

    dns_sd_configs: DNS 서비스 검색


    등한시하다

    kubernetes_sd_configs: Kubernetes 서비스 발견


    kubernetes의 경우,Promethues는 Kubernetes API와 상호작용을 한 다음에 자원 단점을 윤문한다.현재 주로 5가지 서비스 발견 모델을 지원하는데 그것이 1:Node, 2:서비스, 3:Pod, 4:Endpoints, 5:Ingress 대응 설정 파일의 Role:node/role:서비스이다.
    모든 노드 node에 대한 정보를 동적으로 가져오며 다음 구성을 추가할 수 있습니다.
  • role: node
  • kubernetes_sd_configs:
            - role: node
            relabel_configs:
            - action: labelmap
              regex: __meta_kubernetes_node_label_(.+)
            - target_label: __address__
              replacement: kubernetes.default.svc:443
            - source_labels: [__meta_kubernetes_node_name]
              regex: (.+)
              target_label: __metrics_path__
              replacement: /api/v1/nodes/${1}/proxy/metrics
    
    
  • role: endpoints
  •       - job_name: 'kubernetes-service-endpoints'
    
            kubernetes_sd_configs:
            - role: endpoints
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
              action: keep
              regex: true
            - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
              action: replace
              target_label: __scheme__
              regex: (https?)
            - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
              action: replace
              target_label: __metrics_path__
              regex: (.+)
            - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
              action: replace
              target_label: __address__
              regex: ([^:]+)(?::\d+)?;(\d+)
              replacement: $1:$2
            - action: labelmap
              regex: __meta_kubernetes_service_label_(.+)
            - source_labels: [__meta_kubernetes_namespace]
              action: replace
              target_label: kubernetes_namespace
            - source_labels: [__meta_kubernetes_service_name]
              action: replace
              target_label: kubernetes_name
    

    대응하는 서비스,pod도 같은 방식이다.주의해야 할 것은 Prometheus가 Kubernetes API를 받을 수 있도록 하기 위해서, 우리는 Prometheus에 대한 접근 권한을 부여해야 한다. 즉 서비스account이다.그렇지 않으면 설정되어 있어도 가져올 권한이 없습니다.

    Prometheus의 relabelconfigs 구성 세부 정보:

  • source_labels: 원본 탭,relabel 처리를 거치지 않은 탭 이름
  • target_label: action 처리를 통해 새 탭 이름
  • regex: 정규 표현식, 일치하는 원본 탭
  • replacement:replacement에서 지정한 바뀐 탭(target label)에 대응하는 수치
  • action: action은 relabel의 동작을 정의하고 action은 여러 가지를 지원한다. 다음과 같다.
  • replace: 탭 값을 바꾸고regex 정규에 따라 원본 탭에 일치하는 값을 목적 탭에 쓰기
  • keep:regex의 정규 조건을 충족시키는 실례를 채집하여sourcelabels에regex 정규 내용에 일치하지 않는Target 실례 잃어버리기
  • drop:regex의 정규 조건을 만족시키는 실례를 채집하지 않고sourcelabels에서regex 정규 내용에 일치하는 Target 실례 잃어버리기
  • labeldrop: 필터 규칙에 맞는 target 탭을 캡처하여 삭제
  • labelkeep: 필터 규칙에 맞는 target 라벨을 캡처하여 보존
  • labelmap은regex의 정의에 따라Target 실례의 모든 탭의 이름을 매칭하고 매칭된 내용을 새로운 탭의 이름으로 하며 그 값은 새 탭의 값으로 한다
  • hashmod 설정 targetlabelmodulus에 연결된 해시 값 소스labels


  • consul_sd_configs: Consul 서비스 검색


    설명


    Consul은 GO 언어를 바탕으로 개발한 소스 오픈 도구로 주로 분포식, 서비스화된 시스템을 대상으로 서비스 등록, 서비스 발견과 설정 관리 기능을 제공한다.Consul은 서비스 등록/검색, 건강 검사, Key/Value 저장소, 다중 데이터 센터와 분포식 일치성 보증 등의 기능을 제공합니다.이전에는 Prometheus를 통해 Target가 추가되었을 때 file 을 사용해도 서버의 프로필을 변경해야 한다는 모니터링을 실현했습니다.sd_configs 설정도 서버에 로그인해서 Json 파일을 수정해야 하기 때문에 매우 번거롭습니다.

    Consul 설치 구성


    대략

    prometheus.yml 구성:

    - job_name: 'consul-prometheus'
      consul_sd_configs:
      - server: '172.30.12.167:8500'
        services: []  
    

    설명: 여기는 consul 을 사용해야 합니다sd_configs는 Consul 서비스 발견 형식을 사용하고 서버가 Consul인 서비스 주소를 설정합니다.구성이 완료되면 Prometheus 서비스를 다시 시작합니다.

    좋은 웹페이지 즐겨찾기