云原生监控系统Prometheus——Exporter(Elasticsearch监控)

Exporter(Elasticsearch监控)

一、部署 elasticsearch_exporter

  不多bb,直接上配置清单 yaml文件:

kind: Pod
apiVersion: v1
metadata:
  name: elastic-j9qoiy-elasticsearch-exporter-598c9b47b8-vnd2p
  generateName: elastic-j9qoiy-elasticsearch-exporter-598c9b47b8-
  namespace: devops-elasticsearch-test
  labels:
    app: elasticsearch-exporter
    pod-template-hash: 598c9b47b8
    release: elastic-j9qoiy
  annotations:
    cni.projectcalico.org/containerID: 7ff05e8f80d31f38d553f592430dfa0a364541bf454da5f628a1a0810d7dd6fd
    cni.projectcalico.org/podIP: 10.233.68.42/32
    cni.projectcalico.org/podIPs: 10.233.68.42/32
    k8s.v1.cni.cncf.io/network-status: |-
      [{
          "name": "k8s-pod-network",
          "ips": [
              "10.233.68.42"
          ],
          "default": true,
          "dns": {}
      }]
    k8s.v1.cni.cncf.io/networks-status: |-
      [{
          "name": "k8s-pod-network",
          "ips": [
              "10.233.68.42"
          ],
          "default": true,
          "dns": {}
      }]
    kubesphere.io/creator: admin
spec:
  volumes:
    - name: kube-api-access-jk9l6
      projected:
        sources:
          - serviceAccountToken:
              expirationSeconds: 3607
              path: token
          - configMap:
              name: kube-root-ca.crt
              items:
                - key: ca.crt
                  path: ca.crt
          - downwardAPI:
              items:
                - path: namespace
                  fieldRef:
                    apiVersion: v1
                    fieldPath: metadata.namespace
        defaultMode: 420
  containers:
    - name: elasticsearch-exporter
      image: 'justwatch/elasticsearch_exporter:1.1.0'
      command:
        - elasticsearch_exporter
        - '--es.uri=http://localhost:9200'
        - '--es.all'
        - '--es.indices'
        - '--es.indices_settings'
        - '--es.shards'
        - '--es.snapshots'
        - '--es.timeout=30s'
        - '--web.listen-address=:9108'
        - '--web.telemetry-path=/metrics'
      ports:
        - name: http
          containerPort: 9108
          protocol: TCP
      resources: {}
      volumeMounts:
        - name: kube-api-access-jk9l6
          readOnly: true
          mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      livenessProbe:
        httpGet:
          path: /healthz
          port: http
          scheme: HTTP
        initialDelaySeconds: 5
        timeoutSeconds: 5
        periodSeconds: 5
        successThreshold: 1
        failureThreshold: 3
      readinessProbe:
        httpGet:
          path: /healthz
          port: http
          scheme: HTTP
        initialDelaySeconds: 1
        timeoutSeconds: 5
        periodSeconds: 5
        successThreshold: 1
        failureThreshold: 3
      lifecycle:
        preStop:
          exec:
            command:
              - /bin/bash
              - '-c'
              - sleep 20
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: IfNotPresent
      securityContext:
        capabilities:
          drop:
            - SETPCAP
            - MKNOD
            - AUDIT_WRITE
            - CHOWN
            - NET_RAW
            - DAC_OVERRIDE
            - FOWNER
            - FSETID
            - KILL
            - SETGID
            - SETUID
            - NET_BIND_SERVICE
            - SYS_CHROOT
            - SETFCAP
        readOnlyRootFilesystem: true
  restartPolicy: Always
  terminationGracePeriodSeconds: 30
  dnsPolicy: ClusterFirst
  serviceAccountName: default
  serviceAccount: default
  nodeName: k8s-workernode-2-128
  securityContext:
    runAsUser: 1000
    runAsNonRoot: true
  schedulerName: default-scheduler
  tolerations:
    - key: node.kubernetes.io/not-ready
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
    - key: node.kubernetes.io/unreachable
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
  priority: 0
  enableServiceLinks: true
  preemptionPolicy: PreemptLowerPriority  

二、与 Prometheus 集成

  与 Prometheus 的配置文件 prometheus.yaml 中的 static_configs 模块内,继续追加配置内容来采集 elasticsearch_exporter 提供的数据。添加的参考配置内容如下: 

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
	
  - job_name: "elasticsearch_exporter"
    static_configs:
	  - targets: ["192.168.2.121:9108"]
posted @ 2022-07-15 23:20  左扬  阅读(711)  评论(0编辑  收藏  举报
levels of contents