Fixes in template & removed balancer stats for mongod servers

This commit is contained in:
Carlos Salguero
2017-02-17 13:57:21 -03:00
parent a06a377c78
commit 806fd8e804
3 changed files with 34 additions and 23 deletions

View File

@@ -33,7 +33,7 @@ const (
DEFAULT_AUTHDB = "admin"
DEFAULT_HOST = "localhost:27017"
DEFAULT_LOGLEVEL = "warn"
DEFAULT_ORDERBY = "count" // comma separated list
DEFAULT_ORDERBY = "-count" // comma separated list
DEFAULT_SKIPCOLLECTIONS = "system.profile" // comma separated list
)
@@ -514,13 +514,14 @@ func getOptions() (*options, error) {
getopt.IntVarLong(&opts.Limit, "limit", 'n', "Show the first n queries")
getopt.ListVarLong(&opts.OrderBy, "order-by", 'o', "Comma separated list of order by fields (max values): "+
getopt.ListVarLong(&opts.OrderBy, "order-by", 'o',
"Comma separated list of order by fields (max values): "+
"count,ratio,query-time,docs-scanned,docs-returned. "+
"- in front of the field name denotes reverse order.")
"- in front of the field name denotes reverse order. Default: "+DEFAULT_ORDERBY)
getopt.ListVarLong(&opts.SkipCollections, "skip-collections", 's', "A comma separated list of collections (namespaces) to skip."+
" Default: system.profile")
" Default: "+DEFAULT_SKIPCOLLECTIONS)
getopt.StringVarLong(&opts.AuthDB, "authenticationDatabase", 'a', "admin", "Databaase to use for optional MongoDB authentication. Default: admin")
getopt.StringVarLong(&opts.AuthDB, "authenticationDatabase", 'a', "admin", "Database to use for optional MongoDB authentication. Default: admin")
getopt.StringVarLong(&opts.Database, "database", 'd', "", "MongoDB database to profile")
getopt.StringVarLong(&opts.LogLevel, "log-level", 'l', "Log level: error", "panic, fatal, error, warn, info, debug. Default: error")
getopt.StringVarLong(&opts.Password, "password", 'p', "", "Password to use for optional MongoDB authentication").SetOptional()
@@ -528,16 +529,21 @@ func getOptions() (*options, error) {
getopt.SetParameters("host[:port]/database")
getopt.Parse()
var gop = getopt.CommandLine
gop.Parse(os.Args)
if gop.NArgs() > 0 {
opts.Host = gop.Arg(0)
gop.Parse(gop.Args())
}
if opts.Help {
return opts, nil
}
args := getopt.Args() // host is a positional arg
if len(args) > 0 {
opts.Host = args[0]
//args := getopt.Args() // host is a positional arg
//if len(args) > 0 {
// opts.Host = args[0]
}
//}
if getopt.IsSet("order-by") {
validFields := []string{"count", "ratio", "query-time", "docs-scanned", "docs-returned"}

View File

@@ -207,6 +207,7 @@ func main() {
os.Exit(1)
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
hostInfo, err := GetHostinfo(session)
if err != nil {
@@ -239,7 +240,7 @@ func main() {
if hostInfo != nil {
if security, err := GetSecuritySettings(session, hostInfo.Version); err != nil {
log.Printf("[Error] cannot get security settings: %v\n", err)
log.Errorf("[Error] cannot get security settings: %v\n", err)
} else {
t := template.Must(template.New("ssl").Parse(templates.Security))
t.Execute(os.Stdout, security)
@@ -270,12 +271,14 @@ func main() {
}
}
if hostInfo.NodeType == "mongos" {
if bs, err := GetBalancerStats(session); err != nil {
log.Printf("[Error] cannot get balancer stats: %v\n", err)
} else {
t := template.Must(template.New("balancer").Parse(templates.BalancerStats))
t.Execute(os.Stdout, bs)
}
}
}
@@ -463,7 +466,7 @@ func GetSecuritySettings(session pmgo.SessionManager, ver string) (*security, er
}
}
s.Users, err = session.DB("admin").C("system.users").Count()
s.Users, _ = session.DB("admin").C("system.users").Count()
if err != nil {
return nil, errors.Wrap(err, "cannot get users count")
}
@@ -799,7 +802,7 @@ func parseFlags() options {
getopt.StringVarLong(&opts.User, "username", 'u', "", "Username to use for optional MongoDB authentication")
getopt.StringVarLong(&opts.Password, "password", 'p', "", "Password to use for optional MongoDB authentication").SetOptional()
getopt.StringVarLong(&opts.AuthDB, "authenticationDatabase", 'a', "admin",
"Databaase to use for optional MongoDB authentication. Default: admin")
"Databaae to use for optional MongoDB authentication. Default: admin")
getopt.StringVarLong(&opts.LogLevel, "log-level", 'l', "error", "Log level: panic, fatal, error, warn, info, debug. Default: error")
getopt.IntVarLong(&opts.RunningOpsSamples, "running-ops-samples", 's',

View File

@@ -10,8 +10,10 @@ Unsharded Collections: {{.UnshardedColsCount}}
Unsharded Data Size: {{.UnshardedDataSizeScaled}} {{.UnshardedDataSizeScale}}
{{- if .Chunks }}
### Chunks:
{{ range .Chunks }}
{{- if .ID }} {{ printf "%5d" .Count }} : {{ printf "%-30s" .ID}}{{ end -}}
{{- end -}}
{{ end -}}
{{- range .Chunks }}
{{- if .ID }}
{{ printf "%5d" .Count }} : {{ printf "%-30s" .ID}}
{{- end }}
{{- end }}
{{- end -}}
`