MongoDB Prometheus导出程序未废弃所有指标

1hdlvixo  于 2022-11-22  发布在  Go
关注(0)|答案(1)|浏览(149)

我有一个Mongo部署,带有一个指标导出器侧柜。现在,当我在Grafana中加载相关 Jmeter 板时,指标没有显示-似乎导出器没有丢弃所有指标:

什么在起作用

只有Mongo UP指标起作用,即mongodb_up{env=~""}和 * 部分 * 服务器指标

什么不起作用

Jmeter 板中的以下所有度量均未显示任何数据:操作计数器、复制集度量、游标度量
我的配置:部署.yaml(使用***Percona MongoDB导出程序***)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-prom
  namespace: "labs"
  labels:
    app.kubernetes.io/name: mongodb
    helm.sh/chart: mongodb-12.1.12
    app.kubernetes.io/instance: mongodb-prom
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: mongodb
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb
      app.kubernetes.io/instance: mongodb-prom
      app.kubernetes.io/component: mongodb
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb
        helm.sh/chart: mongodb-12.1.12
        app.kubernetes.io/instance: mongodb-prom
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: mongodb
    spec:
  
  serviceAccountName: mongodb-prom
  affinity:
      
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: mongodb
                app.kubernetes.io/instance: mongodb-prom
                app.kubernetes.io/component: mongodb
            namespaces:
              - "labs"
            topologyKey: kubernetes.io/hostname
          weight: 100
      
  securityContext:
    fsGroup: 1001
    sysctls: []
  
  containers:
    - name: mongodb
      image: docker.io/bitnami/mongodb:5.0.9-debian-10-r15
      imagePullPolicy: "IfNotPresent"
      securityContext:
        runAsNonRoot: true
        runAsUser: 1001
      env:
        - name: BITNAMI_DEBUG
          value: "false"
        - name: MONGODB_ROOT_USER
          value: "root"
        - name: MONGODB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-prom
              key: mongodb-root-password
        - name: ALLOW_EMPTY_PASSWORD
          value: "no"
        - name: MONGODB_SYSTEM_LOG_VERBOSITY
          value: "0"
        - name: MONGODB_DISABLE_SYSTEM_LOG
          value: "no"
        - name: MONGODB_DISABLE_JAVASCRIPT
          value: "no"
        - name: MONGODB_ENABLE_JOURNAL
          value: "yes"
        - name: MONGODB_PORT_NUMBER
          value: "27017"
        - name: MONGODB_ENABLE_IPV6
          value: "no"
        - name: MONGODB_ENABLE_DIRECTORY_PER_DB
          value: "no"
      ports:
        - name: mongodb
          containerPort: 27017
      
      volumeMounts:
        - name: datadir
          mountPath: /bitnami/mongodb
        - name: datadir
          mountPath: /tmp           
    - name: metrics
      image: percona/mongodb_exporter:0.35
      imagePullPolicy: "IfNotPresent"
      args:
      - "--mongodb.direct-connect=false"
      - "--mongodb.uri=mongodb://username:password@mongodb-prom/admin"
      ports:
        - name: metrics
          containerPort: 9216
      resources:
        requests:
          memory: 128Mi
          cpu: 250m
  volumes:
    - name: datadir
      persistentVolumeClaim:
        claimName: mongodb

metrics-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: mongodb-metrics
  namespace: "labs"
  labels:
    app.kubernetes.io/name: mongodb
    helm.sh/chart: mongodb-12.1.12
    app.kubernetes.io/instance: mongodb-prom
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: metrics
  annotations:
    prometheus.io/path: /metrics
    prometheus.io/port: '9216'
    prometheus.io/scrape: "true"
spec:
  type: ClusterIP
  ports:
    - port: 9216
      targetPort: metrics
      protocol: TCP
      name: http-metrics
  selector:
    app.kubernetes.io/name: mongodb
    app.kubernetes.io/instance: mongodb-prom
    app.kubernetes.io/component: mongodb

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mongodb-prom
  namespace: "labs"
  labels:
    app.kubernetes.io/name: mongodb
    helm.sh/chart: mongodb-12.1.12
    app.kubernetes.io/instance: mongodb-prom
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: mongodb
spec:
  type: ClusterIP
  sessionAffinity: None
  ports:
    - name: "mongodb"
      port: 27017
      targetPort: mongodb
  selector:
    app.kubernetes.io/name: mongodb
    app.kubernetes.io/instance: mongodb-prom
    app.kubernetes.io/component: mongodb

我所尝试的

1.我已经尝试使用***Bitnami MongoDB Exporter***版本的边车。它产生了完全相同的结果:

- name: metrics
      image: docker.io/bitnami/mongodb-exporter:0.32.0-debian-11-r5
      imagePullPolicy: "IfNotPresent"
      securityContext:
        runAsNonRoot: true
        runAsUser: 1001
      command:
        - /bin/bash
        - -ec
      args:
        - |
          /bin/mongodb_exporter --web.listen-address ":9216" --mongodb.uri "mongodb://$MONGODB_ROOT_USER:$(echo $MONGODB_ROOT_PASSWORD | sed -r "s/@/%40/g;s/:/%3A/g")@localhost:27017/admin?" 
      env:
        - name: MONGODB_ROOT_USER
          value: "root"
        - name: MONGODB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-prom
              key: mongodb-root-password
      ports:
        - name: metrics
          containerPort: 9216
      livenessProbe:
        failureThreshold: 3
        initialDelaySeconds: 15
        periodSeconds: 5
        successThreshold: 1
        timeoutSeconds: 5
        httpGet:
          path: /
          port: metrics
      readinessProbe:
        failureThreshold: 3
        initialDelaySeconds: 5
        periodSeconds: 5
        successThreshold: 1
        timeoutSeconds: 1
        httpGet:
          path: /
          port: metrics
      resources:
        limits: {}
        requests: {}
        ```

1.我将遵循给定here的参考实现,并将clusterMonitor角色添加到db用户,如下所示:
将角色授予用户(“root”,[{角色:“群集监视器”,数据库:“管理员”},{角色:“读取”,数据库:“本地”}])
当我执行db.getUsers();的时候

[
        {
                "_id" : "admin.root",
                "userId" : UUID("d8e181fc-6429-447e-bbcb-cec252f0792f"),
                "user" : "root",
                "db" : "admin",
                "roles" : [
                        {
                                "role" : "clusterMonitor",
                                "db" : "admin"
                        },
                        {
                                "role" : "root",
                                "db" : "admin"
                        },
                        {
                                "role" : "read",
                                "db" : "local"
                        }
                ],
                "mechanisms" : [
                        "SCRAM-SHA-1",
                        "SCRAM-SHA-256"
                ]
        }
]

即使在授予这些角色后, Jmeter 板仍无法加载缺少的指标。
1.我已经更新了 Jmeter 板JSON * 中的Prometheus和Grafana版本,以匹配我安装的版本 *(这会有什么影响吗?)
我使用的默认 Jmeter 板是here
我错过了什么?

nhaq1z21

nhaq1z211#

对于任何在这方面有困难的人,我必须为容器添加--collect-all和--compatibility-mode标志,以提取指标,如下面的配置所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-prom
  namespace: "labs"
  labels:
    app.kubernetes.io/name: mongodb
    helm.sh/chart: mongodb-12.1.12
    app.kubernetes.io/instance: mongodb-prom
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: mongodb
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxUnavailable: 1
    type: RollingUpdate  
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb
      app.kubernetes.io/instance: mongodb-prom
      app.kubernetes.io/component: mongodb
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb
        helm.sh/chart: mongodb-12.1.12
        app.kubernetes.io/instance: mongodb-prom
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: mongodb
    spec:
  
  serviceAccountName: mongodb-prom
  affinity:
      
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: mongodb
                app.kubernetes.io/instance: mongodb-prom
                app.kubernetes.io/component: mongodb
            namespaces:
              - "labs"
            topologyKey: kubernetes.io/hostname
          weight: 100
      
  securityContext:
    fsGroup: 1001
    sysctls: []
  
  containers:
    - name: mongodb
      image: docker.io/bitnami/mongodb:5.0.9-debian-10-r15
      imagePullPolicy: "IfNotPresent"
      securityContext:
        runAsNonRoot: true
        runAsUser: 1001
      env:
        - name: BITNAMI_DEBUG
          value: "false"
        - name: MONGODB_ROOT_USER
          value: "root"
        - name: MONGODB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-prom
              key: mongodb-root-password
        - name: ALLOW_EMPTY_PASSWORD
          value: "no"
        - name: MONGODB_SYSTEM_LOG_VERBOSITY
          value: "0"
        - name: MONGODB_DISABLE_SYSTEM_LOG
          value: "no"
        - name: MONGODB_DISABLE_JAVASCRIPT
          value: "no"
        - name: MONGODB_ENABLE_JOURNAL
          value: "yes"
        - name: MONGODB_PORT_NUMBER
          value: "27017"
        - name: MONGODB_ENABLE_IPV6
          value: "no"
        - name: MONGODB_ENABLE_DIRECTORY_PER_DB
          value: "no"
      ports:
        - name: mongodb
          containerPort: 27017
      
      volumeMounts:
        - name: datadir
          mountPath: /bitnami/mongodb
        - name: datadir
          mountPath: /tmp           
    - name: metrics
      image: docker.io/bitnami/mongodb-exporter:0.32.0-debian-11-r5
      imagePullPolicy: "IfNotPresent"
      securityContext:
        runAsNonRoot: true
        runAsUser: 1001
      command:
        - /bin/bash
        - -ec
      args:
        - |
          /bin/mongodb_exporter --web.listen-address ":9216" --mongodb.uri "mongodb://$MONGODB_ROOT_USER:$(echo $MONGODB_ROOT_PASSWORD | sed -r "s/@/%40/g;s/:/%3A/g")@localhost:27017/admin?" --collect-all --compatible-mode 
      env:
        - name: MONGODB_ROOT_USER
          value: "root"
        - name: MONGODB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-prom
              key: mongodb-root-password
      ports:
        - name: metrics
          containerPort: 9216
      livenessProbe:
        failureThreshold: 3
        initialDelaySeconds: 15
        periodSeconds: 5
        successThreshold: 1
        timeoutSeconds: 5
        httpGet:
          path: /
          port: metrics
      readinessProbe:
        failureThreshold: 3
        initialDelaySeconds: 5
        periodSeconds: 5
        successThreshold: 1
        timeoutSeconds: 1
        httpGet:
          path: /
          port: metrics
      resources:
        limits: {}
        requests: {}
  volumes:
    - name: datadir
      persistentVolumeClaim:
        claimName: mongodb

解决方案来自以下线程:
GithubIssue

相关问题