PT-50 Fixed oplog counters

This commit is contained in:
Carlos Salguero
2016-12-21 14:33:04 -03:00
parent dcab9e3393
commit aa068ea4fe
5 changed files with 94 additions and 24 deletions

View File

@@ -476,20 +476,51 @@ func getNodeType(session pmgo.SessionManager) (string, error) {
func GetOpCountersStats(session pmgo.SessionManager, count int64, sleep time.Duration) (*opCounters, error) {
oc := &opCounters{}
previousoc := &opCounters{}
ss := proto.ServerStatus{}
err := session.DB("admin").Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, &ss)
if err != nil {
return nil, errors.Wrap(err, "GetOpCountersStats.ServerStatus")
}
ticker := time.NewTicker(sleep)
for i := int64(0); i < count-1; i++ {
for i := int64(0); i < count; i++ {
<-ticker.C
err := session.DB("admin").Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, &ss)
if err != nil {
panic(err)
}
if i == 0 {
previousoc.Command.Total = ss.Opcounters.Command
previousoc.Delete.Total = ss.Opcounters.Delete
previousoc.GetMore.Total = ss.Opcounters.GetMore
previousoc.Insert.Total = ss.Opcounters.Insert
previousoc.Query.Total = ss.Opcounters.Query
previousoc.Update.Total = ss.Opcounters.Update
continue
}
ss.Opcounters.Command -= previousoc.Command.Total
ss.Opcounters.Delete -= previousoc.Delete.Total
ss.Opcounters.GetMore -= previousoc.GetMore.Total
ss.Opcounters.Insert -= previousoc.Insert.Total
ss.Opcounters.Query -= previousoc.Query.Total
ss.Opcounters.Update -= previousoc.Update.Total
// Be careful. This cannot be item[0] because we need value - prev_value
// and at pos 0 there is no prev value
if i == 1 {
oc.Command.Max = ss.Opcounters.Command
oc.Command.Min = ss.Opcounters.Command
oc.Delete.Max = ss.Opcounters.Delete
oc.Delete.Min = ss.Opcounters.Delete
oc.GetMore.Max = ss.Opcounters.GetMore
oc.GetMore.Min = ss.Opcounters.GetMore
oc.Insert.Max = ss.Opcounters.Insert
oc.Insert.Min = ss.Opcounters.Insert
oc.Query.Max = ss.Opcounters.Query
oc.Query.Min = ss.Opcounters.Query
oc.Update.Max = ss.Opcounters.Update
oc.Update.Min = ss.Opcounters.Update
}
// Insert
if ss.Opcounters.Insert > oc.Insert.Max {
oc.Insert.Max = ss.Opcounters.Insert
@@ -543,6 +574,14 @@ func GetOpCountersStats(session pmgo.SessionManager, count int64, sleep time.Dur
oc.GetMore.Min = ss.Opcounters.GetMore
}
oc.GetMore.Total += ss.Opcounters.GetMore
previousoc.Insert.Total = ss.Opcounters.Insert
previousoc.Query.Total = ss.Opcounters.Query
previousoc.Command.Total = ss.Opcounters.Command
previousoc.Update.Total = ss.Opcounters.Update
previousoc.Delete.Total = ss.Opcounters.Delete
previousoc.GetMore.Total = ss.Opcounters.GetMore
}
ticker.Stop()

View File

@@ -25,21 +25,25 @@ func TestGetOpCounterStats(t *testing.T) {
ss := proto.ServerStatus{}
test.LoadJson("test/sample/serverstatus.json", &ss)
// serverStatus for getOpCountersStats
session.EXPECT().DB("admin").Return(database)
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
session.EXPECT().DB("admin").Return(database)
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
session.EXPECT().DB("admin").Return(database)
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
session.EXPECT().DB("admin").Return(database)
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
ss = addToCounters(ss, 1)
session.EXPECT().DB("admin").Return(database)
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
var sampleCount int64 = 5
var sampleRate time.Duration = 10 * time.Millisecond // in seconds
expect := timedStats{Min: 0, Max: 473, Total: 1892, Avg: 378}
expect := timedStats{Min: 7, Max: 7, Total: 7, Avg: 1}
os, err := GetOpCountersStats(session, sampleCount, sampleRate)
if err != nil {
@@ -51,6 +55,16 @@ func TestGetOpCounterStats(t *testing.T) {
}
func addToCounters(ss proto.ServerStatus, increment int64) proto.ServerStatus {
ss.Opcounters.Command += increment
ss.Opcounters.Delete += increment
ss.Opcounters.GetMore += increment
ss.Opcounters.Insert += increment
ss.Opcounters.Query += increment
ss.Opcounters.Update += increment
return ss
}
func TestSecurityOpts(t *testing.T) {
cmdopts := []proto.CommandLineOptions{
// 1

View File

@@ -34,12 +34,12 @@
"NumRequests": 522
},
"Opcounters": {
"Insert": 0,
"Query": 22,
"Update": 0,
"Delete": 0,
"GetMore": 0,
"Command": 473
"Insert": 1,
"Query": 2,
"Update": 3,
"Delete": 4,
"GetMore": 5,
"Command": 6
},
"OpcountersRepl": null,
"RecordStats": null,
@@ -55,4 +55,4 @@
"ShardCursorType": null,
"StorageEngine": null,
"WiredTiger": null
}
}