mongostat

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mongostat provides an overview of the status of a currently running mongod or mongos instance.

Index

Constants

This section is empty.

Variables

View Source
var Usage = `` /* 244-byte string literal not displayed */

Functions

This section is empty.

Types

type AsyncClusterMonitor

type AsyncClusterMonitor struct {
	Discover bool

	// Channel to listen for incoming stat data
	ReportChan chan *status.ServerStatus

	// Channel to listen for incoming errors
	ErrorChan chan *status.NodeError

	// Map of hostname -> latest stat data for the host
	LastStatLines map[string]*line.StatLine

	// Creates and consumes StatLines using ServerStatuses
	Consumer *stat_consumer.StatConsumer
	// contains filtered or unexported fields
}

AsyncClusterMonitor is an implementation of ClusterMonitor that writes output gotten from polling samples collected asynchronously from one or more servers.

func (*AsyncClusterMonitor) Monitor

func (cluster *AsyncClusterMonitor) Monitor(sleep time.Duration) error

The Async implementation of Monitor starts the goroutines that listen for incoming stat data, and dump snapshots at a regular interval.

func (*AsyncClusterMonitor) Update

func (cluster *AsyncClusterMonitor) Update(stat *status.ServerStatus, err *status.NodeError)

Update sends a new StatLine on the cluster's report channel.

type ClusterMonitor

type ClusterMonitor interface {
	// Monitor() triggers monitoring and dumping output to begin
	// sleep is the interval to sleep between output dumps.
	// returns an error if it fails, and nil when monitoring ends
	Monitor(sleep time.Duration) error

	// Update signals the ClusterMonitor implementation to refresh its internal
	// state using the data contained in the provided ServerStatus.
	Update(stat *status.ServerStatus, err *status.NodeError)
}

ClusterMonitor maintains an internal representation of a cluster's state, which can be refreshed with calls to Update(), and dumps output representing this internal state on an interval.

type ConfigShard

type ConfigShard struct {
	Id   string `bson:"_id"`
	Host string `bson:"host"`
}

ConfigShard holds a mapping for the format of shard hosts as they appear in the config.shards collection.

type MongoStat

type MongoStat struct {
	// Generic mongo tool options.
	Options *options.ToolOptions

	// Mongostat-specific output options.
	StatOptions *StatOptions

	// How long to sleep between printing the rows, and polling the server.
	SleepInterval time.Duration

	// New nodes can be "discovered" by any other node by sending a hostname
	// on this channel.
	Discovered chan string

	// A map of hostname -> NodeMonitor for all the hosts that
	// are being monitored.
	Nodes map[string]*NodeMonitor

	// ClusterMonitor to manage collecting and printing the stats from all nodes.
	Cluster ClusterMonitor
	// contains filtered or unexported fields
}

MongoStat is a container for the user-specified options and internal cluster state used for running mongostat.

func (*MongoStat) AddNewNode

func (mstat *MongoStat) AddNewNode(fullhost string) error

AddNewNode adds a new host name to be monitored and spawns the necessary goroutine to collect data from it.

func (*MongoStat) Run

func (mstat *MongoStat) Run() error

Run is the top-level function that starts the monitoring and discovery goroutines

type NodeMonitor

type NodeMonitor struct {

	// The time at which the node monitor last processed an update successfully.
	LastUpdate time.Time

	// The most recent error encountered when collecting stats for this node.
	Err error
	// contains filtered or unexported fields
}

NodeMonitor contains the connection pool for a single host and collects the mongostat data for that host on a regular interval.

func NewNodeMonitor

func NewNodeMonitor(opts options.ToolOptions, fullHost string) (*NodeMonitor, error)

NewNodeMonitor copies the same connection settings from an instance of ToolOptions, but monitors fullHost.

func (*NodeMonitor) Disconnect

func (node *NodeMonitor) Disconnect()

func (*NodeMonitor) Poll

func (node *NodeMonitor) Poll(discover chan string, checkShards bool) (*status.ServerStatus, error)

Report collects the stat info for a single node and sends found hostnames on the "discover" channel if checkShards is true.

func (*NodeMonitor) Watch

func (node *NodeMonitor) Watch(sleep time.Duration, discover chan string, cluster ClusterMonitor)

Watch continuously collects and processes stats for a single node on a regular interval. At each interval, it triggers the node's Poll function with the 'discover' channel.

type Options

type Options struct {
	*options.ToolOptions
	*StatOptions
	SleepInterval int
}

func ParseOptions

func ParseOptions(rawArgs []string, versionStr, gitCommit string) (Options, error)

type StatOptions

type StatOptions struct {
	Columns       string `` /* 214-byte string literal not displayed */
	AppendColumns string `` /* 146-byte string literal not displayed */
	HumanReadable string `` /* 189-byte string literal not displayed */
	NoHeaders     bool   `long:"noheaders" description:"don't output column names"`
	RowCount      int64  `long:"rowcount" value-name:"<count>" short:"n" description:"number of stats lines to print (0 for indefinite)"`
	Discover      bool   `long:"discover" description:"discover nodes and display stats for all"`
	Http          bool   `long:"http" description:"use HTTP instead of raw db connection"`
	All           bool   `long:"all" description:"all optional fields"`
	Json          bool   `long:"json" description:"output as JSON rather than a formatted table"`
	Deprecated    bool   `long:"useDeprecatedJsonKeys" description:"use old key names; only valid with the json output option."`
	Interactive   bool   `short:"i" long:"interactive" description:"display stats in a non-scrolling interface"`
}

StatOptions defines the set of options to use for configuring mongostat.

func (*StatOptions) Name

func (*StatOptions) Name() string

Name returns a human-readable group name for mongostat options.

type SyncClusterMonitor

type SyncClusterMonitor struct {
	// Channel to listen for incoming stat data
	ReportChan chan *status.ServerStatus

	// Channel to listen for incoming errors
	ErrorChan chan *status.NodeError

	// Creates and consumes StatLines using ServerStatuses
	Consumer *stat_consumer.StatConsumer
}

SyncClusterMonitor is an implementation of ClusterMonitor that writes output synchronized with the timing of when the polling samples are collected. Only works with a single host at a time.

func (*SyncClusterMonitor) Monitor

func (cluster *SyncClusterMonitor) Monitor(_ time.Duration) error

Monitor waits for data on the cluster's report channel. Once new data comes in, it formats and then displays it to stdout.

func (*SyncClusterMonitor) Update

func (cluster *SyncClusterMonitor) Update(stat *status.ServerStatus, err *status.NodeError)

Update refreshes the internal state of the cluster monitor with the data in the StatLine. SyncClusterMonitor's implementation of Update blocks until it has written out its state, so that output is always dumped exactly once for each poll.

Directories

Path Synopsis
Main package for the mongostat tool.
Main package for the mongostat tool.

Jump to

Keyboard shortcuts

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