Skip to content

Commit d8db77f

Browse files
author
Jay Janssen
committed
Merge branch 'issue-19'
2 parents 4160c34 + b2fd538 commit d8db77f

File tree

7 files changed

+1545
-224
lines changed

7 files changed

+1545
-224
lines changed

myqlib/loader.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ import (
1111
"time"
1212
)
1313

14-
type MySQLCommand string
14+
const SPECIALENDSTRING string = "MYQTOOLSEND"
1515

1616
const (
1717
MYSQLCLI string = "mysql"
18-
STATUS_COMMAND MySQLCommand = "SHOW GLOBAL STATUS;SELECT 'END';\n"
19-
VARIABLES_COMMAND MySQLCommand = "SHOW GLOBAL VARIABLES;SELECT 'END';\n"
18+
19+
// These next two must match
20+
END_STRING string = "MYQTOOLSEND"
21+
END_COMMAND string = "SELECT 'MYQTOOLSEND'"
22+
23+
// The commands we send to the mysql cli
24+
STATUS_COMMAND string = "SHOW GLOBAL STATUS"
25+
VARIABLES_COMMAND string = "SHOW GLOBAL VARIABLES"
26+
2027
// prefix of SHOW VARIABLES keys, they are stored (if available) in the same map as the status variables
2128
VAR_PREFIX = "V_"
2229
)
@@ -243,7 +250,7 @@ func NewLiveLoader(i time.Duration, args string) *LiveLoader {
243250
}
244251

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

292299
// feed the MYSQLCLI the given command to produce more output
300+
full_command := strings.Join( []string{command, END_COMMAND, "\n"}, "; " )
293301
send_command := func() {
294302
// We don't check if the write failed, it's assumed the cmd.Wait() above will catch the sub proc dying
295-
stdin.Write([]byte(command))
303+
304+
stdin.Write([]byte(full_command)) // command we're harvesting
296305
}
297306
// send the first command immediately
298307
send_command()

myqlib/parse_show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
func parseSamples(reader io.Reader, ch chan MyqSample, interval time.Duration) {
2222
outputtype := BATCH // default to BATCH
2323
typechecked := false
24-
recordmatch := []byte("END")
24+
recordmatch := []byte(END_STRING)
2525

2626
// We can't have intervals smaller than 1s
2727
// if the interval is larger, we check samples for intervals

myqlib/parse_show_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ func checksamples(t *testing.T, samples chan MyqSample, expected int) {
182182
}
183183
}
184184

185+
func TestTokuSample(t *testing.T) {
186+
l := FileLoader{loaderInterval(1 * time.Second), "../testdata/mysql.toku", ""}
187+
samples, err := l.getStatus()
188+
189+
if err != nil {
190+
t.Error(err)
191+
}
192+
193+
checksamples(t, samples, 2)
194+
}
195+
196+
185197
func BenchmarkParseStatus(b *testing.B) {
186198
for i := 0; i < b.N; i++ {
187199
l := FileLoader{loaderInterval(1 * time.Second), "../testdata/mysqladmin.single", ""}

0 commit comments

Comments
 (0)