mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-12 14:18:32 +00:00
PT-71
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package tutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
6
src/go/mongolib/proto/chunks_count.go
Normal file
6
src/go/mongolib/proto/chunks_count.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package proto
|
||||
|
||||
type ChunksByCollection struct {
|
||||
ID string `bson:"_id"` // Namespace
|
||||
Count int `bson:"count"`
|
||||
}
|
@@ -3,10 +3,10 @@ package proto
|
||||
import "time"
|
||||
|
||||
type SystemProfile struct {
|
||||
//AllUsers []interface{} `bson:"allUsers"`
|
||||
Client string `bson:"client"`
|
||||
CursorExhausted bool `bson:"cursorExhausted"`
|
||||
DocsExamined int `bson:"docsExamined"`
|
||||
AllUsers []interface{} `bson:"allUsers"`
|
||||
Client string `bson:"client"`
|
||||
CursorExhausted bool `bson:"cursorExhausted"`
|
||||
DocsExamined int `bson:"docsExamined"`
|
||||
ExecStats struct {
|
||||
Advanced int `bson:"advanced"`
|
||||
ExecutionTimeMillisEstimate int `bson:"executionTimeMillisEstimate"`
|
||||
|
@@ -111,6 +111,7 @@ type clusterwideInfo struct {
|
||||
UnshardedDataSize int64 // bytes
|
||||
UnshardedDataSizeScaled float64
|
||||
UnshardedDataSizeScale string
|
||||
Chunks []proto.ChunksByCollection
|
||||
}
|
||||
|
||||
type options struct {
|
||||
@@ -221,7 +222,7 @@ func main() {
|
||||
t := template.Must(template.New("hosttemplateData").Parse(templates.HostInfo))
|
||||
t.Execute(os.Stdout, hostInfo)
|
||||
|
||||
if opts.RunningOpsSamples > 0 {
|
||||
if opts.RunningOpsSamples > 0 && opts.RunningOpsInterval > 0 {
|
||||
if rops, err := GetOpCountersStats(session, opts.RunningOpsSamples, time.Duration(opts.RunningOpsInterval)*time.Millisecond); err != nil {
|
||||
log.Printf("[Error] cannot get Opcounters stats: %v\n", err)
|
||||
} else {
|
||||
@@ -385,6 +386,8 @@ func GetClusterwideInfo(session pmgo.SessionManager) (*clusterwideInfo, error) {
|
||||
cwi.ShardedDataSizeScaled, cwi.ShardedDataSizeScale = sizeAndUnit(cwi.ShardedDataSize)
|
||||
cwi.UnshardedDataSizeScaled, cwi.UnshardedDataSizeScale = sizeAndUnit(cwi.UnshardedDataSize)
|
||||
|
||||
cwi.Chunks, _ = getChunksCount(session)
|
||||
|
||||
return cwi, nil
|
||||
}
|
||||
|
||||
@@ -808,3 +811,17 @@ func parseFlags() options {
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
func getChunksCount(session pmgo.SessionManager) ([]proto.ChunksByCollection, error) {
|
||||
var result []proto.ChunksByCollection
|
||||
|
||||
c := session.DB("config").C("chunks")
|
||||
query := bson.M{"$group": bson.M{"_id": "$ns", "count": bson.M{"$sum": 1}}}
|
||||
|
||||
// db.getSiblingDB('config').chunks.aggregate({$group:{_id:"$ns",count:{$sum:1}}})
|
||||
err := c.Pipe([]bson.M{query}).All(&result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
lutil "github.com/percona/percona-toolkit/src/go/lib/util"
|
||||
"github.com/percona/percona-toolkit/src/go/lib/tutil"
|
||||
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
|
||||
"github.com/percona/pmgo/pmgomock"
|
||||
)
|
||||
@@ -23,7 +23,7 @@ func TestGetOpCounterStats(t *testing.T) {
|
||||
database := pmgomock.NewMockDatabaseManager(ctrl)
|
||||
|
||||
ss := proto.ServerStatus{}
|
||||
lutil.LoadJson("test/sample/serverstatus.json", &ss)
|
||||
tutil.LoadJson("test/sample/serverstatus.json", &ss)
|
||||
|
||||
session.EXPECT().DB("admin").Return(database)
|
||||
database.EXPECT().Run(bson.D{{"serverStatus", 1}, {"recordStats", 1}}, gomock.Any()).SetArg(1, ss)
|
||||
@@ -306,6 +306,39 @@ func TestIsPrivateNetwork(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetChunks(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
session := pmgomock.NewMockSessionManager(ctrl)
|
||||
database := pmgomock.NewMockDatabaseManager(ctrl)
|
||||
pipe := pmgomock.NewMockPipeManager(ctrl)
|
||||
col := pmgomock.NewMockCollectionManager(ctrl)
|
||||
|
||||
var res []proto.ChunksByCollection
|
||||
tutil.LoadJson("test/sample/chunks.json", &res)
|
||||
|
||||
pipe.EXPECT().All(gomock.Any()).SetArg(0, res)
|
||||
|
||||
col.EXPECT().Pipe(gomock.Any()).Return(pipe)
|
||||
|
||||
database.EXPECT().C("chunks").Return(col)
|
||||
|
||||
session.EXPECT().DB("config").Return(database)
|
||||
|
||||
want := []proto.ChunksByCollection{
|
||||
{ID: "samples.col2", Count: 5},
|
||||
}
|
||||
|
||||
got, err := getChunksCount(session)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot get chunks: %s", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("Invalid getChunksCount response.\ngot: %+v\nwant: %+v\n", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func addToCounters(ss proto.ServerStatus, increment int64) proto.ServerStatus {
|
||||
ss.Opcounters.Command += increment
|
||||
ss.Opcounters.Delete += increment
|
||||
|
@@ -7,4 +7,11 @@ const Clusterwide = `
|
||||
Sharded Collections: {{.ShardedColsCount}}
|
||||
Unsharded Collections: {{.UnshardedColsCount}}
|
||||
Sharded Data Size: {{.ShardedDataSizeScaled}} {{.ShardedDataSizeScale}}
|
||||
Unsharded Data Size: {{.UnshardedDataSizeScaled}} {{.UnshardedDataSizeScale}}`
|
||||
Unsharded Data Size: {{.UnshardedDataSizeScaled}} {{.UnshardedDataSizeScale}}
|
||||
{{- if .Chunks }}
|
||||
### Chunks:
|
||||
{{- range .Chunks }}
|
||||
{{ printf "%30s" .ID}}: {{ printf "%5d" .Count }}
|
||||
{{- end -}}
|
||||
{{ end -}}
|
||||
`
|
||||
|
1
src/go/pt-mongodb-summary/test/sample/chunks.json
Normal file
1
src/go/pt-mongodb-summary/test/sample/chunks.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"ID":"samples.col2","Count":5}]
|
Reference in New Issue
Block a user