mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 21:51:21 +00:00
PT-50 Fixed oplog counters
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
GO := GO15VENDOREXPERIMENT=1 go
|
GO := go
|
||||||
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
|
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
|
||||||
VERSION=$(git describe --tags)
|
VERSION=$(git describe --tags)
|
||||||
BUILD=$(date +%FT%T%z)
|
BUILD=$(date +%FT%T%z)
|
||||||
|
|
||||||
PREFIX=$(shell pwd)
|
PREFIX=$(shell pwd)
|
||||||
BIN_DIR=$(shell pwd)
|
BIN_DIR=$(shell git rev-parse --show-toplevel)/bin
|
||||||
|
LDFLAGS="-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}"
|
||||||
|
|
||||||
|
|
||||||
all: format build test
|
all: format gox test
|
||||||
|
|
||||||
style:
|
style:
|
||||||
@echo ">> checking code style"
|
@echo ">> checking code style"
|
||||||
@@ -25,8 +26,24 @@ vet:
|
|||||||
@echo ">> vetting code"
|
@echo ">> vetting code"
|
||||||
@$(GO) vet $(pkgs)
|
@$(GO) vet $(pkgs)
|
||||||
|
|
||||||
build:
|
build-all:
|
||||||
@echo ">> building binaries"
|
@echo ">> building all binaries in $(BIN_DIR). OS & platform will be appended to the file name"
|
||||||
@$(GO) build -ldflags "-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}"
|
@gox build -ldflags $(LDFLAGS) -osarch="linux/amd64 linux/386 darwin/amd64 darwin/386" -output=$(BIN_DIR)"/{{.Dir}}_{{.OS}}_{{.Arch}}" $(pkgs)
|
||||||
|
|
||||||
|
linux-amd64:
|
||||||
|
@echo ">> building linux/amd64 binaries in $(BIN_DIR)"
|
||||||
|
gox -ldflags $(LDFLAGS) -osarch="linux/amd64" -output=$(BIN_DIR)"/{{.Dir}}" $(pkgs)
|
||||||
|
|
||||||
|
linux-386:
|
||||||
|
@echo ">> building linux/386 binaries in $(BIN_DIR)"
|
||||||
|
gox -ldflags $(LDFLAGS) -osarch="linux/amd64" -output=$(BIN_DIR)"/{{.Dir}}" $(pkgs)
|
||||||
|
|
||||||
|
darwin-amd64:
|
||||||
|
@echo ">> building darwin/amd64 binaries in $(BIN_DIR)"
|
||||||
|
gox -ldflags $(LDFLAGS) -osarch="darwin/amd64" -output=$(BIN_DIR)"/{{.Dir}}" $(pkgs)
|
||||||
|
|
||||||
|
darwin-386:
|
||||||
|
@echo ">> building darwin/386 binaries in $(BIN_DIR)"
|
||||||
|
gox -ldflags $(LDFLAGS) -osarch="darwin/386" -output=$(BIN_DIR)"/{{.Dir}}" $(pkgs)
|
||||||
|
|
||||||
.PHONY: all style format build test vet tarball
|
.PHONY: all style format build test vet tarball
|
||||||
|
@@ -159,12 +159,12 @@ type NetworkStats struct {
|
|||||||
|
|
||||||
// OpcountStats stores information related to comamnds and basic CRUD operations.
|
// OpcountStats stores information related to comamnds and basic CRUD operations.
|
||||||
type OpcountStats struct {
|
type OpcountStats struct {
|
||||||
|
Command int64 `bson:"command"`
|
||||||
|
Delete int64 `bson:"delete"`
|
||||||
|
GetMore int64 `bson:"getmore"`
|
||||||
Insert int64 `bson:"insert"`
|
Insert int64 `bson:"insert"`
|
||||||
Query int64 `bson:"query"`
|
Query int64 `bson:"query"`
|
||||||
Update int64 `bson:"update"`
|
Update int64 `bson:"update"`
|
||||||
Delete int64 `bson:"delete"`
|
|
||||||
GetMore int64 `bson:"getmore"`
|
|
||||||
Command int64 `bson:"command"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadWriteLockTimes stores time spent holding read/write locks.
|
// ReadWriteLockTimes stores time spent holding read/write locks.
|
||||||
|
@@ -476,20 +476,51 @@ func getNodeType(session pmgo.SessionManager) (string, error) {
|
|||||||
|
|
||||||
func GetOpCountersStats(session pmgo.SessionManager, count int64, sleep time.Duration) (*opCounters, error) {
|
func GetOpCountersStats(session pmgo.SessionManager, count int64, sleep time.Duration) (*opCounters, error) {
|
||||||
oc := &opCounters{}
|
oc := &opCounters{}
|
||||||
|
previousoc := &opCounters{}
|
||||||
ss := proto.ServerStatus{}
|
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)
|
ticker := time.NewTicker(sleep)
|
||||||
for i := int64(0); i < count-1; i++ {
|
for i := int64(0); i < count; i++ {
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
err := session.DB("admin").Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, &ss)
|
err := session.DB("admin").Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, &ss)
|
||||||
if err != nil {
|
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
|
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
|
// Insert
|
||||||
if ss.Opcounters.Insert > oc.Insert.Max {
|
if ss.Opcounters.Insert > oc.Insert.Max {
|
||||||
oc.Insert.Max = ss.Opcounters.Insert
|
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.Min = ss.Opcounters.GetMore
|
||||||
}
|
}
|
||||||
oc.GetMore.Total += 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()
|
ticker.Stop()
|
||||||
|
|
||||||
|
@@ -25,21 +25,25 @@ func TestGetOpCounterStats(t *testing.T) {
|
|||||||
ss := proto.ServerStatus{}
|
ss := proto.ServerStatus{}
|
||||||
test.LoadJson("test/sample/serverstatus.json", &ss)
|
test.LoadJson("test/sample/serverstatus.json", &ss)
|
||||||
|
|
||||||
// serverStatus for getOpCountersStats
|
|
||||||
session.EXPECT().DB("admin").Return(database)
|
session.EXPECT().DB("admin").Return(database)
|
||||||
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
||||||
|
|
||||||
session.EXPECT().DB("admin").Return(database)
|
session.EXPECT().DB("admin").Return(database)
|
||||||
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
||||||
|
|
||||||
session.EXPECT().DB("admin").Return(database)
|
session.EXPECT().DB("admin").Return(database)
|
||||||
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
||||||
|
|
||||||
session.EXPECT().DB("admin").Return(database)
|
session.EXPECT().DB("admin").Return(database)
|
||||||
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
||||||
|
|
||||||
|
ss = addToCounters(ss, 1)
|
||||||
session.EXPECT().DB("admin").Return(database)
|
session.EXPECT().DB("admin").Return(database)
|
||||||
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
||||||
|
|
||||||
var sampleCount int64 = 5
|
var sampleCount int64 = 5
|
||||||
var sampleRate time.Duration = 10 * time.Millisecond // in seconds
|
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)
|
os, err := GetOpCountersStats(session, sampleCount, sampleRate)
|
||||||
if err != nil {
|
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) {
|
func TestSecurityOpts(t *testing.T) {
|
||||||
cmdopts := []proto.CommandLineOptions{
|
cmdopts := []proto.CommandLineOptions{
|
||||||
// 1
|
// 1
|
||||||
|
@@ -34,12 +34,12 @@
|
|||||||
"NumRequests": 522
|
"NumRequests": 522
|
||||||
},
|
},
|
||||||
"Opcounters": {
|
"Opcounters": {
|
||||||
"Insert": 0,
|
"Insert": 1,
|
||||||
"Query": 22,
|
"Query": 2,
|
||||||
"Update": 0,
|
"Update": 3,
|
||||||
"Delete": 0,
|
"Delete": 4,
|
||||||
"GetMore": 0,
|
"GetMore": 5,
|
||||||
"Command": 473
|
"Command": 6
|
||||||
},
|
},
|
||||||
"OpcountersRepl": null,
|
"OpcountersRepl": null,
|
||||||
"RecordStats": null,
|
"RecordStats": null,
|
||||||
@@ -55,4 +55,4 @@
|
|||||||
"ShardCursorType": null,
|
"ShardCursorType": null,
|
||||||
"StorageEngine": null,
|
"StorageEngine": null,
|
||||||
"WiredTiger": null
|
"WiredTiger": null
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user