Giter Club home page Giter Club logo

ps-top's Introduction

ps-top

ps-top - a top-like program for MySQL

ps-top 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 activity of those users. There are also statistics on mutex and sql stage timings.

Installation

Install each binary by doing: $ go install github.com/sjmudd/ps-top@latest

Check the version of go you are using as older versions of GO may not work.

The sources will be downloaded together with the dependencies and the binary will be built and installed into $GOPATH/bin/. If this path is in your PATH setting then the program can be run directly without having to specify any specific path.

Configuration

Sometimes you may want to combine different tables together and show the combined output. A typical example might be if you have lots of similarly named tables. Should you want to do this you can use the following configuration file ~/.pstoprc to hole the configuration information:

[munge]
<regexp_match> = <replacement_string>
_[0-9]{8}$ = _YYYYMMDD
_[0-9]{6}$ = _YYYYMM

MySQL Access

Access to MySQL can be made by one of the following methods:

  • Default: use a defaults-file named ~/.my.cnf.
  • use an explicit defaults-file with --defaults-file=/path/to/.my.cnf.
  • connect to a host with --host=somehost --port=999 --user=someuser --password=somepass, or
  • connect via a socket with --socket=/path/to/mysql.sock --user=someuser --password=somepass
  • to avoid the password being stored or provided as a command line argument you can use --askpass which will request this from the user on startup

The user if not specified will default to the contents of $USER. The port if not specified will default to 3306.

  • If you use the command line option --use-environment ps-top will look for the credentials in the environment variable MYSQL_DSN and connect with that. This is a GO DSN and is expected to be in the format: user:pass@tcp(host:port)/performance_schema and currently ALL fields must be filled in. With a suitable wrapper function this allows you to access one of many different servers without making the credentials visible on the command line.

An example setting could be to use TLS which is not fully supported at the moment with command line parameters:

$ export MYSQL_DSN='user:pass@tcp(host:3306)/performance_schema?tls=skip-verify&allowCleartextPasswords=1'
$ ps-top

MySQL/MariaDB configuration

The performance_schema database MUST be enabled for ps-top to work. By default on MySQL this is enabled, but on MariaDB >= 10.0.12 it is disabled. So please check your settings. Simply configure in /etc/my.cnf:

performance_schema = 1

If you change this setting you'll need to restart MariaDB for it to take effect.

Grants

ps-top needs SELECT grants to access performance_schema tables. They will not run if access to the required tables is not available.

setup_instruments: To view mutex_latency or stages_latency ps-top will try to change the configuration if needed and if you have grants to do this. If the server is --read-only or you do not have sufficient grants to change these tables these views may be empty. Pior to stopping ps-top will restore the setup_instruments configuration back to its original settings if it had successfully updated the table when starting up.

Views

ps-top can show 7 different views of data, the views are updated every second by default. The views are named:

  • table_io_latency: Show activity by table by the time waiting to perform operations on them.
  • table_io_ops: Show activity by number of operations MySQL performs on them.
  • file_io_latency: Show where MySQL is spending it's time in file I/O.
  • table_lock_latency: Show order based on table locks
  • user_latency: Show ordering based on how long users are running queries, or the number of connections they have to MySQL. This is really missing a feature in MySQL (see: bug#75156) to provide higher resolution query times than seconds. It gives some info but if the queries are very short then the integer runtime in seconds makes the output far less interesting. Total idle time is also shown as this gives an indication of perhaps overly long idle queries, and the sum of the values here if there's a pile up may be interesting.
  • mutex_latency: Show the ordering by mutex latency [1].
  • stages_latency: Show the ordering by time in the different SQL query stages [1].

You can change the polling interval and switch between modes (see below).

[1] See Grants above. These views may appear empty if setup_instruments is not configured correctly.

Keys

When in ps-top mode the following keys allow you to navigate around the different ps-top 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 ps-top 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, user, mutex, stages and memory modes.
  • left arrow - change to previous screen
  • right arrow - change to next screen

See also

See also:

Incompatible Changes

As of v1.0.7 ps-stats has been removed. I never used it and it is simpler to remove unused functionality.

As of v0.5.0 the original utility was renamed from pstop which could work in stdout or top mode into two utilities named ps-top and ps-stats. This change of name was triggered to avoid the name conflict with the Oracle command pstop(1). See https://docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mii/index.html. While the two commands are not related it was felt better to avoid the name overload, and while ps-top is reasonably young this change should not yet cause too much trouble.

Contributing

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.

Licensing

BSD 2-Clause License

Feedback

Feedback and patches welcome. I am especially interested in hearing from you if you are using ps-top, or if you have ideas of how I can better use other information from the performance_schema tables to provide a more complete vision of what MySQL is doing or where it's busy. The tool has been used by myself and colleagues and helped quickly identify bottlenecks and problems in several systems.

Simon J Mudd [email protected]

Code Documenton

godoc.org/github.com/sjmudd/ps-top

ps-top's People

Contributors

cezmunsta avatar dgryski avatar ericherman avatar sjmudd avatar xgdgsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ps-top's Issues

Unknown column 'SUM_TIMER_WAIT' in 'field list'

Hi Simon,

I am trying to run the tool but I get the error:

 2015/10/18 19:45:19 Error 1054: Unknown column 'SUM_TIMER_WAIT' in 'field list'

and the program exits.

I am using mysql 5.5 with performance enabled and accessing as root

+-------------------------+-----------------------------+
| Variable_name           | Value                       |
+-------------------------+-----------------------------+
| innodb_version          | 5.5.44                      |
| protocol_version        | 10                          |
| slave_type_conversions  |                             |
| version                 | 5.5.44-0ubuntu0.14.04.1-log |
| version_comment         | (Ubuntu)                    |
| version_compile_machine | x86_64                      |
| version_compile_os      | debian-linux-gnu            |
+-------------------------+-----------------------------+

mysql> SHOW VARIABLES LIKE 'performance_schema';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| performance_schema | ON    |
+--------------------+-------+

I have even checked and the column is there:

mysql> describe performance_schema.events_waits_summary_global_by_event_name;
+----------------+---------------------+------+-----+---------+-------+
| Field          | Type                | Null | Key | Default | Extra |
+----------------+---------------------+------+-----+---------+-------+
| EVENT_NAME     | varchar(128)        | NO   |     | NULL    |       |
| COUNT_STAR     | bigint(20) unsigned | NO   |     | NULL    |       |
| SUM_TIMER_WAIT | bigint(20) unsigned | NO   |     | NULL    |       |
| MIN_TIMER_WAIT | bigint(20) unsigned | NO   |     | NULL    |       |
| AVG_TIMER_WAIT | bigint(20) unsigned | NO   |     | NULL    |       |
| MAX_TIMER_WAIT | bigint(20) unsigned | NO   |     | NULL    |       |
+----------------+---------------------+------+-----+---------+-------+

Any idea of what can be wrong?

ps-stats help print all view list

Maybe ps-stats help can print all support view list
then can copy , it is easy to copy
table_io_latency, table_io_ops, file_io_latency, table_lock_latency, user_latency, mutex_latency and stages_latency. --totals

Starting ps-top fails with error XXX'Error 1146 'XXX

Hello,
Trying to run ps-top on mysql 5.6, but it fails with the following error:
2023/06/29 13:47:28 mylog.go:45: Unexpected errorXXX'Error 1146 'XXX

Checked the code memoryusage/rows.go the missing table is performance_schema.memory_summary_global_by_event_name, and indeed I don't have one. How can I ignore this check if I don't need the memory statistics anyway?

Thank you.

How to compile ps-top on Ubuntu bionic?

On bionic it fails with an error:

$ go version
go version go1.10.4 linux/amd64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic

$ go get -u github.com/sjmudd/ps-top
package github.com/rivo/uniseg: found packages uniseg (doc.go) and main (gen_breaktest.go) in /home/akuzminsky/go/src/github.com/rivo/uniseg
$ echo $?
1

Reading defaults file doesn't cover quoted passwords

In a ~/.my.cnf file, you can enclose passwords with special characters within quotes, as

password="%@%GT@@gf54%@"

(no this is not my password)

The parser doesn't interpret single or double quotes correctly with password. That is, it tries to send the quotes as part of the password.

Reproduce by enclosing password with single or double quote and get an error connecting. Remove quotes and it works.

Can't install on Ubuntu

Hi @sjmudd,

I'm running into this issue while trying to install ps-top since a few weeks:

$ GOPATH=/home/ubuntu/gocode go get -u github.com/sjmudd/mysql_defaults_file
$ GOPATH=/home/ubuntu/gocode go get -u github.com/nsf/termbox-go
$ GOPATH=/home/ubuntu/gocode go get -u github.com/sjmudd/ps-top/cmd/ps-top
# github.com/go-sql-driver/mysql
gocode/src/github.com/go-sql-driver/mysql/utils.go:806:10: error: reference to undefined identifier ‘atomic.Value’
  value   atomic.Value
          ^
gocode/src/github.com/go-sql-driver/mysql/packets.go:1095:26: error: reference to undefined field or method ‘AppendFormat’
      b = v.In(mc.cfg.Loc).AppendFormat(b, timeFormat)
                          ^

Would you know how to solve this ? Thanks

Installation instruction

In the readme could you please provide an instruction how to install the required golang components and how to build pstop. I also would appreciate to have a precompiled binary file. ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.