Get database collection document metrics using percona/mongodb_exporter:0.36

Hi

It is possible to get metrics for a specific collection in a database. For example i want to plot on a time graph in grafana the number of objects/documents in my database.collection over time.

We are using percona/mongodb_exporter:0.36

Hello, yes it is possible. Why not deploy PMM which includes this info as a dashboard as well as others?
See Monitoring MongoDB Collection Stats with Percona Monitoring and Management for more info

thank you for linking to the article. We are aware about some of this already.

  • The “Top” stats are not helpful for our usecase as it does not tell us the current state.
  • It appears we are still unable to get the database.collection level stats.

We already have monitoring solution setup to monitor and manage other systems via kube-prometheus-stack which includes Prometheus and grafana. As you can see below we are using a sidecar to deploy the percona/mongodb_exporter

    sidecars:
    - image: percona/mongodb_exporter:0.36
      env:
      - name: EXPORTER_USER
        valueFrom:
          secretKeyRef:
            name: psmdb-db-internal-secrets
            key: MONGODB_CLUSTER_MONITOR_USER
      - name: EXPORTER_PASS
        valueFrom:
          secretKeyRef:
            name: psmdb-db-internal-secrets
            key: MONGODB_CLUSTER_MONITOR_PASSWORD
      - name: POD_IP
        valueFrom:
          fieldRef:
            fieldPath: status.podIP
      - name: MONGODB_URI
        value: "mongodb://$(EXPORTER_USER):$(EXPORTER_PASS)@$(POD_IP):27017"
      args: ["--discovering-mode", "--compatible-mode", "--collect-all", "--mongodb.uri=$(MONGODB_URI)"]

We are using this --collect-all (mongodb_exporter/REFERENCE.md at main · percona/mongodb_exporter · GitHub) flag but we are still not seeing the database.collection level stats. The article suggests this should be possible. We are able to get database stats via mongodb_dbstats_objects{database="test"}

In addition to this, PMM 2.26 also includes the ability to gather database, collection, and index statistics. Using these metrics we can monitor collection counts, data growth, and index usage over time.

Any idea what could be happening here.

I realised this could be related to the permissions we are seeing in our logs

https://perconadev.atlassian.net/browse/PMM-11184

time="2023-08-01T00:53:04Z" level=error msg="cannot auto discover databases and collections: cannot list the collections for \"avatar-store\": cannot get the list of collections for discovery: (Unauthorized) not authorized on avatar-store to execute command { listCollections: 1, filter: {}, nameOnly: true, cursor: {}, lsid: { id: UUID(\"87045589-a8c0-4fd7-800f-3680a205feaa\") }, $clusterTime: { clusterTime: Timestamp(1690851181, 2), signature: { hash: BinData(0, 3AEFD3A070F0C63D712A1CD4CF1AB119BAF0495D), keyId: 7235977075700531206 } }, $db: \"avatar-store\", $readPreference: { mode: \"primaryPreferred\" } }"

{"t":{"$date":"2023-08-01T00:53:04.387+00:00"},"s":"I",  "c":"ACCESS",   "id":20436,   "ctx":"conn27024609","msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on avatar-store to execute command { listCollections: 1, filter: {}, nameOnly: true, cursor: {}, lsid: { id: UUID(\"87045589-a8c0-4fd7-800f-3680a205feaa\") }, $clusterTime: { clusterTime: Timestamp(1690851181, 2), signature: { hash: BinData(0, 3AEFD3A070F0C63D712A1CD4CF1AB119BAF0495D), keyId: 7235977075700531206 } }, $db: \"avatar-store\", $readPreference: { mode: \"primaryPreferred\" } }"}}}

If i try to update the permissions it reverts back instantly

rs0 [direct: primary] admin> db.getSiblingDB("admin").updateUser("clusterMonitor", { roles: [ { role: "explainRole", db: "admin" }, { role: "clusterMonitor", db: "admin" }, { role: "read", db: "local" }, { db: "admin", role: "readWrite", collection: "" }, { db: "admin", role: "backup" }, { db: "admin", role: "clusterMonitor" }, { db: "admin", role: "restore" }, { db: "admin", role: "pbmAnyAction" }] });
{
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1708958831, i: 1 }),
    signature: {
      hash: Binary(Buffer.from("683443a3f3749cc3da1c7ae0f485281dc43ad61e", "hex"), 0),
      keyId: Long("7286379826884116487")
    }
  },
  operationTime: Timestamp({ t: 1708958831, i: 1 })
}
rs0 [direct: primary] admin> db.getUser("clusterMonitor")
{
  _id: 'admin.clusterMonitor',
  userId: UUID("2d15ad6c-b2b1-4a51-a50e-ac1c08109e4d"),
  user: 'clusterMonitor',
  db: 'admin',
  roles: [
    { role: 'read', db: 'local' },
    { role: 'explainRole', db: 'admin' },
    { role: 'pbmAnyAction', db: 'admin' },
    { role: 'restore', db: 'admin' },
    { role: 'readWrite', db: 'admin' },
    { role: 'clusterMonitor', db: 'admin' },
    { role: 'backup', db: 'admin' }
  ],
  mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
}
rs0 [direct: primary] admin> db.getUser("clusterMonitor")
{
  _id: 'admin.clusterMonitor',
  userId: UUID("2d15ad6c-b2b1-4a51-a50e-ac1c08109e4d"),
  user: 'clusterMonitor',
  db: 'admin',
  roles: [
    { role: 'explainRole', db: 'admin' },
    { role: 'read', db: 'local' },
    { role: 'clusterMonitor', db: 'admin' }
  ],
  mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
}