• Stars
    star
    117
  • Rank 300,061 (Top 6 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SlowLog Profiler for MySQL and PostgreSQL

slp

slp is a MySQL/PostgreSQL SlowLog Profiler.

ๆ—ฅๆœฌ่ชž

This tool is similar to mysqldumpslow, but can check more metrics.

Installation

Download from https://github.com/tkuchiki/slp/releases

Usage

$ slp --help
slp is a MySQL/PostgreSQL SlowLog Profiler

Usage:
  slp [flags]
  slp [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  diff        Show the difference between the two profile results
  help        Help about any command
  my          Profile the slowlogs for MySQL
  pg          Profile the slowlogs for PostgreSQL

Flags:
      --config string   The configuration file
  -h, --help            help for slp
  -v, --version         version for slp

Use "slp [command] --help" for more information about a command.

$ cat example/mysql.slow.log | slp my
+-------+---------------------------------+----------------+----------------+----------------+----------------+
| COUNT |              QUERY              | MIN(QUERYTIME) | MAX(QUERYTIME) | SUM(QUERYTIME) | AVG(QUERYTIME) |
+-------+---------------------------------+----------------+----------------+----------------+----------------+
| 1     | DELETE FROM `t2` WHERE 'S'      | 0.369618       | 0.369618       | 0.369618       | 0.369618       |
|       | < `c1_date` OR `c2` NOT IN      |                |                |                |                |
|       | (SELECT `c3` FROM `t3`)         |                |                |                |                |
| 1     | DELETE FROM `t4` WHERE `c4`     | 7.148949       | 7.148949       | 7.148949       | 7.148949       |
|       | NOT IN (SELECT `c1` FROM `t1`)  |                |                |                |                |
| 1     | INSERT INTO `t2`                | 0.010498       | 0.010498       | 0.010498       | 0.010498       |
|       | (`c2_id`,`c2_string`,`c2_date`) |                |                |                |                |
|       | VALUES (N,'S','S')              |                |                |                |                |
| 1     | INSERT INTO `t2`                | 0.010498       | 0.010498       | 0.010498       | 0.010498       |
|       | (`c2_id`,`c2_string`,`c2_date`) |                |                |                |                |
|       | VALUES (N,'S','S'),(N,'S','S')  |                |                |                |                |
| 1     | SELECT * FROM `t5` WHERE        | 0.010753       | 0.010753       | 0.010753       | 0.010753       |
|       | `c5_id` IN ('S','S','S')        |                |                |                |                |
| 1     | SELECT `t1`.`id` FROM `t1`      | 0.020219       | 0.020219       | 0.020219       | 0.020219       |
|       | JOIN `t2` ON `t2`.`t1_id` =     |                |                |                |                |
|       | `t1`.`id` WHERE `t2`.`t1_id` =  |                |                |                |                |
|       | 'S' ORDER BY `t2`.`t1_id`       |                |                |                |                |
| 2     | UPDATE `t1` SET                 | 1.428614       | 3.504247       | 4.932861       | 2.466430       |
|       | `c1_count`=(SELECT COUNT(N) AS  |                |                |                |                |
|       | `cnt` FROM `t2` WHERE `c3_id`   |                |                |                |                |
|       | = `t3`.`id`)                    |                |                |                |                |
+-------+---------------------------------+----------------+----------------+----------------+----------------+

$ cat example/postgresql.slow.log | slp pg
+-------+--------------------------------+----------------+----------------+----------------+----------------+
| COUNT |             QUERY              | MIN(QUERYTIME) | MAX(QUERYTIME) | SUM(QUERYTIME) | AVG(QUERYTIME) |
+-------+--------------------------------+----------------+----------------+----------------+----------------+
| 1     | DELETE FROM t2 WHERE 'S' <     | 0.369618       | 0.369618       | 0.369618       | 0.369618       |
|       | c1_date OR NOT c2 IN (SELECT   |                |                |                |                |
|       | c3 FROM t3)                    |                |                |                |                |
| 1     | DELETE FROM t4 WHERE NOT c4 IN | 7.148949       | 7.148949       | 7.148949       | 7.148949       |
|       | (SELECT c1 FROM t1)            |                |                |                |                |
| 1     | INSERT INTO t2 (c2_id,         | 0.010498       | 0.010498       | 0.010498       | 0.010498       |
|       | c2_string, c2_date) VALUES (N, |                |                |                |                |
|       | 'S', 'S')                      |                |                |                |                |
| 1     | INSERT INTO t2 (c2_id,         | 0.010498       | 0.010498       | 0.010498       | 0.010498       |
|       | c2_string, c2_date) VALUES (N, |                |                |                |                |
|       | 'S', 'S'), (N, 'S', 'S')       |                |                |                |                |
| 1     | SELECT * FROM t5 WHERE c5_id   | 0.010753       | 0.010753       | 0.010753       | 0.010753       |
|       | IN ('S', 'S', 'S')             |                |                |                |                |
| 1     | SELECT t1.id FROM t1 JOIN      | 0.020219       | 0.020219       | 0.020219       | 0.020219       |
|       | t2 ON t2.t1_id = t1.id WHERE   |                |                |                |                |
|       | t2.t1_id = 'S' ORDER BY        |                |                |                |                |
|       | t2.t1_id                       |                |                |                |                |
| 2     | UPDATE t1 SET c1_count =       | 1.428614       | 3.504247       | 4.932861       | 2.466430       |
|       | (SELECT count(*) AS cnt FROM   |                |                |                |                |
|       | t2 WHERE c3_id = t3.id)        |                |                |                |                |
+-------+--------------------------------+----------------+----------------+----------------+----------------+

print-output-options

You can see the --output option values.

$ slp my print-output-options
count
query
min-query-time
max-query-time
sum-query-time
avg-query-time
min-lock-time
max-lock-time
sum-lock-time
avg-lock-time
min-rows-sent
max-rows-sent
sum-rows-sent
avg-rows-sent
min-rows-examined
max-rows-examined
sum-rows-examined
avg-rows-examined
min-rows-affected
max-rows-affected
sum-rows-affected
avg-rows-affected
min-bytes-sent
max-bytes-sent
sum-bytes-sent
avg-bytes-sent

$ slp pg print-output-options
count
query
min-query-time
max-query-time
sum-query-time
avg-query-time

$ slp my print-output-options --percentiles 95,99
count
query
min-query-time
max-query-time
sum-query-time
avg-query-time
p95-query-time
p99-query-time
min-lock-time
max-lock-time
sum-lock-time
avg-lock-time
p95-lock-time
p99-lock-time
min-rows-sent
max-rows-sent
sum-rows-sent
avg-rows-sent
p95-rows-sent
p99-rows-sent
min-rows-examined
max-rows-examined
sum-rows-examined
avg-rows-examined
p95-rows-examined
p99-rows-examined
min-rows-affected
max-rows-affected
sum-rows-affected
avg-rows-affected
p95-rows-affected
p99-rows-affected
min-bytes-sent
max-bytes-sent
sum-bytes-sent
avg-bytes-sent
p95-bytes-sent
p99-bytes-sent

$ slp pg print-output-options --percentiles 95,99
count
query
min-query-time
max-query-time
sum-query-time
avg-query-time
p95-query-time
p99-query-time

diff

  • Show the difference between the two profile results
  • + means an increasing count, rows_sent, rows_examined, rows_affected, bytes_sent, and query_timeใ€lock_time are slower
  • - means a decreasing count, rows_sent, rows_examined, rows_affected, bytes_sent, and query_timeใ€lock_time are faster
$ cat /path/to/mysql.slow.log | slp my --dump dumpfile1.yaml

$ cat /path/to/mysql.slow.log | slp my --dump dumpfile2.yaml

$ slp diff dumpfile1.yaml dumpfile2.yaml --show-footers
+---------+---------------------------------+----------------+-------------------+-------------------+-------------------+
|  COUNT  |              QUERY              | MIN(QUERYTIME) |  MAX(QUERYTIME)   |  SUM(QUERYTIME)   |  AVG(QUERYTIME)   |
+---------+---------------------------------+----------------+-------------------+-------------------+-------------------+
| 1       | SELECT * FROM `t5` WHERE        | 0.010753       | 0.010753          | 0.010753          | 0.010753          |
|         | `c5_id` IN ('S','S','S')        |                |                   |                   |                   |
| 1       | DELETE FROM `t2` WHERE 'S'      | 0.369618       | 0.369618          | 0.369618          | 0.369618          |
|         | < `c1_date` OR `c2` NOT IN      |                |                   |                   |                   |
|         | (SELECT `c3` FROM `t3`)         |                |                   |                   |                   |
| 1       | DELETE FROM `t4` WHERE `c4`     | 7.148949       | 7.148949          | 7.148949          | 7.148949          |
|         | NOT IN (SELECT `c1` FROM `t1`)  |                |                   |                   |                   |
| 1       | INSERT INTO `t2`                | 0.010498       | 0.010498          | 0.010498          | 0.010498          |
|         | (`c2_id`,`c2_string`,`c2_date`) |                |                   |                   |                   |
|         | VALUES (N,'S','S')              |                |                   |                   |                   |
| 1       | INSERT INTO `t2`                | 0.010498       | 0.010498          | 0.010498          | 0.010498          |
|         | (`c2_id`,`c2_string`,`c2_date`) |                |                   |                   |                   |
|         | VALUES (N,'S','S'),(N,'S','S')  |                |                   |                   |                   |
| 1       | SELECT `t1`.`id` FROM `t1`      | 0.020219       | 0.020219          | 0.020219          | 0.020219          |
|         | JOIN `t2` ON `t2`.`t1_id` =     |                |                   |                   |                   |
|         | `t1`.`id` WHERE `t2`.`t1_id` =  |                |                   |                   |                   |
|         | 'S' ORDER BY `t2`.`t1_id`       |                |                   |                   |                   |
| 2       | UPDATE `t1` SET                 | 1.428614       | 3.504247          | 4.932861          | 2.466430          |
|         | `c1_count`=(SELECT COUNT(N) AS  |                |                   |                   |                   |
|         | `cnt` FROM `t2` WHERE `c3_id`   |                |                   |                   |                   |
|         | = `t3`.`id`)                    |                |                   |                   |                   |
| 2 (+1)  | DELETE FROM `t1` WHERE 'S' <    | 0.035678       | 1.035678 (+1.000) | 1.071356 (+1.036) | 0.535678 (+0.500) |
|         | `c1_date`                       |                |                   |                   |                   |
+---------+---------------------------------+----------------+-------------------+-------------------+-------------------+
| 10 (+1) |                                                                                                               
+---------+---------------------------------+----------------+-------------------+-------------------+-------------------+

Global options

See: Usage samples

  • -c, --config
    • The configuration file
    • YAML
  • --file=FILE
    • The access log file
  • -d, --dump=DUMP
    • File path for creating the profile results to a file
  • -l, --load=LOAD
    • File path to read the results of the profile created with the -d, --dump option
    • Can expect it to work fast if you change the --sort and --reverse options for the same profile results
  • --sort=count
    • Output the results in sorted order
    • Sort in ascending order
    • count, query
    • min-query-time, max-query-time, sum-query-time, avg-query-time
    • min-lock-time, max-lock-time, sum-lock-time, avg-lock-time
    • min-rows-sent, max-rows-sent, sum-rows-sent, avg-rows-sent
    • min-rows-examined, max-rows-examined, sum-rows-examined, avg-rows-examined
    • min-rows-affected, max-rows-affected, sum-rows-affected, avg-rows-affected
    • min-bytes-sent, max-bytes-sent, sum-bytes-sent, avg-bytes-sent
    • The default is count
    • pN(1~100)-<sort-key> is modified by the values specified in --percentiles
      • The p means percentile
      • e.g. p90-query-time
      • count and query does not support
  • -r, --reverse
    • Sort in desecending order
  • --format=table
    • Print the profile results in a table, Markdown, TSV, CSV and HTML format
    • The default is table format
  • --noheaders
    • Print no header when TSV and CSV format
  • --show-footers
    • Print the total number of each 1xx ~ 5xx in the footer of the table or Markdown format
  • --limit=5000
    • Maximum number of profile results to be printed
    • This setting is to avoid using too much memory
    • The default is 5000 lines
  • -o, --output="simple"
    • Specify the profile results to be print, separated by commas
    • count, query, min-query-time, max-query-time, sum-query-time, avg-query-time, min-lock-time, max-lock-time, sum-lock-time, avg-lock-time, min-rows-sent, max-rows-sent, sum-rows-sent, avg-rows-sent, min-rows-examined, max-rows-examined, sum-rows-examined, avg-rows-examined, min-rows-affected, max-rows-affected, sum-rows-affected, avg-rows-affected, min-bytes-sent, max-bytes-sent, sum-bytes-sent, avg-bytes-sent
      • These outputs are the same for all
      • pN(1~100)-<sort-key> is modified by the values specified in --percentiles
    • The default is simple
    • standard outputs all without *-rows-affected and *-bytes-sent
  • -m, --matching-groups=PATTERN,...
    • Treat Queries that match regular expressions as the same Query
    • Evaluate in the specified order. If matched, no further evaluation is performed.
  • -f, --filters=FILTERS
    • Filters the targets for profile
    • See Filter
  • --pos=POSITION_FILE
    • Stores the number of bytes to which the file has been read.
    • If the number of bytes is stored in the POSITION_FILE, the data after that number of bytes will be profiled
    • You can profile without truncating the file
      • Also, it is expected to work fast because it seeks and skips files
  • --nosave-pos
    • Data after the number of bytes specified by --pos is profiled, but the number of bytes reads is not stored
  • --percentiles
    • Specifies the percentile values to output, separated by commas
    • e.g. 90,95,99
  • -a, --noabstract
    • Do not abstract all numbers to N and strings to 'S'
  • --bundle-values
  • --bundle-where-in

pg options

  • --log-line-prefix="%m [%p]"
    • The log_line_prefix of postgresql.conf

Filter

It is a function to include or exclude targets according to the conditions.

Variables

Filter on the following variables:.

  • Query
    • SQL
  • QueryTime
    • The time to acquire queries in seconds
  • LockTime
    • The time to acquire locks in seconds
  • RowsSent
    • The number of rows sent to the client
  • RowsExamined
    • The number of rows examined by the server layer
  • RowsAffected
    • The number of rows changed
  • BytesSent
    • The number of bytes sent to all clients

Operators

The following operators are available:.

  • +, -, *, /, %, **(pow)
  • ==, !=, <, >, <=, >=
  • not, !
  • and, &&
  • or, ||
  • matches
    • e.g.
      • Query matches "PATTERN"
      • not(Query matches "PATTERN")
  • contains
    • e.g.
      • Query contains "STRING"
      • not(Query contains "STRING")
  • startsWith
    • e.g.
      • Query startsWith "PREFIX"
      • not(Query startsWith "PREFIX")
  • endsWith
    • e.g.
      • Query endsWith "SUFFIX"
      • not(Query endsWith "SUFFIX")
  • in
    • e.g.
      • QueryTime in [0.1, 0.2]
      • QueryTime not in [0.1, 0.2]

See: https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md

Usage samples

See: Usage samples

Donation

Donations are welcome as always!
โค๏ธ Sponsor

More Repositories

1

alp

Access Log Profiler
Go
666
star
2

go-timezone

Timezone utility for Go
Go
99
star
3

faketime

Mock time.Now() in golang
Go
35
star
4

aws-cert-utils

Certificate Utility for AWS(ACM, IAM, ALB, CLB, CloudFront)
Go
17
star
5

parsetime

date/time parser for golang
Go
13
star
6

mackerel-plugin-linux-proc-stats

Linux processes metrics plugin for mackerel.io agent.
Go
13
star
7

bats-travis-ci

Using Bats with Travis CI
Shell
11
star
8

ghooks-cmd-runner

Receives Github webhooks and runs commands
Go
10
star
9

encrypt-pw

Encrypts password
Go
9
star
10

bash-progress-bar

Progress bar for bash
Shell
8
star
11

timezones

Timezone list
Python
6
star
12

slowlog-sorter

MySQL slow query log sorter (read from file or stdin)
Go
4
star
13

watchcat

Go
4
star
14

mackerel-plugin-rack-stats

Unicorn metrics plugin for mackerel.io agent
Go
4
star
15

docker-embulk

Makefile
4
star
16

rds-slowlog-downloader

Downloads RDS(for MySQL, Aurora) slow query logs.
Go
4
star
17

metrics-sender

Send metrics to metrics collectors.
Go
3
star
18

json2mdtbl

JSON to Markdown Table
Go
3
star
19

as-cleaner

Delete Amazon EBS Snapshot for deregistered AMI
Go
3
star
20

norikra-listener-zabbix

Norikra listener plugin to send performance data for Zabbix.
Ruby
3
star
21

kubectls

kubectls is a kubectl version manager
Shell
2
star
22

chef-embulk

Chef cookbook for Embulk
Ruby
2
star
23

awslb-log-viewer

Go
2
star
24

kube-sec-decoder

Go
2
star
25

bash-get-long-opts

Get long options for bash.
Shell
1
star
26

chef-luajit

Cookbook for LuaJIT
Ruby
1
star
27

tsmv

time sliced mv
Go
1
star
28

alv

Access Log Visualizer
Go
1
star
29

docs

tech memo
1
star
30

sh-aws-ini-parser

AWS credentials / config file parser in sh.
Shell
1
star
31

gologrotate

logrotate for golang
Go
1
star
32

mysqldumpindex

Generate "CREATE(DROP) INDEX" from MySQL tables
Ruby
1
star
33

envlate

Expand environment variables in template (the templates use Go text/template syntax)
Go
1
star
34

json-checker

Checker utility for JSON syntax
Python
1
star
35

chef-certbot

Chef cookbook for certbot
Ruby
1
star
36

wireray

Go
1
star
37

gas-gantt-chart

Google Sheets ใฎใ‚ฌใƒณใƒˆใƒใƒฃใƒผใƒˆ็”จใ‚นใ‚ฏใƒชใƒ—ใƒˆ
JavaScript
1
star
38

go-mimetype-ext

Mimetype utilities for Golang
Go
1
star
39

bash-create-and-delete-users

create and delete users to linux(bash environment)
Shell
1
star
40

docker-delayed-start-mysql

delayed start mysql container for Docker
Dockerfile
1
star
41

memcli

memcached cli
Go
1
star
42

cmd-rotate

Run command and log rotation.
Go
1
star
43

log2ltsv

Convert apache and nginx access log to ltsv format
Go
1
star
44

ansible-my-osx

Shell
1
star
45

chef-dump-attr

Dump attributes command for Chef
Ruby
1
star
46

ssmenv

Expand environment variables from AWS EC2 Systems Manager Parameter Store
Go
1
star
47

get-stretcher-manifest

Get manifest file (See: https://github.com/fujiwara/stretcher)
Go
1
star
48

bash-aws-cmds

awscli tools for bash
Shell
1
star
49

zabbix-api-caller

zabbix api with golang
Go
1
star
50

sample-of-golang-os-exec

Go
1
star
51

go-ietf-lang-tag

IETF language tag Utility
Go
1
star
52

mysql2redis

Go
1
star