• k8s-prometheus 数据采集(node redis kubelet等)


    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: prometheus-config
      namespace: kube-ops
    data:
      prometheus.yml: |
        global:
          scrape_interval: 20s
          scrape_timeout: 20s
        scrape_configs:
        - job_name: 'prometheus'
          static_configs:
          - targets: ['localhost:9090']
        - job_name: traefik
          static_configs:
            - targets: ['traefik-ingress-service.kube-system.svc.cluster.local:8080']
        - job_name: redis
          static_configs:
            - targets: ['redis:9121']
        - job_name: 'kubernetes-nodes'
          kubernetes_sd_configs:
          - role: node
          relabel_configs:
          - source_labels: [__address__]
            regex: '(.*):10250'
            replacement: '${1}:9100'
            target_label: __address__
            action: replace
          - action: labelmap
            regex: __meta_kubernetes_node_label_(.+)
        - job_name: 'kubelet'
          scheme: https
          tls_config:
            ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
          bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
          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

    下面是解释每个字段意思:

    - job_name: 'kubelet'
      # 通过https访问apiserver,通过apiserver的api获取数据
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
              
      #以k8s的角色(role)来定义收集,比如node,service,pod,endpoints,ingress等等 
      kubernetes_sd_configs:
      # 从k8s的node对象获取数据
      - role: node
      relabel_configs:
      # 用新的前缀代替原label name前缀,没有replacement的话功能就是去掉label_name前缀
      # 例如:以下两句的功能就是将__meta_kubernetes_node_label_kubernetes_io_hostname
      # 变为kubernetes_io_hostname
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
      # replacement中的值将会覆盖target_label中指定的label name的值,
      # 即__address__的值会被替换为kubernetes.default.svc:443
      - target_label: __address__
        replacement: kubernetes.default.svc:443
        #replacement: 10.142.21.21:6443
      # 获取__meta_kubernetes_node_name的值
      - source_labels: [__meta_kubernetes_node_name]
        #匹配一个或多个任意字符,将上述source_labels的值生成变量
        regex: (.+)
        # 将# replacement中的值将会覆盖target_label中指定的label name的值,
        # 即__metrics_path__的值会被替换为/api/v1/nodes/${1}/proxy/metrics,
        # 其中${1}的值会被替换为__meta_kubernetes_node_name的值
        target_label: __metrics_path__
        replacement: /api/v1/nodes/${1}/proxy/metrics
      #or:
      #- source_labels: [__address__]
      #  regex: '(.*):10250'
      #  replacement: '${1}:4194'
      #  target_label: __address__
      #- source_labels: [__meta_kubernetes_node_label_role]
      #  action: replace
      #  target_label: role
  • 相关阅读:
    学习方法:费曼学习方法
    学习方法:天才的秘密
    学习方法:学习的大致过程
    OS:VM虚拟机连不上网络
    cpp:argc和argv的应用
    baidu:{{!!}}
    os:windows许可证书位置
    书法:练字的心得体会
    修复Python终端中敲击方向键显示 [ ^[[A, ^[[B, ^[[C, ^[[D ]
    jquery下removeClass(“oldClassName”).addClass("newClassName")的问题
  • 原文地址:https://www.cnblogs.com/fuyuteng/p/11168853.html
Copyright © 2020-2023  润新知