From 193ae41f5473832680f1969a1e0bc19bc27909b8 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Thu, 11 Dec 2014 23:28:07 +0100 Subject: [PATCH] Adjust README.md and allow left and right arrow keys to navigate --- README.md | 71 ++++++++++++++++++++++++++++++++++++++++++------------ i_s/pl_by_user.go | 3 ++- keys.txt | 21 ---------------- main.go | 5 +++- screen/screen.go | 5 ++-- state/state.go | 33 +++++++++++++++++++------ version/version.go | 2 +- 7 files changed, 91 insertions(+), 49 deletions(-) delete mode 100644 keys.txt diff --git a/README.md b/README.md index 37b1395..b2f03c2 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,70 @@ -pstop -===== +## pstop pstop - a top-like program for MySQL pstop is a program which collects information from MySQL 5.6+'s -performance_schema database and uses this information to display server -load in real-time. Data is shown by table or filename and the -metrics also show how this is split between select, insert, update or -delete activity. User activity is now shown showing the number of -different hosts that connect with the same username and the actiity -of those users. +performance_schema database and uses this information to display +server load in real-time. Data is shown by table or filename and +the metrics also show how this is split between select, insert, +update or delete activity. User activity is now shown showing the +number of different hosts that connect with the same username and +the actiity of those users. -This program was started as a simple project to allow me to learn go, -which I'd been following for a while, but hadn't used in earnest. This -probably shows in the code so suggestions on improvement are most welcome. +This program was started as a simple project to allow me to learn +go, which I'd been following for a while, but hadn't used in earnest. +This probably shows in the code so suggestions on improvement are +most welcome. -Access to MySQL is currently via a defaults-file which is assumed to be -~/.my.cnf. I should probably make this more configurable. +### Installation + +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. + +### Grants Do not forget to ensure that the MySQL user you configure has access to the performance_schema tables. -See also BUGS and NEW_FEATURES which describe things that probably need -looking at, keys.txt which describes the keys used inside pstop, and -screen_samples.txt which provides some sample output from my own system. +### Screens + +pstop has 5 different screens: +* Latency mode: order table activity by the time waiting to perform operations on them. +* Ops (operations) mode: order table activity by the number of operations MySQL performs on them. +* I/O mode: show where MySQL is spending it's time in file I/O. +* Locks mode: show order based on table locks +* User mode: show ordering based on how long users are running queries, or the number of connections they have to MySQL. + +### Keys + +The following keys allow you to navigate around the different pstop displays or to change it's behaviour. + +* h - gives you a help screen. +* - - reduce the poll interval by 1 second (minimum 1 second) +* + - increase the poll interval by 1 second +* q - quit +* t - toggle between showing the statistics since resetting pstop started or you explicitly reset them (with 'z') [REL] or showing the statistics as collected from MySQL [ABS]. +* z - reset statistics. That is counters you see are relative to when you "reset" statistics. +* - change display modes between: latency, ops, file I/O, lock modes and user modes. +* left arrow - change to previous screen +* right arrow - change to next screen + +### See also + +See also BUGS and NEW_FEATURES which describe things that probably +need looking at and screen_samples.txt which provides some sample +output from my own system. + +### Feedback Feedback and patches welcome. Simon J Mudd + +### Code Documenton +[godoc.org/github.com/sjmudd/pstop](http://godoc.org/github.com/sjmudd/pstop) diff --git a/i_s/pl_by_user.go b/i_s/pl_by_user.go index cd7bf9c..ae5b4aa 100644 --- a/i_s/pl_by_user.go +++ b/i_s/pl_by_user.go @@ -118,7 +118,8 @@ func (t ByRunTime) Len() int { return len(t) } func (t ByRunTime) Swap(i, j int) { t[i], t[j] = t[j], t[i] } func (t ByRunTime) Less(i, j int) bool { return (t[i].runtime > t[j].runtime) || - ((t[i].runtime == t[j].runtime) && (t[i].connections > t[j].connections)) + ((t[i].runtime == t[j].runtime) && (t[i].connections > t[j].connections)) || + ((t[i].runtime == t[j].runtime) && (t[i].connections == t[j].connections) && (t[i].username < t[j].username)) } func (t pl_by_user_rows) Sort() { diff --git a/keys.txt b/keys.txt deleted file mode 100644 index a3e899a..0000000 --- a/keys.txt +++ /dev/null @@ -1,21 +0,0 @@ -pstop uses several keys. Help is available by pressing 'h'. This is what -it tells you. - - -------- - -pstop version 0.1.0 (C) 2014 Simon J Mudd - -Program to show the top I/O information by accessing information from the -performance_schema schema. Ideas based on mysql-sys. - -Keys: -- - reduce the poll interval by 1 second (minimum 1 second) -+ - increase the poll interval by 1 second -h - this help screen -q - quit -t - toggle between showing the statistics since resetting pstop started or - you explicitly reset them (with 'z') [REL] or showing the statistics - as collected from MySQL [ABS]. -z - reset statistics - - change display modes between: latency, ops, file I/O, lock modes - and user mode. diff --git a/main.go b/main.go index 1f40e65..545170c 100644 --- a/main.go +++ b/main.go @@ -183,7 +183,10 @@ func main() { switch event.Key { case termbox.KeyCtrlZ, termbox.KeyCtrlC, termbox.KeyEsc: finished = true - case termbox.KeyTab: // tab - change display modes + case termbox.KeyArrowLeft: // left arrow change to previous display mode + state.DisplayPrevious() + state.Display() + case termbox.KeyTab, termbox.KeyArrowRight: // tab or right arrow - change to next display mode state.DisplayNext() state.Display() } diff --git a/screen/screen.go b/screen/screen.go index 6a9a788..338583a 100644 --- a/screen/screen.go +++ b/screen/screen.go @@ -91,8 +91,9 @@ func (s *TermboxScreen) DisplayHelp() { s.PrintAt(0, 9, "q - quit") s.PrintAt(0, 10, "t - toggle between showing time since resetting statistics or since P_S data was collected") s.PrintAt(0, 11, "z - reset statistics") - s.PrintAt(0, 12, " - change display modes between: latency, ops, file I/O, lock and user modes") - s.PrintAt(0, 14, "Press h to return to main screen") + s.PrintAt(0, 12, " or - change display modes between: latency, ops, file I/O, lock and user modes") + s.PrintAt(0, 13, " - change display modes to the previous screen (see above)") + s.PrintAt(0, 15, "Press h to return to main screen") } func (s *TermboxScreen) Close() { diff --git a/state/state.go b/state/state.go index e0056ba..682fb1c 100644 --- a/state/state.go +++ b/state/state.go @@ -152,6 +152,8 @@ func (state State) Help() bool { return state.help } +// states go: showLatency -> showOps -> showIO -> showLocks -> showUsers + // display the output according to the mode we are in func (state *State) Display() { if state.help { @@ -171,6 +173,29 @@ func (state *State) Display() { } } +// fix_latency_setting() ensures the SetWantsLatency() value is +// correct. This needs to be done more cleanly. +func (state *State) fix_latency_setting() { + if state.show == showLatency { + state.tiwsbt.SetWantsLatency(true) + } + if state.show == showOps { + state.tiwsbt.SetWantsLatency(false) + } +} + +// change to the previous display mode +func (state *State) DisplayPrevious() { + if state.show == showLatency { + state.show = showUsers + } else { + state.show-- + } + state.fix_latency_setting() + state.screen.Clear() + state.screen.Flush() +} + // change to the next display mode func (state *State) DisplayNext() { if state.show == showUsers { @@ -178,13 +203,7 @@ func (state *State) DisplayNext() { } else { state.show++ } - // this needs to be done more cleanly - if state.show == showLatency { - state.tiwsbt.SetWantsLatency(true) - } - if state.show == showOps { - state.tiwsbt.SetWantsLatency(false) - } + state.fix_latency_setting() state.screen.Clear() state.screen.Flush() } diff --git a/version/version.go b/version/version.go index 0d16748..07ad6b1 100644 --- a/version/version.go +++ b/version/version.go @@ -2,7 +2,7 @@ package version const ( - version = "0.1.0" + version = "0.1.1" ) // return the current application version -- 2.7.4