Skip to content

Commit

Permalink
Add system review metrics for MySQL and MS SQL server
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonchik Tsymzhitov authored and Gonchik Tsymzhitov committed Mar 21, 2020
1 parent 6bab2a5 commit a1f28c2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 9 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ or

To run DB status:

java -cp support-tools.jar \
com.atlassian.util.status.JIRADatabaseStatus
jira_home jira_install_dir
java -cp support-tools.jar com.atlassian.util.status.JIRADatabaseStatus ${jira_home} ${jira_install_dir}

or:

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.atlassian</groupId>
<artifactId>support-tools</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ConnectionFactory(JiraDatabaseConfig config) {
* @return a connection
*/
public Connection getConnection() {
if (connection !=null){
if (connection != null) {
return connection;
}
try {
Expand Down
65 changes: 62 additions & 3 deletions src/main/java/com/atlassian/util/status/JIRADatabaseStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public void analyzeConnection() {
ConnectionTester tester = null;
switch (dbType) {
case "mysql":
throw new NotImplementedException();
tester = new MySQLTester(connectionFactory.getConnection());
break;
case "postgres72":
tester = new PostgresTester(connectionFactory.getConnection());
break;
case "oracle":
throw new NotImplementedException();
case "sqlserver":
throw new NotImplementedException();
tester = new MSSQLTester(connectionFactory.getConnection());
break;
}
Objects.requireNonNull(tester).run();
}
Expand All @@ -73,7 +75,7 @@ public ConnectionTester(Connection connection) {
public abstract void run();
}

private class PostgresTester extends ConnectionTester {
private static class PostgresTester extends ConnectionTester {

public PostgresTester(Connection connection) {
super(connection);
Expand Down Expand Up @@ -119,4 +121,61 @@ public void run() {
}
}
}

private static class MySQLTester extends ConnectionTester {

public MySQLTester(Connection connection) {
super(connection);
}

@Override
public void run() {
System.out.println("You will probably need to enable these parameters to get data:\n"
+ "\t* The parameter track_activities enables monitoring of the current command being executed by any server process.\n"
+ "\t* The parameter track_counts controls whether statistics are collected about table and index accesses.\n"
+ "\t* The parameter track_functions enables tracking of usage of user-defined functions.\n"
+ "\t* The parameter track_io_timing enables monitoring of block read and write times.");

String[] tables = {
"INFORMATION_SCHEMA.PROCESSLIST", // One row per server process, showing information related to the current activity of that process, such as state and current query. See INFORMATION_SCHEMA.PROCESSLIST for details.
"INFORMATION_SCHEMA.STATISTICS", // The STATISTICS table provides information about table indexes.
"INFORMATION_SCHEMA.TABLES", // One row for each table in the current database, showing statistics about accesses to that specific table. See INFORMATION_SCHEMA.TABLES for details.
"INFORMATION_SCHEMA.ENGINES", // The ENGINES table provides information about storage engines.
"INFORMATION_SCHEMA.GLOBAL_VARIABLES", // Show Global variables
};
for (String table : tables) {
DBTablePrinter.printTable(connection, table);
}
}
}

private static class MSSQLTester extends ConnectionTester {

public MSSQLTester(Connection connection) {
super(connection);
}

@Override
public void run() {
System.out.println("You will probably need to enable these parameters to get data:\n"
+ "\t* The parameter track_activities enables monitoring of the current command being executed by any server process.\n"
+ "\t* The parameter track_counts controls whether statistics are collected about table and index accesses.\n"
+ "\t* The parameter track_functions enables tracking of usage of user-defined functions.\n"
+ "\t* The parameter track_io_timing enables monitoring of block read and write times.");
// docs based on the https://docs.microsoft.com/ru-ru/sql/relational-databases/system-dynamic-management-views/sys-dm-os-performance-counters-transact-sql
String[] tables = {
"sys.sysprocesses", // Contains information about processes that are running on an instance of SQL Server.
"sys.indexes", // Contains one row for each index and table in the current database.
"sys.index_columns",
"sys.configurations", // For a list of all server configuration options,
"sys.dm_os_performance_counters", // Returns a row per performance counter maintained by the server
"sys.dm_os_process_memory", // Most memory allocations that are attributed to the SQL Server process space
"sys.dm_os_waiting_tasks", // Returns information about the wait queue of tasks that are waiting on some resource
};
for (String table : tables) {
DBTablePrinter.printTable(connection, table);
}
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/thirdparty/DBTablePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class DBTablePrinter {
/**
* Default maximum number of rows to query and print.
*/
private static final int DEFAULT_MAX_ROWS = 10;
private static final int DEFAULT_MAX_ROWS = 100;

/**
* Default maximum width for text columns
Expand Down

0 comments on commit a1f28c2

Please sign in to comment.