繁体   English   中英

MongoDB Prometheus 导出器未废弃所有指标

[英]MongoDB Prometheus exporter not scrapping all metrics

我有一个带有指标导出器边车的 Mongo 部署。 现在,当我在 Grafana 中加载相关的仪表板时,指标没有显示——导出器似乎没有废弃所有指标:

短跑

什么是工作

只有 Mongo UP 指标在工作。 e mongodb_up{env=~""}和服务器指标的一部分

什么不起作用

仪表板中的以下所有指标均未显示任何数据: opscounters、复制集指标、Cursor 指标

我的配置:Deployment.yaml(使用Percona MongoDB Exporter

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

指标-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

服务.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版本作为 sidecar。 它产生完全相同的结果:

     - 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: {} ```
  2. 我遵循此处给出的参考实现,并且已将 clusterMonitor 角色添加到 db 用户,如下所示:

    db.grantRolesToUser("root",[{ role: "clusterMonitor", db: "admin" }, { role: "read", db: "local" }])

当我执行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"
                ]
        }
]

即使在授予这些角色之后,仪表板仍未加载缺失的指标。

  1. 我已经更新了仪表板 JSON 中的 Prometheus 和 Grafana 版本以匹配我安装的版本(这会影响什么吗?)

我使用的默认仪表板在这里

我错过了什么?

对于任何为此苦苦挣扎的人,我必须为容器添加 --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
   

解决方案来自以下线程:

Github问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM