-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_global_status.sql
79 lines (72 loc) · 2.62 KB
/
query_global_status.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
SET @machine_name = @@hostname;
-- Select time series of one specific status
SELECT ts, variable_value AS 'threads_running'
FROM global_status
WHERE machine_name = @machine_name
AND variable_name = 'threads_running'
ORDER BY ts ASC
;
-- Select time series of two specific status'
SELECT s1.ts
, s1.variable_value AS 'table_open_cache_misses'
, s2.variable_value AS 'table_open_cache_hits'
FROM global_status AS s1
JOIN global_status AS s2 ON s1.ts = s2.ts
WHERE s1.machine_name = @machine_name
AND s1.variable_name = 'table_open_cache_misses'
AND s2.machine_name = @machine_name
AND s2.variable_name = 'table_open_cache_hits'
ORDER BY ts ASC
;
-- Delta to previous value
SELECT ts, variable_value
, variable_value - LAG(variable_value)
OVER (ORDER BY variable_value) AS difference_to_previous
FROM global_status
WHERE machine_name = @machine_name
AND variable_name = 'table_open_cache_misses'
ORDER BY ts ASC
;
-- Select time series of two specific status' and create .csv file for later import into Excel
SELECT s1.ts
, s1.variable_value AS 'innodb_rows_deleted'
, s2.variable_value AS 'innodb_rows_inserted'
INTO OUTFILE '/tmp/innodb_rows.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM global_status AS s1
JOIN global_status AS s2 ON s1.ts = s2.ts
WHERE s1.machine_name = @machine_name
AND s1.variable_name = 'innodb_rows_deleted'
AND s2.machine_name = @machine_name
AND s2.variable_name = 'innodb_rows_inserted'
ORDER BY ts ASC
;
-- Select time series of two specific status' and create .csv file for gnuplot
SELECT UNIX_TIMESTAMP(s1.ts)
, s1.variable_value AS 'innodb_rows_deleted'
, s2.variable_value AS 'innodb_rows_inserted'
INTO OUTFILE '/tmp/innodb_rows.csv'
FIELDS TERMINATED BY "\t"
LINES TERMINATED BY '\n'
FROM global_status AS s1
JOIN global_status AS s2 ON s1.ts = s2.ts
WHERE s1.machine_name = @machine_name
AND s1.variable_name = 'innodb_rows_deleted'
AND s2.machine_name = @machine_name
AND s2.variable_name = 'innodb_rows_inserted'
ORDER BY s1.ts ASC
;
-- gnuplot> plot "/tmp/innodb_rows.csv" using 1:2 title 'rows_deleted' with lines, \
-- "/tmp/innodb_rows.csv" using 1:3 title 'rows inserted' with lines
-- Min/max/avg per hour of a specific status
SELECT SUBSTR(ts, 1, 13) AS per_hour
, MIN(variable_value) AS 'threads_running_min'
, MAX(variable_value) AS 'threads_running_max'
, ROUND(AVG(variable_value), 1) AS 'threads_running_avg'
FROM global_status
WHERE machine_name = @machine_name
AND variable_name = 'threads_running'
GROUP BY SUBSTR(ts, 1, 13)
ORDER BY ts ASC
;