From 65c9ae05af2882d60512d5beefa99dae232d9f16 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Sun, 14 Dec 2014 22:23:11 +0100 Subject: [PATCH] v0.1.3 add support for explicit --defaults-file=xx on command line --- BUGS | 6 ++++-- NEW_FEATURES | 34 ++++++++++++++++++---------------- README.md | 4 ++-- main.go | 26 +++++++++++++++++--------- version/version.go | 2 +- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/BUGS b/BUGS index 7194db2..8ef7fba 100644 --- a/BUGS +++ b/BUGS @@ -7,8 +7,10 @@ See also NEW_FEATURES for things which probably need adding soon. by looking at the pattern defined in the server. Currently I'm using hard-coded stuff which matches personal usage. -2. Latency issues over slow connections. Perhaps should use compressed -connection to speed things up? +2. Latency issues over slow connections. Perhaps I should use +compressed connection to speed things up, but that is not possible +at the moment. See https://github.com/go-sql-driver/mysql/issues/24 +for more details. 3. Sometimes I see this: diff --git a/NEW_FEATURES b/NEW_FEATURES index 5135d27..6ca2b5a 100644 --- a/NEW_FEATURES +++ b/NEW_FEATURES @@ -20,28 +20,30 @@ over time but providing output as stdout. It might be useful to have options to pstop to present the info in that sort of format too. -4. add some replication metrics to pstop as most of my servers are +4. Add some replication metrics to pstop as most of my servers are slaves and we want to know where the server is busy. I've seen a way to do that and need to incorporate it into pstop. -5. _if_ ps statistics get truncated it would be good to be able -to remember the latest state and add those metrics back again, _if_ -looking at absolute rather than statistics. I currently truncate -info after 15-minutes, so this might happen while watching a server -with pstop. +5. _if_ ps statistics get truncated it would be good to be able to +remember the latest state and add those metrics back again, _if_ +looking at absolute rather than relative statistics. On servers I +manage I currently truncate info as it is collected after 15-minutes, +so this might happen while watching a server with pstop. 6. Improve the options for sorting the data. Total latency is good, but it would be good to see the write based metrics ordered by total write latency. So look to improve the display and sort options here. 7. Add command line options for providing access to the MySQL server. -Currently uses ~/.my.cnf and that's all. - -8. shift-tab to go back a screen. - -Issue 3 - termbox - SHIFT + TAB with go - termbox library ... -code.google.com/p/termbox/issues/detail?id=3 -14 Sep 2010 - If I press Shift + Tab the Poll function will send -me 3 things successively: 1: Key 27 2: Ch 91 3: Ch 90 It's the only -Key I know that do that. -https://github.com/peco/peco/issues/161 +--defaults-file=/path/to/.my.cnf now works, but missing an explicit +--host=xx --port=99 --user=xx --password=xx or --socket=/path/to/mysql.sock +options. + +8. I/O Latency by File shows read/write bytes and operations but +none of these values is converted into B/s or ops/sec which might +be better given we want to see the rate values. MB/s or ops/s are +easier to understand and the values don't change depending on the +period being viewed. That said unless we have the times the metrics +were collected we can't calculate these rates so the ABS values +can't show the rate information but would need to show only the +counters. diff --git a/README.md b/README.md index 42e1e82..b05a69c 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Install and update this go package with `go get -u github.com/sjmudd/pstop` ### Configuration Access to MySQL is currently via a defaults-file which is assumed -to be `~/.my.cnf`. This should probably be made more configurable. -If you see a need for this please let me know. +to be `~/.my.cnf`. Alternatively you can now provide +-defaults-file=/path/to/.my.cnf if needed. ### Grants diff --git a/main.go b/main.go index ddefcf0..53960f2 100644 --- a/main.go +++ b/main.go @@ -31,20 +31,22 @@ const ( ) var ( - flag_version = flag.Bool("version", false, "Show the version of "+lib.MyName()) - flag_debug = flag.Bool("debug", false, "Enabling debug logging") - flag_help = flag.Bool("help", false, "Provide some help for "+lib.MyName()) - cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + flag_debug = flag.Bool("debug", false, "Enabling debug logging") + flag_defaults_file = flag.String("defaults-file", "", "Provide a defaults-file to use to connect to MySQL") + flag_help = flag.Bool("help", false, "Provide some help for "+lib.MyName()) + flag_version = flag.Bool("version", false, "Show the version of "+lib.MyName()) + cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") re_valid_version = regexp.MustCompile(`^(5\.[67]\.|10\.[01])`) ) -func get_db_handle() *sql.DB { +// Connect to the database with the given defaults-file, or ~/.my.cnf if not provided. +func get_db_handle( defaults_file string ) *sql.DB { var err error var dbh *sql.DB lib.Logger.Println("get_db_handle() connecting to database") - dbh, err = mysql_defaults_file.OpenUsingDefaultsFile(sql_driver, "", "performance_schema") + dbh, err = mysql_defaults_file.OpenUsingDefaultsFile(sql_driver, defaults_file, "performance_schema") if err != nil { log.Fatal(err) } @@ -76,8 +78,9 @@ func usage() { fmt.Println("Usage: " + lib.MyName() + " ") fmt.Println("") fmt.Println("Options:") - fmt.Println("-help show this help message") - fmt.Println("-version show the version") + fmt.Println("-defaults-file=/path/to/defaults.file Connect to MySQL using given defaults-file" ) + fmt.Println("-help show this help message") + fmt.Println("-version show the version") } // pstop requires MySQL 5.6+ or MariaDB 10.0+. Check the version @@ -119,6 +122,7 @@ func validate_mysql_version(dbh *sql.DB) error { } func main() { + var defaults_file string = "" flag.Parse() // clean me up @@ -145,7 +149,11 @@ func main() { lib.Logger.Println("Starting " + lib.MyName()) - dbh := get_db_handle() + if flag_defaults_file != nil && *flag_defaults_file != "" { + defaults_file = *flag_defaults_file + } + + dbh := get_db_handle( defaults_file ) if err := validate_mysql_version(dbh); err != nil { log.Fatal(err) } diff --git a/version/version.go b/version/version.go index 2259527..be253eb 100644 --- a/version/version.go +++ b/version/version.go @@ -2,7 +2,7 @@ package version const ( - version = "0.1.2" + version = "0.1.3" ) // return the current application version -- 2.7.4