-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.
+* <tab> - 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
<sjmudd@pobox.com>
+
+### Code Documenton
+[godoc.org/github.com/sjmudd/pstop](http://godoc.org/github.com/sjmudd/pstop)
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() {
+++ /dev/null
-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 <sjmudd@pobox.com>
-
-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
-<tab> - change display modes between: latency, ops, file I/O, lock modes
- and user mode.
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()
}
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, "<tab> - 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, "<tab> or <right arrow> - change display modes between: latency, ops, file I/O, lock and user modes")
+ s.PrintAt(0, 13, "<left arrow> - change display modes to the previous screen (see above)")
+ s.PrintAt(0, 15, "Press h to return to main screen")
}
func (s *TermboxScreen) Close() {
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 {
}
}
+// 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 {
} 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()
}
package version
const (
- version = "0.1.0"
+ version = "0.1.1"
)
// return the current application version