myqlib

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MYSQLCLI          string       = "mysql"
	STATUS_COMMAND    MySQLCommand = "SHOW GLOBAL STATUS;SELECT 'END';\n"
	VARIABLES_COMMAND MySQLCommand = "SHOW GLOBAL VARIABLES;SELECT 'END';\n"
	// prefix of SHOW VARIABLES keys, they are stored (if available) in the same map as the status variables
	VAR_PREFIX = "V_"
)
View Source
const (
	BATCH showoutputtype = iota
	TABULAR
)
View Source
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 = 1024 * 1024
)

Variables

View Source
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.

View Source
var MYSQLCLIARGS []string = []string{
	"-B",
	"-n",
	"-N",
}

Build the argument list

Functions

func DefaultViews

func DefaultViews() map[string]View

func GetState

func GetState(l Loader) (chan *MyqState, error)

Given a loader, get a channel of myqstates being returned

func GetTermSize

func GetTermSize() (height, width int64)

this needs some error handling and testing love

func ScanBytes

func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanBytes is a split function for a Scanner that returns each byte as a token.

func ScanLines

func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error)

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

func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error)

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.

func ScanWords

func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanWords is a split function for a Scanner that returns each space-separated word of text, with surrounding spaces deleted. It will never return an empty string. The definition of space is set by unicode.IsSpace.

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 NewCurDiffCol(name, help string, width int64, bigger, smaller string, precision int64, units UnitsDef) CurDiffCol

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

func NewDiffCol(name, help string, width int64, variable_name string, precision int64, units UnitsDef) DiffCol

func (DiffCol) Data

func (c DiffCol) Data(state *MyqState) chan string

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

type FixedWidthBuffer struct {
	bytes.Buffer
	// contains filtered or unexported fields
}

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

func NewFuncCol(name, help string, width int64, fn func(*MyqState, Col) chan string) FuncCol

func (FuncCol) Data

func (c FuncCol) Data(state *MyqState) chan string

type GaugeCol

type GaugeCol struct {
	DefaultCol
	NumCol
	// contains filtered or unexported fields
}

Gauge Columns simply display a SHOW STATUS variable

func NewGaugeCol

func NewGaugeCol(name, help string, width int64, variable_name string, precision int64, units UnitsDef) GaugeCol

func (GaugeCol) Data

func (c GaugeCol) Data(state *MyqState) chan string

type GroupCol

type GroupCol struct {
	NormalView
	// contains filtered or unexported fields
}

ExtraHeaderView

func NewGroupCol

func NewGroupCol(title, help string, cols ...Col) *GroupCol

func (*GroupCol) Header

func (v *GroupCol) Header(state *MyqState) chan string

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 Loader

type Loader interface {
	// contains filtered or unexported methods
}

type MySQLCommand added in v0.9.1

type MySQLCommand string

type MyqSample

type MyqSample map[string]string

MyqSamples are K->V maps

func (MyqSample) Length

func (s MyqSample) Length() int

Number of keys in the sample

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

func NewRateCol(name, help string, width int64, variable_name string, precision int64, units UnitsDef) RateCol

func (RateCol) Data

func (c RateCol) Data(state *MyqState) chan string

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 NewRateSumCol(name, help string, width int64, precision int64, units UnitsDef, variables ...string) RateSumCol

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

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new Scanner to read from r. The split function defaults to ScanLines.

func (*Scanner) Bytes

func (s *Scanner) Bytes() []byte

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) Err

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

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.

func (*Scanner) Split

func (s *Scanner) Split(split SplitFunc)

Split sets the split function for the Scanner. If called, it must be called before Scan. The default split function is ScanLines.

func (*Scanner) Text

func (s *Scanner) Text() string

Text returns the most recent token generated by a call to Scan as a newly allocated string holding its bytes.

type SplitFunc

type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

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)

func NewStringCol

func NewStringCol(name, help string, w int64, variable_name string) StringCol

func (StringCol) Data

func (c StringCol) Data(state *MyqState) chan string

type UnitsDef

type UnitsDef map[float64]string
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

Jump to

Keyboard shortcuts

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