Prometheus - aliyun-exporter

2021-09-27

Dockerfile

FROM python:3.8-slim

MAINTAINER hy2900822@126.com

RUN pip3 install werkzeug==0.16.1

WORKDIR /opt

RUN apt-get update \
    && apt-get install git -y \
    && git clone https://github.com/aylei/aliyun-exporter.git --depth 1 \
    && cd aliyun-exporter \
    && python3 setup.py install \
    && rm -rf /opt/aliyun-exporter \
    && apt-get remove git -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN sed -i  '/f unit and not name.endswith/i\        name=name.replace(".", "_")'  /usr/local/lib/python3.8/site-packages/prometheus_client-0.9.0-py3.8.egg/prometheus_client/metrics_core.py

EXPOSE 80
CMD ["aliyun-exporter"]

aliyun-redis-exporter run in k8s

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: aliyun-exporter
    app.kubernetes.io/instance: aliyun-redis-exporter
    app.kubernetes.io/name: aliyun-redis-exporter
  name: aliyun-redis-exporter
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/component: aliyun-exporter
      app.kubernetes.io/instance: aliyun-redis-exporter
      app.kubernetes.io/name: aliyun-redis-exporter
  template:
    metadata:
      labels:
        app.kubernetes.io/component: aliyun-exporter
        app.kubernetes.io/instance: aliyun-redis-exporter
        app.kubernetes.io/name: aliyun-redis-exporter
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app.kubernetes.io/name
                  operator: In
                  values:
                  - aliyun-redis-exporter
              namespaces:
              - monitoring
              topologyKey: kubernetes.io/hostname
            weight: 100
      containers:
      - name: aliyun-redis-exporter
        image: registry-vpc.cn-hangzhou.aliyuncs.com/yqn-prod/aliyun-exporter
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          tcpSocket:
            port: 9525
          periodSeconds: 10
        ports:
        - containerPort: 9525
          name: http
        startupProbe:
          failureThreshold: 20
          httpGet:
            path: /
            port: 9525
            scheme: HTTP
          periodSeconds: 6
          initialDelaySeconds: 10
        ports:
        resources:
          limits:
            cpu: 0.1
            memory: 100Mi
          requests:
            cpu: 0.01
            memory: 10Mi
        terminationMessagePolicy: FallbackToLogsOnError
        volumeMounts:
        - mountPath: /opt/
          name: aliyun-exporter-config
          readOnly: true
        - name: localtime
          mountPath: /etc/localtime
          readOnly: true
      terminationGracePeriodSeconds: 120
      imagePullSecrets:
      - name: ali-login-registry
      volumes:
      - name: aliyun-exporter-config
        secret:
          secretName: aliyun-redis-exporter
      - name: localtime
        hostPath:
          path: /etc/localtime

---

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app.kubernetes.io/component: aliyun-exporter
    app.kubernetes.io/instance: aliyun-redis-exporter
    app.kubernetes.io/name: aliyun-redis-exporter
  name: aliyun-redis-exporter
  namespace: monitoring
spec:
  endpoints:
  - port: http
    interval: 60s
    relabelings:
    - separator: /
      sourceLabels:
      - service
      targetLabel: instance
  selector:
    matchLabels:
      app.kubernetes.io/component: aliyun-exporter
      app.kubernetes.io/instance: aliyun-redis-exporter
      app.kubernetes.io/name: aliyun-redis-exporter

---

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: aliyun-exporter
    app.kubernetes.io/instance: aliyun-redis-exporter
    app.kubernetes.io/name: aliyun-redis-exporter
  name: aliyun-redis-exporter
  namespace: monitoring
spec:
  clusterIP: None
  ports:
  - name: http
    port: 9525
    targetPort: 9525
  selector:
    app.kubernetes.io/component: aliyun-exporter
    app.kubernetes.io/instance: aliyun-redis-exporter
    app.kubernetes.io/name: aliyun-redis-exporter

config明文(用于生成secret)

credential:
  access_key_id: LTAI80hx2zV0kC
  access_key_secret: lt23l6nLWLmYpIpbi6wWvDq
  region_id: cn-hangzhou
metrics:
  acs_kvstore:
  - name: ShardingAvgRt
    period: 60
  - name: ShardingConnectionUsage
    period: 60
  - name: ShardingCpuUsage
    period: 60
  - name: ShardingHitRate
    period: 60
  - name: ShardingIntranetInRatio
    period: 60
  - name: ShardingIntranetOutRatio
    period: 60
  - name: ShardingMemoryUsage
    period: 60
  - name: ShardingQPSUsage
    period: 60
  - name: StandardAvgRt
    period: 60
  - name: StandardConnectionUsage
    period: 60
  - name: StandardCpuUsage
    period: 60
  - name: StandardHitRate
    period: 60
  - name: StandardIntranetInRatio
    period: 60
  - name: StandardIntranetOutRatio
    period: 60
  - name: StandardMemoryUsage
    period: 60
  - name: StandardQPSUsage
    period: 60
  - name: FailedCount
    period: 60

info_metrics:
- redis

标题:Prometheus - aliyun-exporter
地址:https://blog.njqhome.com:8443/articles/2021/09/27/1632727134281.html