using MongoDB server version: 4.2.22
ii mongodb-org-server 4.2.22 amd64 MongoDB database server
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
I m trying to setup a monitoring on GCP - > MongoDB | Cloud Monitoring | Google Cloud
I can get the metric by
adding a new user for the monitoring :
db.getSiblingDB("admin").createUser(
{
user: "metricUser",
pwd: "Password123@",
roles: ["clusterMonitor"],
})
metrics works !
but from the metric scraping process (google-cloud-ops-agent-opentelemetry-collector.service),
I get the following errors every 30seconds :
Jan 19 15:41:50 mongo-server-2.private.xxxx.com otelopscol[543784]: 2023-01-19T15:41:50.280Z debug scraperhelper/scrapercontroller.go:197 Error scraping metrics {"error": "failed to fetch index stats metrics: (Unauthorized) not authorized on local to execute command { aggregate: \"system.replset\", pipeline: [ { $indexStats: {} } ], cursor: {}, lsid: { id: UUID(\"df5c11f9-e865-45d7-8c11-aeb6e1cdeddd\") }, $clusterTime: { clusterTime: Timestamp(1674142905, 1), signature: { hash: BinData(0, 9161B7FBCD2C952834EA0DAB5B87B6153B3BE5CA), keyId: 7138546094778089478 } }, $db: \"local\", $readPreference: { mode: \"primary\" } }", "scraper": "mongodb"}
Jan 19 15:41:50 mongo-server-2.private..xxxx.com otelopscol[543784]: go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).scrapeMetricsAndReport
Jan 19 15:41:50 mongo-server-2.private.xxxx.com otelopscol[543784]: /root/go/pkg/mod/go.opentelemetry.io/collector@v0.61.0/receiver/scraperhelper/scrapercontroller.go:197
Jan 19 15:41:50 mongo-server-2.private.xxxx.com otelopscol[543784]: go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).startScraping.func1
Jan 19 15:41:50 mongo-server-2.private.xxxx.com otelopscol[543784]: /root/go/pkg/mod/go.opentelemetry.io/collector@v0.61.0/receiver/scraperhelper/scrapercontroller.go:172
from mongo logs every 30seconds:
2023-01-20T17:02:36.891+0000 I ACCESS [conn67] Unauthorized: not authorized on local to execute command { aggregate: "system.replset", pipeline: [ { $indexStats: {} } ], cursor: {}, lsid: { id: UUID("ec721915-45ce-4ac5-a8be-99c676afba63") }, $clusterTime: { clusterTime: Timestamp(1674234148, 1), signature: { hash: BinData(0, F171EA196DF7052781BD2A4B04117F0108CFC181), keyId: 7138546094778089478 } }, $db: "local", $readPreference: { mode: "primary" } }
2023-01-20T17:03:06.892+0000 I ACCESS [conn67] Unauthorized: not authorized on local to execute command { aggregate: "system.replset", pipeline: [ { $indexStats: {} } ], cursor: {}, lsid: { id: UUID("ec721915-45ce-4ac5-a8be-99c676afba63") }, $clusterTime: { clusterTime: Timestamp(1674234178, 1), signature: { hash: BinData(0, F8BF81DE3805E58A97310628BAB162337F481413), keyId: 7138546094778089478 } }, $db: "local", $readPreference: { mode: "primary" } }
2023-01-20T17:03:36.892+0000 I ACCESS [conn67] Unauthorized: not authorized on local to execute command { aggregate: "system.replset", pipeline: [ { $indexStats: {} } ], cursor: {}, lsid: { id: UUID("ec721915-45ce-4ac5-a8be-99c676afba63") }, $clusterTime: { clusterTime: Timestamp(1674234208, 1), signature: { hash: BinData(0, F02AE9EC78F26A6525DDE4363D2ABDD0A602501E), keyId: 7138546094778089478 } }, $db: "local", $readPreference: { mode: "primary" } }
I added also this role: readAnyDatabase to metricUser user but still getting the noisy Unauthorized
errors log.
db.getRole("clusterMonitor",{showPrivileges:true})
{
"role" : "clusterMonitor",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ],
"privileges" : [
{
"resource" : {
"cluster" : true
},
"actions" : [
"checkFreeMonitoringStatus",
"connPoolStats",
"getCmdLineOpts",
"getLog",
"getParameter",
"getShardMap",
"hostInfo",
"inprog",
"listDatabases",
"listSessions",
"listShards",
"netstat",
"replSetGetConfig",
"replSetGetStatus",
"serverStatus",
"shardingState",
"top",
"useUUID"
]
},
{
"resource" : {
"db" : "",
"collection" : ""
},
"actions" : [
"collStats",
"dbStats",
"getDatabaseVersion",
"getShardVersion",
"indexStats"
]
},
{
"resource" : {
"db" : "config",
"collection" : ""
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"getDatabaseVersion",
"getShardVersion",
"indexStats",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "local",
"collection" : ""
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"getDatabaseVersion",
"getShardVersion",
"indexStats",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "local",
"collection" : "system.js"
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "config",
"collection" : "system.js"
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "local",
"collection" : "system.replset"
},
"actions" : [
"find"
]
},
{
"resource" : {
"db" : "",
"collection" : "system.profile"
},
"actions" : [
"find"
]
}
],
"inheritedPrivileges" : [
{
"resource" : {
"cluster" : true
},
"actions" : [
"checkFreeMonitoringStatus",
"connPoolStats",
"getCmdLineOpts",
"getLog",
"getParameter",
"getShardMap",
"hostInfo",
"inprog",
"listDatabases",
"listSessions",
"listShards",
"netstat",
"replSetGetConfig",
"replSetGetStatus",
"serverStatus",
"shardingState",
"top",
"useUUID"
]
},
{
"resource" : {
"db" : "",
"collection" : ""
},
"actions" : [
"collStats",
"dbStats",
"getDatabaseVersion",
"getShardVersion",
"indexStats"
]
},
{
"resource" : {
"db" : "config",
"collection" : ""
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"getDatabaseVersion",
"getShardVersion",
"indexStats",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "local",
"collection" : ""
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"getDatabaseVersion",
"getShardVersion",
"indexStats",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "local",
"collection" : "system.js"
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "config",
"collection" : "system.js"
},
"actions" : [
"changeStream",
"collStats",
"dbHash",
"dbStats",
"find",
"killCursors",
"listCollections",
"listIndexes",
"planCacheRead"
]
},
{
"resource" : {
"db" : "local",
"collection" : "system.replset"
},
"actions" : [
"find"
]
},
{
"resource" : {
"db" : "",
"collection" : "system.profile"
},
"actions" : [
"find"
]
}
]
}