Skip to content

Commit

Permalink
Merge branch 'issue-19'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Janssen committed Sep 4, 2015
2 parents 4160c34 + b2fd538 commit d8db77f
Show file tree
Hide file tree
Showing 7 changed files with 1,545 additions and 224 deletions.
19 changes: 14 additions & 5 deletions myqlib/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ import (
"time"
)

type MySQLCommand string
const SPECIALENDSTRING string = "MYQTOOLSEND"

const (
MYSQLCLI string = "mysql"
STATUS_COMMAND MySQLCommand = "SHOW GLOBAL STATUS;SELECT 'END';\n"
VARIABLES_COMMAND MySQLCommand = "SHOW GLOBAL VARIABLES;SELECT 'END';\n"

// These next two must match
END_STRING string = "MYQTOOLSEND"
END_COMMAND string = "SELECT 'MYQTOOLSEND'"

// The commands we send to the mysql cli
STATUS_COMMAND string = "SHOW GLOBAL STATUS"
VARIABLES_COMMAND string = "SHOW GLOBAL VARIABLES"

// prefix of SHOW VARIABLES keys, they are stored (if available) in the same map as the status variables
VAR_PREFIX = "V_"
)
Expand Down Expand Up @@ -243,7 +250,7 @@ func NewLiveLoader(i time.Duration, args string) *LiveLoader {
}

// Collect output from MYSQLCLI and send it back in a sample
func (l LiveLoader) harvestMySQL(command MySQLCommand) (chan MyqSample, error) {
func (l LiveLoader) harvestMySQL(command string) (chan MyqSample, error) {
// Make sure we have MYSQLCLI
path, err := exec.LookPath(MYSQLCLI)
if err != nil {
Expand Down Expand Up @@ -290,9 +297,11 @@ func (l LiveLoader) harvestMySQL(command MySQLCommand) (chan MyqSample, error) {
}()

// feed the MYSQLCLI the given command to produce more output
full_command := strings.Join( []string{command, END_COMMAND, "\n"}, "; " )
send_command := func() {
// We don't check if the write failed, it's assumed the cmd.Wait() above will catch the sub proc dying
stdin.Write([]byte(command))

stdin.Write([]byte(full_command)) // command we're harvesting
}
// send the first command immediately
send_command()
Expand Down
2 changes: 1 addition & 1 deletion myqlib/parse_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
func parseSamples(reader io.Reader, ch chan MyqSample, interval time.Duration) {
outputtype := BATCH // default to BATCH
typechecked := false
recordmatch := []byte("END")
recordmatch := []byte(END_STRING)

// We can't have intervals smaller than 1s
// if the interval is larger, we check samples for intervals
Expand Down
12 changes: 12 additions & 0 deletions myqlib/parse_show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ func checksamples(t *testing.T, samples chan MyqSample, expected int) {
}
}

func TestTokuSample(t *testing.T) {
l := FileLoader{loaderInterval(1 * time.Second), "../testdata/mysql.toku", ""}
samples, err := l.getStatus()

if err != nil {
t.Error(err)
}

checksamples(t, samples, 2)
}


func BenchmarkParseStatus(b *testing.B) {
for i := 0; i < b.N; i++ {
l := FileLoader{loaderInterval(1 * time.Second), "../testdata/mysqladmin.single", ""}
Expand Down
Loading

0 comments on commit d8db77f

Please sign in to comment.