Skip to content

Commit

Permalink
fix mongodb replica set lag awalys 0 #1449 (#2125)
Browse files Browse the repository at this point in the history
  • Loading branch information
im-vincent authored and sparrc committed Dec 16, 2016
1 parent 9c8f246 commit e8bf968
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions plugins/inputs/mongodb/mongostat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"sort"
"strings"
"time"

"gopkg.in/mgo.v2/bson"
)

const (
Expand Down Expand Up @@ -105,10 +103,10 @@ type ReplSetStatus struct {

// ReplSetMember stores information related to a replica set member
type ReplSetMember struct {
Name string `bson:"name"`
State int64 `bson:"state"`
StateStr string `bson:"stateStr"`
OptimeDate *bson.MongoTimestamp `bson:"optimeDate"`
Name string `bson:"name"`
State int64 `bson:"state"`
StateStr string `bson:"stateStr"`
OptimeDate time.Time `bson:"optimeDate"`
}

// WiredTiger stores information related to the WiredTiger storage engine.
Expand Down Expand Up @@ -712,9 +710,9 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
}
}

if me.OptimeDate != nil && master.OptimeDate != nil && me.State == 2 {
// MongoTimestamp type is int64 where the first 32bits are the unix timestamp
lag := int64(*master.OptimeDate>>32 - *me.OptimeDate>>32)
if me.State == 2 {
// OptimeDate.Unix() type is int64
lag := master.OptimeDate.Unix() - me.OptimeDate.Unix()
if lag < 0 {
returnVal.ReplLag = 0
} else {
Expand Down

0 comments on commit e8bf968

Please sign in to comment.