Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultViews() map[string]View
- func GetState(l Loader) (chan *MyqState, error)
- func GetTermSize() (height, width int64)
- func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error)
- func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error)
- func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error)
- func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error)
- type Col
- type CurDiffCol
- type DefaultCol
- type DiffCol
- type ExtraHeaderView
- type FileLoader
- type FixedWidthBuffer
- type FuncCol
- type GaugeCol
- type GroupCol
- type LiveLoader
- type Loader
- type MySQLAdminCommand
- type MyqSample
- type MyqState
- type NormalView
- type NumCol
- type PercentCol
- type RateCol
- type RateSumCol
- type RightmostCol
- type Scanner
- type SplitFunc
- type StringCol
- type UnitsDef
- type View
Constants ¶
const ( MYSQLADMIN string = "mysqladmin" STATUS_COMMAND MySQLAdminCommand = "extended-status" VARIABLES_COMMAND MySQLAdminCommand = "variables" // prefix of SHOW VARIABLES keys, they are stored (if available) in the same map as the status variables VAR_PREFIX = "V_" )
const ( BATCH showoutputtype = iota TABULAR )
const ( // MaxScanTokenSize is the maximum size used to buffer a token. // The actual maximum token size may be smaller as the buffer // may need to include, for instance, a newline. MaxScanTokenSize = 256 * 1024 )
Variables ¶
var ( ErrTooLong = errors.New("bufio.Scanner: token too long") ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count") ErrAdvanceTooFar = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input") )
Errors returned by Scanner.
Functions ¶
func DefaultViews ¶
func GetTermSize ¶
func GetTermSize() (height, width int64)
this needs some error handling and testing love
func ScanLines ¶
ScanLines is a split function for a Scanner that returns each line of text, stripped of any trailing end-of-line marker. The returned line may be empty. The end-of-line marker is one optional carriage return followed by one mandatory newline. In regular expression notation, it is `\r?\n`. The last non-empty line of input will be returned even if it has no newline.
func ScanRunes ¶
ScanRunes is a split function for a Scanner that returns each UTF-8-encoded rune as a token. The sequence of runes returned is equivalent to that from a range loop over the input as a string, which means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd". Because of the Scan interface, this makes it impossible for the client to distinguish correctly encoded replacement runes from encoding errors.
Types ¶
type Col ¶
type Col interface { // Column help Help() chan string // Write a line (or lines) of header to the returned channel Header(state *MyqState) chan string // A full line of output given the state Data(state *MyqState) chan string // width of the column Width() int64 }
All Columns must implement the following
var ( Timestamp_col Col = NewFuncCol(`time`, `Time data was printed`, 8, func(state *MyqState, c Col) chan string { ch := make(chan string, 1) defer close(ch) ch <- fit_string(time.Now().Format(`15:04:05`), c.Width()) return ch }) Runtime_col Col = NewFuncCol(`time`, `Interval since data started`, 8, func(state *MyqState, c Col) chan string { ch := make(chan string, 1) defer close(ch) runtime := time.Duration(state.Cur.getI(`uptime`)-state.FirstUptime) * time.Second ch <- fit_string(fmt.Sprintf("%.0fs", runtime.Seconds()), c.Width()) return ch }) )
Time Columns
type CurDiffCol ¶
type CurDiffCol struct { DefaultCol NumCol // contains filtered or unexported fields }
CurDiff Columns the difference between two variables in the same sample (different from DiffCol)
func NewCurDiffCol ¶
func (CurDiffCol) Data ¶
func (c CurDiffCol) Data(state *MyqState) chan string
type DefaultCol ¶
type DefaultCol struct {
// contains filtered or unexported fields
}
'Default' column -- "inherited" by others
func (DefaultCol) Header ¶
func (c DefaultCol) Header(state *MyqState) chan string
func (DefaultCol) Help ¶
func (c DefaultCol) Help() chan string
func (DefaultCol) Width ¶
func (c DefaultCol) Width() int64
type DiffCol ¶
type DiffCol struct {
GaugeCol
}
Diff Columns the difference of a SHOW STATUS variable between samples
func NewDiffCol ¶
type ExtraHeaderView ¶
type ExtraHeaderView struct { NormalView // contains filtered or unexported fields }
ExtraHeaderView
func NewExtraHeaderView ¶
func NewExtraHeaderView(help string, extra_header func(state *MyqState) chan string, cols ...Col) *ExtraHeaderView
func (*ExtraHeaderView) Header ¶
func (v *ExtraHeaderView) Header(state *MyqState) chan string
type FileLoader ¶
type FileLoader struct {
// contains filtered or unexported fields
}
Load mysql status output from a mysqladmin output file
func NewFileLoader ¶
func NewFileLoader(i time.Duration, statusFile, varFile string) *FileLoader
type FixedWidthBuffer ¶
func (*FixedWidthBuffer) SetWidth ¶
func (b *FixedWidthBuffer) SetWidth(w int64)
func (*FixedWidthBuffer) WriteString ¶
func (b *FixedWidthBuffer) WriteString(s string) (n int, err error)
type FuncCol ¶
type FuncCol struct { DefaultCol // contains filtered or unexported fields }
Func Columns run a custom function to produce their output
func NewFuncCol ¶
type GaugeCol ¶
type GaugeCol struct { DefaultCol NumCol // contains filtered or unexported fields }
Gauge Columns simply display a SHOW STATUS variable
func NewGaugeCol ¶
type GroupCol ¶
type GroupCol struct { NormalView // contains filtered or unexported fields }
ExtraHeaderView
func NewGroupCol ¶
type LiveLoader ¶
type LiveLoader struct {
// contains filtered or unexported fields
}
SHOW output via mysqladmin on a live server
func NewLiveLoader ¶
func NewLiveLoader(i time.Duration, args string) *LiveLoader
type MySQLAdminCommand ¶
type MySQLAdminCommand string
type MyqState ¶
type MyqState struct {
Cur, Prev MyqSample
SecondsDiff float64 // Difference between Cur and Prev
FirstUptime int64 // Uptime of our first sample this run
}
MyqState contains the current and previous SHOW STATUS outputs. Also SHOW VARIABLES. Prev might be nil
type NormalView ¶
type NormalView struct { DefaultCol // Views are columns too // contains filtered or unexported fields }
NormalView
func NewNormalView ¶
func NewNormalView(help string, cols ...Col) *NormalView
func (*NormalView) Data ¶
func (v *NormalView) Data(state *MyqState) chan string
func (*NormalView) Header ¶
func (v *NormalView) Header(state *MyqState) chan string
func (*NormalView) Help ¶
func (v *NormalView) Help() chan string
func (*NormalView) SetTimeCol ¶
func (v *NormalView) SetTimeCol(timecol *Col)
func (*NormalView) ShortHelp ¶
func (v *NormalView) ShortHelp() chan string
func (*NormalView) Width ¶
func (v *NormalView) Width() (w int64)
type NumCol ¶
type NumCol struct {
// contains filtered or unexported fields
}
Meta-type, displays some kind of number
type PercentCol ¶
type PercentCol struct { DefaultCol NumCol // contains filtered or unexported fields }
Percent Columns calculate a ratio between two metrics
func NewPercentCol ¶
func NewPercentCol(name, help string, w int64, numerator, denomenator string, p int64) PercentCol
func (PercentCol) Data ¶
func (c PercentCol) Data(state *MyqState) chan string
type RateCol ¶
type RateCol struct {
GaugeCol
}
Rate Columns the rate of change of a SHOW STATUS variable
func NewRateCol ¶
type RateSumCol ¶
type RateSumCol struct { DefaultCol NumCol // contains filtered or unexported fields }
RateSum Columns the rate of change of a sum of variables
func NewRateSumCol ¶
func (RateSumCol) Data ¶
func (c RateSumCol) Data(state *MyqState) chan string
type RightmostCol ¶
type RightmostCol struct {
StringCol
}
RightmostCol shows width rightmost chars of the variable_name
func NewRightmostCol ¶
func NewRightmostCol(name, help string, w int64, variable_name string) RightmostCol
func (RightmostCol) Data ¶
func (c RightmostCol) Data(state *MyqState) chan string
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text. Successive calls to the Scan method will step through the 'tokens' of a file, skipping the bytes between the tokens. The specification of a token is defined by a split function of type SplitFunc; the default split function breaks the input into lines with line termination stripped. Split functions are defined in this package for scanning a file into lines, bytes, UTF-8-encoded runes, and space-delimited words. The client may instead provide a custom split function.
Scanning stops unrecoverably at EOF, the first I/O error, or a token too large to fit in the buffer. When a scan stops, the reader may have advanced arbitrarily far past the last token. Programs that need more control over error handling or large tokens, or must run sequential scans on a reader, should use bufio.Reader instead.
func NewScanner ¶
NewScanner returns a new Scanner to read from r. The split function defaults to ScanLines.
func (*Scanner) Bytes ¶
Bytes returns the most recent token generated by a call to Scan. The underlying array may point to data that will be overwritten by a subsequent call to Scan. It does no allocation.
func (*Scanner) Scan ¶
Scan advances the Scanner to the next token, which will then be available through the Bytes or Text method. It returns false when the scan stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil. Split panics if the split function returns 100 empty tokens without advancing the input. This is a common error mode for scanners.
type SplitFunc ¶
SplitFunc is the signature of the split function used to tokenize the input. The arguments are an initial substring of the remaining unprocessed data and a flag, atEOF, that reports whether the Reader has no more data to give. The return values are the number of bytes to advance the input and the next token to return to the user, plus an error, if any. If the data does not yet hold a complete token, for instance if it has no newline while scanning lines, SplitFunc can return (0, nil, nil) to signal the Scanner to read more data into the slice and try again with a longer slice starting at the same point in the input.
If the returned error is non-nil, scanning stops and the error is returned to the client.
The function is never called with an empty data slice unless atEOF is true. If atEOF is true, however, data may be non-empty and, as always, holds unprocessed text.
type StringCol ¶
type StringCol struct { DefaultCol // contains filtered or unexported fields }
String Columns show a string (or substring up to width)
type UnitsDef ¶
var ( NumberUnits UnitsDef = UnitsDef{ 1: ``, 1000: `k`, 1000000: `m`, 1000000000: `g`, } MemoryUnits UnitsDef = UnitsDef{ 1: `b`, 1024: `K`, 1048576: `M`, 1073741824: `G`, 1099511627776: `T`, } SecondUnits UnitsDef = UnitsDef{ 1000: `ks`, 1: `s`, 0.001: `ms`, 0.000001: `µs`, 0.000000001: `ns`, } MicroSecondUnits UnitsDef = UnitsDef{ 1000000000: `ks`, 1000000: `s`, 1000: `ms`, 1: `µs`, } NanoSecondUnits UnitsDef = UnitsDef{ 1000000000: `s`, 1000000: `ms`, 1000: `µs`, 1: `ns`, } PercentUnits UnitsDef = UnitsDef{ 1: `%`, } )
type View ¶
type View interface { // Column help Help() chan string ShortHelp() chan string // Header/Data functions return a channel of strings Header(state *MyqState) chan string Data(state *MyqState) chan string // Use this timecol in the output SetTimeCol(timecol *Col) // contains filtered or unexported methods }
All Views must implement the following