Lower authorization errors to debug level in mongodb input (#4869)
This commit is contained in:
parent
106f5b5ca8
commit
cd865cfd22
plugins/inputs/mongodb
|
@ -3,6 +3,7 @@ package mongodb
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
@ -26,6 +27,10 @@ type oplogEntry struct {
|
||||||
Timestamp bson.MongoTimestamp `bson:"ts"`
|
Timestamp bson.MongoTimestamp `bson:"ts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsAuthorization(err error) bool {
|
||||||
|
return strings.Contains(err.Error(), "not authorized")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) gatherOplogStats() *OplogStats {
|
func (s *Server) gatherOplogStats() *OplogStats {
|
||||||
stats := &OplogStats{}
|
stats := &OplogStats{}
|
||||||
localdb := s.Session.DB("local")
|
localdb := s.Session.DB("local")
|
||||||
|
@ -39,14 +44,22 @@ func (s *Server) gatherOplogStats() *OplogStats {
|
||||||
if err == mgo.ErrNotFound {
|
if err == mgo.ErrNotFound {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Println("E! Error getting first oplog entry (" + err.Error() + ")")
|
if IsAuthorization(err) {
|
||||||
|
log.Println("D! Error getting first oplog entry (" + err.Error() + ")")
|
||||||
|
} else {
|
||||||
|
log.Println("E! Error getting first oplog entry (" + err.Error() + ")")
|
||||||
|
}
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
if err := localdb.C(collection_name).Find(query).Sort("-$natural").Limit(1).One(&op_last); err != nil {
|
if err := localdb.C(collection_name).Find(query).Sort("-$natural").Limit(1).One(&op_last); err != nil {
|
||||||
if err == mgo.ErrNotFound {
|
if err == mgo.ErrNotFound || IsAuthorization(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Println("E! Error getting last oplog entry (" + err.Error() + ")")
|
if IsAuthorization(err) {
|
||||||
|
log.Println("D! Error getting first oplog entry (" + err.Error() + ")")
|
||||||
|
} else {
|
||||||
|
log.Println("E! Error getting first oplog entry (" + err.Error() + ")")
|
||||||
|
}
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +111,11 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool) error
|
||||||
},
|
},
|
||||||
}, &resultShards)
|
}, &resultShards)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("E! Error getting database shard stats (" + err.Error() + ")")
|
if IsAuthorization(err) {
|
||||||
|
log.Println("D! Error getting database shard stats (" + err.Error() + ")")
|
||||||
|
} else {
|
||||||
|
log.Println("E! Error getting database shard stats (" + err.Error() + ")")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oplogStats := s.gatherOplogStats()
|
oplogStats := s.gatherOplogStats()
|
||||||
|
|
Loading…
Reference in New Issue