Prometheus - 收集阿里云slow sql

2021-09-27

使用阿里云accessKey与Secret创建 k8s secret

kubectl -n monitoring create secret generic aliyun-auth-ops --from-literal=ALIYUN_ACCESS_ID=LTAI80hDIGzVs0kC --from-literal=ALIYUN_ACCESS_SECRET=lt23l6nLWLfpIpbi6wWvDq

Deployment aliyun-slow-sql,stdout输出Json

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: aliyun-slow-sql
    app.kubernetes.io/instance: aliyun-slow-sql
    app.kubernetes.io/name: aliyun-slow-sql
  name: aliyun-slow-sql
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/component: aliyun-slow-sql
      app.kubernetes.io/instance: aliyun-slow-sql
      app.kubernetes.io/name: aliyun-slow-sql
  template:
    metadata:
      labels:
        app.kubernetes.io/component: aliyun-slow-sql
        app.kubernetes.io/instance: aliyun-slow-sql
        app.kubernetes.io/name: aliyun-slow-sql
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app.kubernetes.io/name
                  operator: In
                  values:
                  - aliyun-slow-sql
              namespaces:
              - monitoring
              topologyKey: kubernetes.io/hostname
            weight: 100
      containers:
      - args:
        - /opt/aliyun-slow-sql
        - --access.key.id=$(ALIYUN_ACCESS_ID)
        - --access.key.secret=$(ALIYUN_ACCESS_SECRET)
        - --region.id=cn-hangzhou
        - --instance.ids=rm-bp1i2z0rukssjejaf,rm-bp16m0talmy173yp5,rm-bp15x4n41pmm9073i,rm-bp159pbvgo0624v9b,rm-bp143tza4i8pq95y0,rm-bp16091gd2da8kl3s,rm-bp1du2xtrgssr4851,rm-bp14ckfo8e8g38dgr,rm-bp16sur15ombt856z,rm-bp16s6r07u828ed39,rm-bp11i3p3otiq151qd,rm-bp1mc196k00bm0w58,rr-bp17fpxkgayuko9gm,rm-bp1e5y09t9dc9dg1d,sp50404ac9cb3a7
        - --robot.url=ignore
        - --secret=ignore
        image: harbor.njqhome.com:8443/mid/aliyun-slow-sql #https://github.com/Riete/aliyun-slow-sql.git
        imagePullPolicy: IfNotPresent
        name: aliyun-slow-sql
        resources:
          limits:
            cpu: 0.1
            memory: 30Mi
          requests:
            cpu: 0.01
            memory: 10Mi
        env:
        - name: ALIYUN_ACCESS_ID
          valueFrom:
            secretKeyRef:
              key: ALIYUN_ACCESS_ID
              name: aliyun-auth-ops
        - name: ALIYUN_ACCESS_SECRET
          valueFrom:
            secretKeyRef:
              key: ALIYUN_ACCESS_SECRET
              name: aliyun-auth-ops
      imagePullSecrets:
      - name: ali-login-registry

使用阿里云sls收集

apiVersion: log.alibabacloud.com/v1alpha1
kind: AliyunLogConfig
metadata:
  # your config name, must be unique in you k8s cluster
  name: aliyun-slow-sql
spec:
  project: yqn-service
  lifeCycle: 30
  # logstore name to upload log
  logstore: mysql-slowlog
  # logtail config detail
  logtailConfig:
    # docker stdout's input type is 'plugin'
    inputType: plugin
    # logtail config name, should be same with [metadata.name]
    configName: aliyun-slow-sql
    inputDetail:
      plugin:
        inputs:
          -
            # input type
            type: service_docker_stdout
            detail:
              # collect stdout and stderr
              Stdout: true
              Stderr: true
              IncludeLabel:
                "io.kubernetes.container.name": "aliyun-slow-sql"
#              ExcludeEnv:
#                COLLECT_STDOUT_FLAG: "false"
        processors:
          -
            type: processor_json
            detail:
                SourceKey: content
                NoKeyError: true
                KeepSource: false
                ExpandConnector: ""

标题:Prometheus - 收集阿里云slow sql
地址:https://blog.njqhome.com:8443/articles/2021/09/27/1632723681561.html