Example #1
0
        public TrackerDatabaseSize getDatabaseSize (string databaseName) {

            TrackerDatabaseSize trackerDatabaseSize = new TrackerDatabaseSize();


            try {
                mysqlConnection = new MySqlConnection(database.getConnectionString());

                mysqlConnection.Open();

                string sql =
                    "SELECT table_schema \"databaseName\", " +
                    "sum( data_length + index_length ) / 1024 / 1024 \"databaseSize\", " +
                    "sum( data_free )/ 1024 / 1024 \"databaseFreeSpace\" " +

                    "FROM information_schema.TABLES " +
                    "WHERE table_schema LIKE @databaseName;";

                MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);
                mySqlCommand.Parameters.AddWithValue("@databaseName", databaseName);
                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                if (!mySqlDataReader.HasRows) {
                    mySqlDataReader.Dispose();
                    throw new QueryException(1, "No database.");
                } else {
                    mySqlDataReader.Read();
                    trackerDatabaseSize.Name = mySqlDataReader.GetString("databaseName");
                    trackerDatabaseSize.DatabaseSize = mySqlDataReader.GetDouble("databaseSize");
                    trackerDatabaseSize.DatabaseFreeSpace = mySqlDataReader.GetDouble("databaseFreeSpace");
                }

            } catch (MySqlException mySqlException) {
                throw new QueryException(1, mySqlException.Message);
            } catch (QueryException queryException) {
                throw queryException;
            } catch (Exception exception) {
                throw new QueryException(1, exception.Message);
            } finally {
                mysqlConnection.Close();
            }

            return trackerDatabaseSize;
        }
 public TrackerDatabaseSizeItem(TrackerDatabaseSize trackerDatabaseSize) {
     this.trackerDatabaseSize = trackerDatabaseSize;
 }
Example #3
0
        public ConcurrentQueue<TrackerDatabaseSize> getDatabasesSize () {

            ConcurrentQueue<TrackerDatabaseSize> trackerDatabaseSizes = new ConcurrentQueue<TrackerDatabaseSize>();


            try {
                mysqlConnection = new MySqlConnection(database.getConnectionString());

                mysqlConnection.Open();

                string sql =
                    "SELECT table_schema \"databaseName\", " +
                    "sum( data_length + index_length ) / 1024 / 1024 \"databaseSize\", " +
                    "sum( data_free )/ 1024 / 1024 \"databaseFreeSpace\" " +

                    "FROM information_schema.TABLES " +
                    "WHERE table_schema LIKE \"trk_%\" OR table_schema LIKE \"dbt_%\" " +
                     "GROUP BY table_schema ;";

                MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);

                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                if (!mySqlDataReader.HasRows) {
                    mySqlDataReader.Dispose();
                    throw new QueryException(1, "No database.");
                } else {
                    while (mySqlDataReader.Read()) {
                        TrackerDatabaseSize trackerDatabaseSize = new TrackerDatabaseSize();

                        trackerDatabaseSize.Name = mySqlDataReader.GetString("databaseName");
                        trackerDatabaseSize.DatabaseSize = mySqlDataReader.GetDouble("databaseSize");
                        trackerDatabaseSize.DatabaseFreeSpace = mySqlDataReader.GetDouble("databaseFreeSpace");

                        trackerDatabaseSizes.Enqueue(trackerDatabaseSize);
                    }
                }

            } catch (MySqlException mySqlException) {
                throw new QueryException(1, mySqlException.Message);
            } catch (QueryException queryException) {
                throw queryException;
            } catch (Exception exception) {
                throw new QueryException(1, exception.Message);
            } finally {
                mysqlConnection.Close();
            }
            return trackerDatabaseSizes;
        }