2828import java .util .Date ;
2929
3030import org .sqlite .server .SQLiteProcessor ;
31+ import org .sqlite .server .SQLiteServer ;
32+ import org .sqlite .server .sql .SQLMetric ;
3133
32- /** "SHOW STATUS" statement that shows server current status, includes memory,
34+ /** "SHOW STATUS" statement that shows server current status, includes SQL, memory,
3335 * thread, runtime and OS information.
3436 *
3537 * @author little-pan
@@ -47,7 +49,8 @@ public ShowStatusStatement(String sql) {
4749 @ Override
4850 protected String getSQL (String localSchema ) throws SQLException {
4951 final String f =
50- "select Mem_Committed, Mem_Max, Mem_Used, "
52+ "select Select_Stmts, Update_Stmts, Insert_Stmts, Delete_Stmts, Total_Stmts, Slow_Stmts, "
53+ + "Mem_Committed, Mem_Max, Mem_Used, "
5154 + "OS_Arch, OS_Name, OS_Version, "
5255 + "RT_Name, RT_Start_Time, RT_Uptime, RT_Vendor, RT_Version, "
5356 + "Thread_Count, Thread_Daemon_Count, Thread_Peak_Count, Thread_Started_Count, "
@@ -64,9 +67,15 @@ protected void init() throws SQLException {
6467 String f , sql ;
6568 // CREATE TABLE
6669 f = "create table if not exists '%s'.%s("
67- + "`Mem_Committed` bigint null,"
68- + "`Mem_Max` bigint not null,"
69- + "`Mem_Used` bigint not null,"
70+ + "`Select_Stmts` bigint,"
71+ + "`Update_Stmts` bigint,"
72+ + "`Insert_Stmts` bigint,"
73+ + "`Delete_Stmts` bigint,"
74+ + "`Total_Stmts` bigint,"
75+ + "`Slow_Stmts` bigint,"
76+ + "`Mem_Committed` bigint,"
77+ + "`Mem_Max` bigint,"
78+ + "`Mem_Used` bigint,"
7079 + "`OS_Arch` varchar(80),"
7180 + "`OS_Name` varchar(64),"
7281 + "`OS_Version` varchar(64),"
@@ -96,12 +105,15 @@ public void preExecute(int maxRows) throws SQLException, IllegalStateException {
96105
97106 // Collect processor state
98107 SQLiteProcessor processor = super .getContext ();
108+ SQLiteServer server = processor .getServer ();
99109 // INSERT new data for query
100- f = "insert into '%s'.%s(`Mem_Committed`, `Mem_Max`, `Mem_Used`, `OS_Arch`, `OS_Name`, `OS_Version`, "
110+ f = "insert into '%s'.%s(`Select_Stmts`, `Update_Stmts`, `Insert_Stmts`, `Delete_Stmts`, "
111+ + "`Total_Stmts`, `Slow_Stmts`,"
112+ + "`Mem_Committed`, `Mem_Max`, `Mem_Used`, `OS_Arch`, `OS_Name`, `OS_Version`, "
101113 + "`RT_Name`, `RT_Start_Time`, `RT_Uptime`, `RT_Vendor`, `RT_Version`, "
102114 + "`Thread_Count`, `Thread_Daemon_Count`, `Thread_Peak_Count`, `Thread_Started_Count`, "
103115 + "`Sys_Load_Average`)"
104- + "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ;
116+ + "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" ;
105117 sql = format (f , localSchema , TBL_NAME );
106118 try (PreparedStatement ps = processor .getConnection ().prepareStatement (sql )) {
107119 MemoryMXBean memMxBean = ManagementFactory .getMemoryMXBean ();
@@ -114,6 +126,15 @@ public void preExecute(int maxRows) throws SQLException, IllegalStateException {
114126 int i = 0 ;
115127 long v = -1 ;
116128
129+ // SQL metric
130+ SQLMetric sqlMetric = server .getSQLMetric ();
131+ ps .setLong (++i , sqlMetric .selectStmts );
132+ ps .setLong (++i , sqlMetric .updateStmts );
133+ ps .setLong (++i , sqlMetric .insertStmts );
134+ ps .setLong (++i , sqlMetric .deleteStmts );
135+ ps .setLong (++i , sqlMetric .totalStmts );
136+ ps .setLong (++i , sqlMetric .slowStmts );
137+
117138 // Memory committed
118139 if (heapMemUsage .getCommitted () > 0 ) {
119140 v = heapMemUsage .getCommitted ();
0 commit comments