mdb

package
v2.4.2-rc0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 33 Imported by: 4

Documentation

Index

Constants

View Source
const COLLSCAN = "COLLSCAN"

COLLSCAN constance

View Source
const REPLICA = "replica"

REPLICA set

View Source
const SHARDED = "sharded"

SHARDED cluster

View Source
const STANDALONE = "standalone"

STANDALONE cluster

Variables

View Source
var KEYHOLEDB = "_KEYHOLE_88800"

KEYHOLEDB default database

Functions

func GetIndexSuggestion added in v1.0.1

func GetIndexSuggestion(explain ExplainCommand, cardList []CardinalityCount) gox.OrderedMap

GetIndexSuggestion returns a recommended index by cardinalities index follows a principle of equality, sort, rnage

func GetKeys added in v1.0.1

func GetKeys(document bson.D, _range ...bool) []string

GetKeys gets all fields of a odc as an array

func GetOplogStats added in v1.0.1

func GetOplogStats(client *mongo.Client) bson.M

GetOplogStats returns oplog stats

func GetShardListWithURI added in v1.5.1

func GetShardListWithURI(client *mongo.Client, uri string) ([]string, error)

GetShardListWithURI gets a list of shards

func IsMaster

func IsMaster(client *mongo.Client) (bson.M, error)

IsMaster executes dbisMaster()

func ListDatabaseNames

func ListDatabaseNames(client *mongo.Client) ([]string, error)

ListDatabaseNames gets all database names

func MongoPipeline

func MongoPipeline(str string) mongo.Pipeline

MongoPipeline gets aggregation pipeline from a string

func NewMongoClient

func NewMongoClient(uri string, files ...string) (*mongo.Client, error)

NewMongoClient new mongo client

func RunAdminCommand

func RunAdminCommand(client *mongo.Client, command string) (bson.M, error)

RunAdminCommand executes admin Command

func RunCommandOnDB

func RunCommandOnDB(client *mongo.Client, command string, db string) (bson.M, error)

RunCommandOnDB execute admin Command at given database

Types

type AccessesDoc added in v1.1.2

type AccessesDoc struct {
	Ops   int       `json:"ops" bson:"ops"`
	Since time.Time `json:"since" bson:"since"`
}

AccessesDoc - accessss

type Cardinality

type Cardinality struct {
	// contains filtered or unexported fields
}

Cardinality -

func NewCardinality

func NewCardinality(client *mongo.Client) *Cardinality

NewCardinality returns cardinality constructor

func (*Cardinality) GetCardinalityArray added in v1.0.1

func (card *Cardinality) GetCardinalityArray(database string, collection string, keys ...[]string) (CardinalitySummary, error)

GetCardinalityArray returns cardinality list

func (*Cardinality) GetSummary added in v1.0.1

func (card *Cardinality) GetSummary(summary CardinalitySummary) string

GetSummary get summary of cardinality

func (*Cardinality) SetVerbose

func (card *Cardinality) SetVerbose(verbose bool)

SetVerbose -

type CardinalityCount added in v1.0.1

type CardinalityCount struct {
	Field string
	Count int64
}

CardinalityCount stores cardinality counts

type CardinalitySummary added in v1.0.1

type CardinalitySummary struct {
	SampledCount int64
	List         []CardinalityCount
}

CardinalitySummary stores Cardinality summary

type ChangeStream added in v1.0.1

type ChangeStream struct {
	// contains filtered or unexported fields
}

ChangeStream defines what to watch? client, database or collection

func NewChangeStream added in v1.0.1

func NewChangeStream() *ChangeStream

NewChangeStream gets a new ChangeStream

func (*ChangeStream) SetCollection added in v1.0.1

func (cs *ChangeStream) SetCollection(collection string)

SetCollection sets collection

func (*ChangeStream) SetDatabase added in v1.0.1

func (cs *ChangeStream) SetDatabase(database string)

SetDatabase sets database

func (*ChangeStream) SetPipeline added in v1.0.1

func (cs *ChangeStream) SetPipeline(pipeline []bson.D)

SetPipeline sets pipeline

func (*ChangeStream) SetPipelineString added in v1.0.1

func (cs *ChangeStream) SetPipelineString(pipe string)

SetPipelineString sets pipeline string

func (*ChangeStream) Watch added in v1.0.1

func (cs *ChangeStream) Watch(client *mongo.Client, cb callback)

Watch prints oplogs in JSON format

type ChartDataPoint added in v1.0.1

type ChartDataPoint struct {
	// contains filtered or unexported fields
}

ChartDataPoint has chart data points key/value

type DBStats

type DBStats struct {
	DB        string `json:"db" bson:"db"`
	DataSize  int    `json:"dataSize" bson:"dataSize"`
	IndexSize int    `json:"indexSize" bson:"indexSize"`
	Objects   int    `json:"objects" bson:"objects"`
}

DBStats contains info from db.stats()

type DatabaseInfo

type DatabaseInfo struct {
	// contains filtered or unexported fields
}

DatabaseInfo stores struct

func NewDatabaseInfo

func NewDatabaseInfo() *DatabaseInfo

NewDatabaseInfo returns DatabaseInfo

func (*DatabaseInfo) GetAllDatabasesInfo

func (dbi *DatabaseInfo) GetAllDatabasesInfo(client *mongo.Client) ([]bson.M, error)

GetAllDatabasesInfo gets all db info

func (*DatabaseInfo) SetVerbose

func (dbi *DatabaseInfo) SetVerbose(verbose bool)

SetVerbose sets verbosity

type Explain added in v1.0.1

type Explain struct {
	// contains filtered or unexported fields
}

Explain stores explain object info

func NewExplain added in v1.0.1

func NewExplain() *Explain

NewExplain returns Explain struct

func (*Explain) ExecuteAllPlans added in v1.0.1

func (e *Explain) ExecuteAllPlans(client *mongo.Client, filename string) error

ExecuteAllPlans calls queryPlanner and cardinality

func (*Explain) PrintExplainResults added in v1.0.1

func (e *Explain) PrintExplainResults(filename string) error

PrintExplainResults prints explain results

func (*Explain) SetVerbose added in v1.0.1

func (e *Explain) SetVerbose(verbose bool)

SetVerbose sets verbosity

type ExplainCommand added in v1.0.1

type ExplainCommand struct {
	Collection string `bson:"find"`
	Filter     bson.D `bson:"filter"`
	Sort       bson.D `bson:"sort,omitempty"`
	Hint       bson.D `bson:"hint,omitempty"`
	Group      string `bson:"group,omitempty"`
}

ExplainCommand stores explain document

type ExplainSummary added in v1.0.1

type ExplainSummary struct {
	ShardName              string       `json:"shardName"`
	ExecutionStats         StageStats   `json:"executionStats"`
	AllPlansExecutionStats []StageStats `json:"allPlansExecution"`
}

ExplainSummary stores explain summary

type IndexScore added in v1.0.1

type IndexScore struct {
	Index gox.OrderedMap `json:"index"`
	Score float64        `json:"score"`
}

IndexScore keeps index score

type IndexStatsDoc

type IndexStatsDoc struct {
	Fields       []string
	Key          string     `json:"key"`
	Name         string     `json:"name"`
	EffectiveKey string     `json:"effectiveKey"`
	IsDupped     bool       `json:"dupped"`
	IsShardKey   bool       `json:"shardKey"`
	TotalOps     int        `json:"totalOps"`
	Usage        []UsageDoc `json:"stats"`
}

IndexStatsDoc -

type IndexesReader added in v1.1.2

type IndexesReader struct {
	// contains filtered or unexported fields
}

IndexesReader holder indexes reader struct

func NewIndexesReader added in v1.1.2

func NewIndexesReader(client *mongo.Client) *IndexesReader

NewIndexesReader establish seeding parameters

func (*IndexesReader) GetIndexes added in v1.1.2

func (ir *IndexesReader) GetIndexes() (bson.M, error)

GetIndexes list all indexes of collections of databases

func (*IndexesReader) GetIndexesFromCollection added in v1.1.2

func (ir *IndexesReader) GetIndexesFromCollection(collection *mongo.Collection) []IndexStatsDoc

GetIndexesFromCollection gets indexes from a collection

func (*IndexesReader) GetIndexesFromDB added in v1.1.2

func (ir *IndexesReader) GetIndexesFromDB(dbName string) (bson.M, error)

GetIndexesFromDB list all indexes of collections of a database

func (*IndexesReader) Print added in v1.1.2

func (ir *IndexesReader) Print(indexesMap bson.M)

Print prints indexes

func (*IndexesReader) SetDBName added in v1.1.2

func (ir *IndexesReader) SetDBName(dbName string)

SetDBName sets verbose level

func (*IndexesReader) SetNoColor

func (ir *IndexesReader) SetNoColor(nocolor bool)

SetNoColor set nocolor flag

func (*IndexesReader) SetVerbose added in v1.1.2

func (ir *IndexesReader) SetVerbose(verbose bool)

SetVerbose sets verbose level

type LogInfo added in v1.0.1

type LogInfo struct {
	OpsPatterns    []OpPerformanceDoc
	OutputFilename string
	SlowOps        []SlowOps
	// contains filtered or unexported fields
}

LogInfo keeps loginfo struct

func NewLogInfo added in v1.0.1

func NewLogInfo() *LogInfo

NewLogInfo -

func (*LogInfo) Analyze added in v1.1.3

func (li *LogInfo) Analyze(filename string) (string, error)

Analyze -

func (*LogInfo) Parse added in v1.0.1

func (li *LogInfo) Parse(reader *bufio.Reader, counts ...int) error

Parse parse text or json

func (*LogInfo) ParseLog added in v1.0.1

func (li *LogInfo) ParseLog(str string) (LogStats, error)

ParseLog - parses text message before v4.4

func (*LogInfo) ParseLogv2 added in v1.0.1

func (li *LogInfo) ParseLogv2(str string) (LogStats, error)

ParseLogv2 - parses text message before v4.4

func (*LogInfo) SetCollscan added in v1.0.1

func (li *LogInfo) SetCollscan(collscan bool)

SetCollscan -

func (*LogInfo) SetRegexPattern added in v1.0.1

func (li *LogInfo) SetRegexPattern(regex string)

SetRegexPattern sets regex patthen

func (*LogInfo) SetSilent added in v1.0.1

func (li *LogInfo) SetSilent(silent bool)

SetSilent -

func (*LogInfo) SetVerbose added in v1.0.1

func (li *LogInfo) SetVerbose(verbose bool)

SetVerbose -

type LogStats added in v1.0.1

type LogStats struct {
	// contains filtered or unexported fields
}

LogStats log stats structure

type MongoCluster added in v1.1.0

type MongoCluster struct {
	// contains filtered or unexported fields
}

MongoCluster holds mongo cluster info

func NewMongoCluster added in v1.1.0

func NewMongoCluster(client *mongo.Client) *MongoCluster

NewMongoCluster server info struct

func (*MongoCluster) GetClusterInfo added in v1.1.0

func (mc *MongoCluster) GetClusterInfo() (bson.M, error)

GetClusterInfo -

func (*MongoCluster) SetConnString added in v1.5.1

func (mc *MongoCluster) SetConnString(connString connstring.ConnString)

SetConnString set connString object

func (*MongoCluster) SetDoodleMode added in v1.4.2

func (mc *MongoCluster) SetDoodleMode(doodle bool)

SetDoodleMode sets doodle

func (*MongoCluster) SetFilename added in v1.4.2

func (mc *MongoCluster) SetFilename(filename string)

SetFilename sets output file name

func (*MongoCluster) SetVerbose added in v1.1.0

func (mc *MongoCluster) SetVerbose(verbose bool)

SetVerbose -

func (*MongoCluster) SetVeryVerbose

func (mc *MongoCluster) SetVeryVerbose(vv bool)

SetVeryVerbose -

type OpPerformanceDoc added in v1.1.3

type OpPerformanceDoc struct {
	Command    string // count, delete, find, remove, and update
	Count      int    // number of ops
	Filter     string // query pattern
	MaxMilli   int    // max millisecond
	Namespace  string // database.collectin
	Scan       string // COLLSCAN
	TotalMilli int    // total milliseconds
	Index      string // index used
}

OpPerformanceDoc stores performance data

type OplogStats added in v1.0.1

type OplogStats struct {
	LogSizeMB int
	UsedMB    int
	TimeDiff  int
	Count     int
}

OplogStats stores oplog stats

type QueryExplainer added in v1.0.1

type QueryExplainer struct {
	ExplainCmd ExplainCommand `bson:"explain"`
	NameSpace  string
	// contains filtered or unexported fields
}

QueryExplainer stores query analyzer info

func NewQueryExplainer added in v1.0.1

func NewQueryExplainer(client *mongo.Client) *QueryExplainer

NewQueryExplainer returns QueryExplainer

func (*QueryExplainer) Explain added in v1.0.1

func (qe *QueryExplainer) Explain() (ExplainSummary, error)

Explain explains query plans

func (*QueryExplainer) GetExplainDetails added in v1.0.1

func (qe *QueryExplainer) GetExplainDetails(doc bson.M) ExplainSummary

GetExplainDetails returns summary from a doc

func (*QueryExplainer) GetFilter added in v1.0.1

func (qe *QueryExplainer) GetFilter() bson.D

GetFilter sets verbosity

func (*QueryExplainer) GetIndexesScores added in v1.0.1

func (qe *QueryExplainer) GetIndexesScores(keys []string) []IndexScore

GetIndexesScores returns a list of indexes scores

func (*QueryExplainer) GetSummary added in v1.0.1

func (qe *QueryExplainer) GetSummary(summary ExplainSummary) string

GetSummary get summary of explain executionStats

func (*QueryExplainer) ReadQueryShape added in v1.0.1

func (qe *QueryExplainer) ReadQueryShape(buffer []byte) error

ReadQueryShape parses filter map

func (*QueryExplainer) SetVerbose added in v1.0.1

func (qe *QueryExplainer) SetVerbose(verbose bool)

SetVerbose sets verbosity

type ServerInfo

type ServerInfo struct {
	Cluster     string     `json:"cluster" bson:"cluster"`
	Host        string     `json:"host" bson:"host"`
	Process     string     `json:"process" bson:"process"`
	Version     string     `json:"version" bson:"version"`
	Sharding    bson.M     `json:"sharding" bson:"sharding"`
	Shards      []ShardDoc `json:"shards" bson:"shards"`
	Repl        bson.M     `json:"repl" bson:"repl"`
	StorageSize bson.M
}

ServerInfo constains server info from db.serverStatus()

func GetServerInfo

func GetServerInfo(client *mongo.Client, skipStorageStats ...bool) (ServerInfo, error)

GetServerInfo returns ServerInfo from db.serverStatus()

type ShardDoc

type ShardDoc struct {
	ID    string `json:"_id" bson:"_id"`
	Host  string `json:"host" bson:"host"`
	State int    `json:"state" bson:"state"`
}

ShardDoc information

func GetShards

func GetShards(client *mongo.Client) ([]ShardDoc, error)

GetShards gets a list of shards

type SlowOps added in v1.0.1

type SlowOps struct {
	Milli int
	Log   string
}

SlowOps holds slow ops log and time

type StageStats added in v1.0.1

type StageStats struct {
	Level             int
	Score             float64         `json:"Score"`
	Stage             string          `json:"stage"`
	Filter            *gox.OrderedMap `json:"filter"`
	KeyPattern        *gox.OrderedMap `json:"keyPattern"`
	Advanced          int32           `json:"advanced"`
	Works             int32           `json:"works"`
	ExecTimeMillisEst int32           `json:"executionTimeMillisEstimate"`
	TotalKeysExamined int32           `json:"totalKeysExamined"`
	TotalDocsExamined int32           `json:"totalDocsExamined"`
	InputStages       []StageStats    `json:"inputStages"`
}

StageStats stores stats for each stage

type UsageDoc

type UsageDoc struct {
	Host     string      `json:"host"`
	Accesses AccessesDoc `json:"accesses"`
}

UsageDoc -

type WiredTigerCache added in v1.0.1

type WiredTigerCache struct {
	// contains filtered or unexported fields
}

WiredTigerCache stores wiredTiger cache structure

func NewWiredTigerCache added in v1.0.1

func NewWiredTigerCache(client *mongo.Client) *WiredTigerCache

NewWiredTigerCache returns *WiredTigerCache

func (*WiredTigerCache) GetAllDatabasesInfo

func (wtc *WiredTigerCache) GetAllDatabasesInfo() error

GetAllDatabasesInfo returns db info

func (*WiredTigerCache) GetWiredTigerCacheData added in v1.0.1

func (wtc *WiredTigerCache) GetWiredTigerCacheData(w http.ResponseWriter, r *http.Request)

GetWiredTigerCacheData gets WT cache data

func (*WiredTigerCache) Handler added in v1.0.1

func (wtc *WiredTigerCache) Handler(w http.ResponseWriter, r *http.Request)

Handler supports resetful calls

func (*WiredTigerCache) Start added in v1.0.1

func (wtc *WiredTigerCache) Start()

Start starts a web server and a thread to collect caches

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL