@@ -11,12 +11,19 @@ import (
1111 "time"
1212)
1313
14- type MySQLCommand string
14+ const SPECIALENDSTRING string = "MYQTOOLSEND"
1515
1616const (
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 ()
0 commit comments