HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

how to get 'Queries per second avg' using SQL (not 'mysqladmin status')

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
persqlavgmysqladminstatusgetsecondusinghowqueries

Problem

When I start mysqladmin, it prints out several statistics, including "Queries per second avg":

# mysqladmin --defaults-file=../mylogin.cnf status
Uptime: 4568115  Threads: 859  Questions: 3703806462  Slow queries: 19415  Opens: 10300505  Flush tables: 247  Open tables: 2000  Queries per second avg: 810.795


Can I retrieve this "Queries per second avg" value within an SQL query? We use MariaDB 10.1.x

Solution

For those running MariaDB and MySQL (If using 5.7, show_compatibility_56 enabled)

SELECT Q / T Queries_per_second_avg FROM
(SELECT variable_value Q FROM information_schema.global_status
WHERE variable_name = 'Questions') A,
(SELECT variable_value T FROM information_schema.global_status
WHERE variable_name = 'Uptime') B;


For those running MySQL 5.7, show_compatibility_56 disabled

SELECT Q / T Queries_per_second_avg FROM
(SELECT variable_value Q FROM performance_schema.global_status
WHERE variable_name = 'Questions') A,
(SELECT variable_value T FROM performance_schema.global_status
WHERE variable_name = 'Uptime') B;

Code Snippets

SELECT Q / T Queries_per_second_avg FROM
(SELECT variable_value Q FROM information_schema.global_status
WHERE variable_name = 'Questions') A,
(SELECT variable_value T FROM information_schema.global_status
WHERE variable_name = 'Uptime') B;
SELECT Q / T Queries_per_second_avg FROM
(SELECT variable_value Q FROM performance_schema.global_status
WHERE variable_name = 'Questions') A,
(SELECT variable_value T FROM performance_schema.global_status
WHERE variable_name = 'Uptime') B;

Context

StackExchange Database Administrators Q#210602, answer score: 5

Revisions (0)

No revisions yet.