I am using following code to check if innoDb is enabled in mysql server but i want to get total number of disk writes by mysql. please help with the following program
public class connectToInnoDb {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3310/INFORMATION_SCHEMA","root","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM ENGINES");
while(rs.next()) {
if(rs.getString(1) == "Innodb")
System.out.println("Yes");
}
con.close();
}catch(Exception e){ System.out.println(e);}
}
You can get a lot of InnoDB information with SHOW ENGINE INNODB STATUS
, including I/O counts:
mysql> SHOW ENGINE INNODB STATUS\G
...
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (read thread)
I/O thread 4 state: waiting for i/o request (read thread)
I/O thread 5 state: waiting for i/o request (read thread)
I/O thread 6 state: waiting for i/o request (write thread)
I/O thread 7 state: waiting for i/o request (write thread)
I/O thread 8 state: waiting for i/o request (write thread)
I/O thread 9 state: waiting for i/o request (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
431 OS file reads, 69 OS file writes, 53 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
...
I see above there have been 69 OS file writes. The numbers above are small because I got this information from a sandbox MySQL instance running on my laptop, and it hasn't been running long.
As commented by JimGarrison above, most of the information reported by INNODB STATUS is also available to you as individual rows in the INFORMATION_SCHEMA.INNODB_METRICS table. This is much easier to use in Java than SHOW ENGINE INNODB STATUS and trying to parse the text.
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_METRICS
WHERE NAME = 'os_data_writes'\G
NAME: os_data_writes
SUBSYSTEM: os
COUNT: 69
MAX_COUNT: 69
MIN_COUNT: NULL
AVG_COUNT: 0.0034979215248910067
COUNT_RESET: 69
MAX_COUNT_RESET: 69
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
TIME_ENABLED: 2017-12-22 10:27:50
TIME_DISABLED: NULL
TIME_ELAPSED: 19726
TIME_RESET: NULL
STATUS: enabled
TYPE: status_counter
COMMENT: Number of writes initiated (innodb_data_writes)
Read https://dev.mysql.com/doc/refman/5.7/en/innodb-information-schema-metrics-table.html
I won't show the Java code, you already know how to run a query and fetch the results. These statements can be run as SQL statements the same way you run SELECT
queries.
mysql> SHOW GLOBAL STATUS LIKE 'Innodb%write%';
+-----------------------------------+-------+
| Variable_name | Value |
+-----------------------------------+-------+
| Innodb_buffer_pool_write_requests | 5379 |
| Innodb_data_pending_writes | 0 |
| Innodb_data_writes | 416 |
| Innodb_dblwr_writes | 30 |
| Innodb_log_write_requests | 1100 |
| Innodb_log_writes | 88 |
| Innodb_os_log_pending_writes | 0 |
| Innodb_truncated_status_writes | 0 |
+-----------------------------------+-------+
mysql> SHOW GLOBAL STATUS LIKE 'Uptime';
+---------------+--------+
| Variable_name | Value |
+---------------+--------+
| Uptime | 4807 | -- divide by this to get "per second"
+---------------+--------+
Note: "requests" include both writes that need to hit the disk and those that do not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.